/**
 * 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( 'magazinestyle_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 = [
                'magazinestyle_tickerbg',
                'magazinestyle_tickerlabelfont',
                'magazinestyle_tickerpostbg',
                'magazinestyle_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 = [
                'magazinestyle_tickerbg_two',
                'magazinestyle_tickerlabelfont_two',
                'magazinestyle_tickerpostbg_two',
                'magazinestyle_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 = [
                'magazinestyle_tickerbg_three',
                'magazinestyle_tickerlabelfont_three',
                'magazinestyle_tickerpostbg_three',
                'magazinestyle_tickerspeed_three',
                'magazinestyle_tickerpostlink_three'
            ];

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

    const controlsposter = [
        'magazinestyle_poststylethree_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( 'magazinestyle_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 = [
                'magazinestyle_topnavbgcolor',
                'magazinestyle_topnavhover',
                'magazinestyle_topnavtext',
                'magazinestyle_primarymenubg',
                'magazinestyle_primarymenubgs',
                'magazinestyle_primarymenutext',
                'magazinestyle_primarymenuhover',
                'magazinestyle_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 = [
                'magazinestyle_heroarea_links',
                'magazinestyle_heroarea_links_hover',
                'magazinestyle_heroarea',
                'magazinestyle_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 = [
                'magazinestyle_primarymenutext_three',
                'magazinestyle_topnavi_leftthree',
                'magazinestyle_topnavi_rightthree',
                'magazinestyle_primarymenutexthover_three',
                'magazinestyle_topnavibg_three',
                'magazinestyle_topnavi_enablethree',
                'magazinestyle_primarymenubg_three',
                'magazinestyle_topnavitext_three',
            ];

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

    wp.customize( 'magazinestyle_carttotal', function( value ) {
        value.bind( function( newVal ) {
            if ( newVal === true ) {                   
                jQuery( '.woocommerce-Price-amount' ).css( 'display', 'inline' );
            } else {
                jQuery( '.woocommerce-Price-amount' ).css( 'display', 'none' );
            }
        });
    });

    wp.customize("magazinestyle_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( 'magazinestyle_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( 'magazinestyle_footer_copy', function( value ) {
		value.bind( function( footerCopybg ) {
			jQuery('#wrapper-footer').css('background', footerCopybg );
		} );
	} );
    wp.customize( 'magazinestyle_pagenavi_current', function( value ) {
		value.bind( function( pagenavic ) {
			jQuery('span.page-link.current').css('background-color', pagenavic );
		} );
	} );  
	wp.customize( 'magazinestyle_pagenavi_bg', function( value ) {
		value.bind( function( pagenavibg ) {
			jQuery('a.page-link').css('background-color', pagenavibg );
		} );
	} );    
	wp.customize( 'magazinestyle_pagenavia_textcurrent', function( value ) {
		value.bind( function( pagenavitextc) {
			jQuery('span.page-link.current').css('color', pagenavitextc );
		} );
	} );    
	wp.customize( 'magazinestyle_pagenavia_text', function( value ) {
		value.bind( function( pagenavitext) {
			jQuery('a.page-link').css('color', pagenavitext );
		} );
	} );  
	wp.customize( 'magazinestyle_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('magazinestyle_pagenav_bg')();
            jQuery(this).css('background-color', pagenavibg);
			});
		} );
	} );
    wp.customize( 'magazinestyle_scrolltop_radius ', function( value ) {
		value.bind( function( borderRadius ) {
			jQuery('a.scrollup.backtoup').css('border-radius', borderRadius + 'px');
		} );
	} );
    

} )( jQuery );