<?php
/**
 * Branded Theme Customizer
 *
 * @package Branded
 */

/**
 * Add postMessage support for site title and description for the Theme Customizer.
 *
 * @param WP_Customize_Manager $wp_customize Theme Customizer object.
 */
function branded_customize_register( $wp_customize ) {
	
	//Add a class for titles
    class branded_Info extends WP_Customize_Control {
        public $type = 'info';
        public $label = '';
        public function render_content() {
        ?>
			<h3><?php echo esc_html( $this->label ); ?></h3>
        <?php
        }
    }
	
	function branded_sanitize_checkbox( $checked ) {
		// Boolean check.
		return ( ( isset( $checked ) && true == $checked ) ? true : false );
	}	

	$wp_customize->get_setting( 'blogname' )->transport         = 'postMessage';
	$wp_customize->get_setting( 'blogdescription' )->transport  = 'postMessage';
	
	$wp_customize->add_setting('branded_color_scheme',array(
			'default'	=> '#81d742',
			'sanitize_callback'	=> 'sanitize_hex_color'
	));
	
	$wp_customize->add_control(
		new WP_Customize_Color_Control($wp_customize,'branded_color_scheme',array(
			'label' => __('Color Scheme','branded'),			
			 'description'	=> __('Change color of theme','branded'),
			'section' => 'colors',
			'settings' => 'branded_color_scheme'
		))
	);
	
	// Slider Section		
	$wp_customize->add_section('branded_slider_section', array(
            'title' => __('Slider Settings', 'branded'),
            'priority' => null,
			'description'	=> __('Featured Image Size Should be same ( 1400x600 ) More slider settings available in PRO Version.','branded'),            			
        )
    );
	
	$wp_customize->add_setting('branded_page-setting7',array(
			'default'	=> '0',			
			'capability' => 'edit_theme_options',
			'sanitize_callback'	=> 'absint'
	));
	
	$wp_customize->add_control('branded_page-setting7',array(
			'type'	=> 'dropdown-pages',
			'label'	=> __('Select page for slide one:','branded'),
			'section'	=> 'branded_slider_section'
	));	
	
	$wp_customize->add_setting('branded_page-setting8',array(
			'default'	=> '0',			
			'capability' => 'edit_theme_options',
			'sanitize_callback'	=> 'absint'
	));
	
	$wp_customize->add_control('branded_page-setting8',array(
			'type'	=> 'dropdown-pages',
			'label'	=> __('Select page for slide two:','branded'),
			'section'	=> 'branded_slider_section'
	));	
	
	$wp_customize->add_setting('branded_page-setting9',array(
			'default'	=> '0',			
			'capability' => 'edit_theme_options',
			'sanitize_callback'	=> 'absint'
	));
	
	$wp_customize->add_control('branded_page-setting9',array(
			'type'	=> 'dropdown-pages',
			'label'	=> __('Select page for slide three:','branded'),
			'section'	=> 'branded_slider_section'
	));	// Slider Section
	
	$wp_customize->add_setting('branded_disabled_slides',array(
			'default' => true,
			'sanitize_callback' => 'branded_sanitize_checkbox',
			'capability' => 'edit_theme_options',
	));	 
	
	$wp_customize->add_control( 'branded_disabled_slides', array(
		   'settings' => 'branded_disabled_slides',
		   'section'   => 'branded_slider_section',
		   'label'     => __('Uncheck To Enable This Section','branded'),
		   'type'      => 'checkbox'
	 ));//Disable Slider Section	
	 
	// Homepage Section Titles	
	$wp_customize->add_section('branded_section_title', array(
			'title'	=> __('Homepage Section Titles','branded'),
			'description'	=> __('Manage Home Page Section Titles','branded'),
			'priority'	=> null
	));	
	
	$wp_customize->add_setting('branded_three_box_title',array(
			'default'	=> '',	
			'sanitize_callback'	=> 'sanitize_text_field',		
			'capability' => 'edit_theme_options'			
	));
	
	$wp_customize->add_control('branded_three_box_title',array(
			'settings' => 'branded_three_box_title',
			'type'	=> 'text',
			'label'	=> __('Title for Box Three Section','branded'),
			'section'	=> 'branded_section_title'
	));
	
	$wp_customize->add_setting('branded_latest_news_title',array(
			'default'	=> '',	
			'sanitize_callback'	=> 'sanitize_text_field',		
			'capability' => 'edit_theme_options'			
	));
	
	$wp_customize->add_control('branded_latest_news_title',array(
			'settings' => 'branded_latest_news_title',
			'type'	=> 'text',
			'label'	=> __('Title for Latest News Section','branded'),
			'section'	=> 'branded_section_title'
	));
	
	// End Homepage Section Titles 
	 
	 //Why Choose Us section
	$wp_customize->add_section('branded_section_first',array(
			'title'	=> __('Why Choose Us ','branded'),
			'description'	=> __('Add your details here','branded'),
			'priority'	=> null
	));	
	
	$wp_customize->add_setting('branded_why-page1',array(
			'default'	=> '0',			
			'capability' => 'edit_theme_options',
			'sanitize_callback'	=> 'absint'
	));
	
	$wp_customize->add_control('branded_why-page1',array(
			'type' => 'dropdown-pages',			
			'section' => 'branded_section_first',
	));	
	
	$wp_customize->add_setting('branded_disabled_whychooseus',array(
			'default' => true,
			'sanitize_callback' => 'branded_sanitize_checkbox',
			'capability' => 'edit_theme_options',
	));	 
	
	$wp_customize->add_control( 'branded_disabled_whychooseus', array(
		   'settings' => 'branded_disabled_whychooseus',
		   'section'   => 'branded_section_first',
		   'label'     => __('Uncheck To Enable This Section','branded'),
		   'type'      => 'checkbox'
	 )); //Disable Why Choose Us section
	
	// Home Three Boxes Section 	
	$wp_customize->add_section('branded_section_second', array(
			'title'	=> __('Homepage Three Boxes Section','branded'),
			'description'	=> __('Select Pages from the dropdown for homepage three boxes section','branded'),
			'priority'	=> null
	));	
	
	$wp_customize->add_setting('branded_page-column1',	array(
			'default'	=> '0',			
			'capability' => 'edit_theme_options',
			'sanitize_callback'	=> 'absint'
	));
 
	$wp_customize->add_control(	'branded_page-column1',array(
			'type' => 'dropdown-pages',
			'section' => 'branded_section_second',
	));	
	
	$wp_customize->add_setting('branded_page-column2',	array(
			'default'	=> '0',			
			'capability' => 'edit_theme_options',
			'sanitize_callback'	=> 'absint'
	));
 
	$wp_customize->add_control(	'branded_page-column2',array(
			'type' => 'dropdown-pages',
			'section' => 'branded_section_second',
	));
	
	$wp_customize->add_setting('branded_page-column3',	array(
			'default'	=> '0',			
			'capability' => 'edit_theme_options',
			'sanitize_callback'	=> 'absint'
	));
 
	$wp_customize->add_control(	'branded_page-column3',array(
			'type' => 'dropdown-pages',
			'section' => 'branded_section_second',
	));//end four column page boxes
	
	$wp_customize->add_setting('branded_disabled_pgboxes',array(
			'default' => true,
			'sanitize_callback' => 'branded_sanitize_checkbox',
			'capability' => 'edit_theme_options',
	));	 
	
	$wp_customize->add_control( 'branded_disabled_pgboxes', array(
		   'settings' => 'branded_disabled_pgboxes',
		   'section'   => 'branded_section_second',
		   'label'     => __('Uncheck To Enable This Section','branded'),
		   'type'      => 'checkbox'
	 ));//Disable Homepage boxes Section	
	
    // Homepage latest news Section
	
	$wp_customize->add_section('branded_section_third', array(
			'title'	=> __('Homepage Latest News Section','branded'),
			'description'	=> __('Manage Latest News in Home Page','branded'),
			'priority'	=> null
	));	
	
	$wp_customize->add_setting('branded_disabled_latest_news',array(
			'default' => true,
			'sanitize_callback' => 'branded_sanitize_checkbox',
			'capability' => 'edit_theme_options',
	));	 
	
	$wp_customize->add_control( 'branded_disabled_latest_news', array(
		   'settings' => 'branded_disabled_latest_news',
		   'section'   => 'branded_section_third',
		   'label'     => __('Uncheck To Enable This Section','branded'),
		   'type'      => 'checkbox'
	 ));//Disable Homepage latest news Section
	
}
add_action( 'customize_register', 'branded_customize_register' );

function branded_custom_css(){
		?>
        	<style type="text/css"> 
					
					a, .blog_lists h2 a:hover,
					#sidebar ul li a:hover,									
					.blog_lists h3 a:hover,
					.cols-4 ul li a:hover, .cols-4 ul li.current_page_item a,
					.recent-post h6:hover,					
					.fourbox:hover h3,
					.footer-icons a:hover,
					.postmeta a:hover,
					.powerby a:hover
					{ color:<?php echo esc_html( get_theme_mod('branded_color_scheme','#81d742')); ?>;}
					 
					
					.pagination ul li .current, .pagination ul li a:hover, 
					#commentform input#submit:hover,					
					.nivo-controlNav a.active,
					.ReadMore:hover,
					.appbutton:hover,					
					.slide_info .slide_more,				
					h3.widget-title,
					.sitenav ul li a:hover, .sitenav ul li.current_page_item a, 
					.sitenav ul li.current-menu-ancestor a.parent,					
					#sidebar .search-form input.search-submit,				
					.wpcf7 input[type='submit']					
					{ background-color:<?php echo esc_html( get_theme_mod('branded_color_scheme','#81d742')); ?>;}
					
					
					.footer-icons a:hover							
					{ border-color:<?php echo esc_html( get_theme_mod('branded_color_scheme','#81d742')); ?>;}					
					
					
			</style>
<?php                      
}
         
add_action('wp_head','branded_custom_css');	  

/**
 * Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
 */
function branded_customize_preview_js() {
	wp_enqueue_script( 'branded_customizer', get_template_directory_uri() . '/js/customize-preview.js', array( 'customize-preview' ), '20130508', true );
}
add_action( 'customize_preview_init', 'branded_customize_preview_js' );