/**
 * Scripts within the customizer controls window.
 *
 * Contextually shows the navbar type setting and informs the preview
 * when users open or close the front page sections section.
 */
 



 ( function () {
	wp.customize.bind( 'ready', function () {		
		wp.customize( 'poster_newsticker_style', function ( setting ) {			
			//style one
		  function setupControl(controlName) {
                wp.customize.control(controlName, function (control) {
                    const visibility = function () {
                        if ('styleone' === setting.get()) {
                            control.container.slideDown(180);
                        } else {
                            control.container.slideUp(180);
                        }
                    };
                    visibility();
                    setting.bind(visibility);
                });
            }

            // List of controls to be handled
            const controls = [
                'poster_tickerbg',
                'poster_tickerlabelfont',
                'poster_tickerpostbg',
                'poster_tickerpostlink'
            ];

            // Setup each control
            controls.forEach(function (controlName) {
                setupControl(controlName);
            });
			
			
			
			 function setupControlTwo(controlNameTwo) {
                wp.customize.control(controlNameTwo, function (control) {
                    const visibility = function () {
                        if ('styletwo' === setting.get()) {
                            control.container.slideDown(180);
                        } else {
                            control.container.slideUp(180);
                        }
                    };
                    visibility();
                    setting.bind(visibility);
                });
            }
			 // List of controls to be handled
            const controlstwo = [
                'poster_tickerbg_two',
                'poster_tickerlabelfont_two',
                'poster_tickerpostbg_two',
                'poster_tickerpostlink_two'
            ];

            // Setup each control
            controlstwo.forEach(function (controlNameTwo) {
                setupControlTwo(controlNameTwo);
            });
			//style two
			
			 function setupControlThree(controlNameThree) {
                wp.customize.control(controlNameThree, function (control) {
                    const visibility = function () {
                        if ('stylethree' === setting.get()) {
                            control.container.slideDown(180);
                        } else {
                            control.container.slideUp(180);
                        }
                    };
                    visibility();
                    setting.bind(visibility);
                });
            }
			 // List of controls to be handled
            const controlsthree = [
                'poster_tickerbg_three',
                'poster_tickerlabelfont_three',
                'poster_tickerpostbg_three',
                'poster_tickerspeed_three',
                'poster_tickerpostlink_three'
            ];

            // Setup each control
            controlsthree.forEach(function (controlNameThree) {
                setupControlThree(controlNameThree);
            });
			//style three
		
					
		});			
		wp.customize('poster_posts_layout', function (setting) {
    function setupControlPoster(controlNamePoster) {
        wp.customize.control(controlNamePoster, function (control) {
            const visibility = function () {
                if ('poster' === setting.get()) {
                    control.container.slideDown(180);
                } else {
                    control.container.slideUp(180);
                }
            };
            visibility();
            setting.bind(visibility);
        });
    }

    const controlsposter = [
        'poster_poster_heading',
        'topcateid_hide',
        'topcateid',
        'cat_contlr_top',
        'cat_contlr_left',
        'cat_contlr_right',
        'leftcateid_hide',
        'leftcateid',
        'rightcateid_hide',
        'rightcateid',
    ];

    controlsposter.forEach(function (controlNamePoster) {
        setupControlPoster(controlNamePoster);
    });
});

		wp.customize( 'poster_header_style', function ( setting ) {			
			//style one
		  function setupControl(controlName) {
                wp.customize.control(controlName, function (control) {
                    const visibility = function () {
                        if ('styleone' === setting.get()) {
                            control.container.slideDown(180);
                        } else {
                            control.container.slideUp(180);
                        }
                    };
                    visibility();
                    setting.bind(visibility);
                });
            }

            // List of controls to be handled
            const controls = [
                'poster_topnavbgcolor',
                'poster_topnavhover',
                'poster_topnavtext',
                'poster_primarymenubg',
                'poster_primarymenubgs',
                'poster_primarymenutext',
                'poster_primarymenuhover',
                'poster_primarymenuhovertext'
            ];

            // Setup each control
            controls.forEach(function (controlName) {
                setupControl(controlName);
            });
			
			
			
			
			//style two
			  function setupControlTwo(controlNameTwo) {
                wp.customize.control(controlNameTwo, function (control) {
                    const visibility = function () {
                        if ('styletwo' === setting.get()) {
                            control.container.slideDown(180);
                        } else {
                            control.container.slideUp(180);
                        }
                    };
                    visibility();
                    setting.bind(visibility);
                });
            }
			 // List of controls to be handled
            const controlstwo = [
                'poster_heroarea_links',
                'poster_heroarea_links_hover',
                'poster_heroarea',
                'poster_stickymenu',
            ];

            // Setup each control
            controlstwo.forEach(function (controlNameTwo) {
                setupControlTwo(controlNameTwo);
            });
			
			//style Three
			  function setupControlThree(controlNameThree) {
                wp.customize.control(controlNameThree, function (control) {
                    const visibility = function () {
                        if ('stylethree' === setting.get()) {
                            control.container.slideDown(180);
                        } else {
                            control.container.slideUp(180);
                        }
                    };
                    visibility();
                    setting.bind(visibility);
                });
            }
			 // List of controls to be handled
            const controlsthree = [
                'poster_primarymenutext_three',
                'poster_topnavi_leftthree',
                'poster_topnavi_rightthree',
                'poster_primarymenutexthover_three',
                'poster_topnavibg_three',
                'poster_topnavi_enablethree',
                'poster_primarymenubg_three',
                'poster_topnavitext_three',
            ];

            // Setup each control
            controlsthree.forEach(function (controlNameThree) {
                setupControlThree(controlNameThree);
            });		
					
		});			
	} );

    wp.customize("poster_scroll_top_position", function(value) {
        value.bind(function(newVal) {
            if ( newVal === "left" ) {
                jQuery( "a.scrollup" ).css( { "right": "auto", "left": "0" } );
            } else if ( newVal === "right" ) {
                jQuery( "a.scrollup" ).css( { "left": "auto", "right": "0" } );
            }
        });
    });
    wp.customize( 'poster_footerbg', function( value ) {
		value.bind( function( footerWigbg ) {
			jQuery('#wrapper-footer-full').css('background-color', footerWigbg );
			jQuery('#wrapper-static-hero').css('background-color', footerWigbg );
		} );
	} );
    wp.customize( 'poster_footer_copy', function( value ) {
		value.bind( function( footerCopybg ) {
			jQuery('#wrapper-footer').css('background', footerCopybg );
		} );
	} );
    wp.customize( 'poster_pagenavi_current', function( value ) {
		value.bind( function( pagenavic ) {
			jQuery('span.page-link.current').css('background-color', pagenavic );
		} );
	} );  
	wp.customize( 'poster_pagenavi_bg', function( value ) {
		value.bind( function( pagenavibg ) {
			jQuery('a.page-link').css('background-color', pagenavibg );
		} );
	} );    
	wp.customize( 'poster_pagenavia_textcurrent', function( value ) {
		value.bind( function( pagenavitextc) {
			jQuery('span.page-link.current').css('color', pagenavitextc );
		} );
	} );    
	wp.customize( 'poster_pagenavia_text', function( value ) {
		value.bind( function( pagenavitext) {
			jQuery('a.page-link').css('color', pagenavitext );
		} );
	} );  
	wp.customize( 'poster_pagenavia_hover', function( value ) {
    value.bind( function( pagenavihover ) {
        jQuery('a.page-link').hover(function(){
            jQuery(this).css('background-color', pagenavihover);
        }, function(){
            var pagenavibg = wp.customize.value('poster_pagenav_bg')();
            jQuery(this).css('background-color', pagenavibg);
			});
		} );
	} );
    wp.customize( 'poster_scrolltop_radius ', function( value ) {
		value.bind( function( borderRadius ) {
			jQuery('a.scrollup.backtoup').css('border-radius', borderRadius + 'px');
		} );
	} );
    

} )( jQuery );