jQuery( document ).ready( function($) {
	$( '.pmthemes-control-toggles' ).each( function() {
		$( this ).find( 'button' ).first().addClass( 'active' );
	} );

	$( document ).on( 'click', '.pmthemes-control-toggles button', function( e ) {
		e.preventDefault();
		var button = $( this ),
			target = button.data( 'target' ),
			other_targets = button.siblings();

		button.addClass( 'active' );
		button.siblings().removeClass( 'active' );

		$( 'li[data-control-section="' + target + '"]' ).css( {
			visibility: 'visible',
			height: '',
			width: '',
			margin: '',
		} );

		$.each( other_targets, function( index, value ) {
			var other_target = $( this ).data( 'target' );
			$( 'li[data-control-section="' + other_target + '"]' ).css( {
				visibility: 'hidden',
				height: '0',
				width: '0',
				margin: '0'
			} );
		} );
	} );

    // Navigation Settings Controls
    var main_navigation_controls = [
        'pmthemes_control_nav_on_header',
        'pmthemes_control_sticky_navi',
        'pmthemes_control_search_icon',
        'pmthemes_control_mainmenu_font_size',
        'pmthemes_control_mainmenu_bar_padding',
        'pmthemes_control_no_drpdown_ind',
    ];

    $.each( main_navigation_controls, function( index, value ) {
        $( '#customize-control-' + value ).attr( 'data-control-section', 'main-navigation' );
    } );

    var top_navigation_controls = [
        'pmthemes_control_header_icons',
        'pmthemes_control_topnav_align',
        'pmthemes_control_topnav_down',
        'pmthemes_control_topmenu_font_size',
        'pmthemes_control_topmenu_bar_padding',
        'pmthemes_control_top_nav_inactive',
        'pmthemes_control_header_line_enable',
    ];

    $.each( top_navigation_controls, function( index, value ) {
        $( '#customize-control-' + value ).attr( 'data-control-section', 'top-navigation' ).css( {
            visibility: 'hidden',
            height: '0',
            width: '0',
            margin: '0',
            overflow: 'hidden'
        } );
    } );
});
// Navigating to a URL in the Customizer Preview when a Section is Expanded
// https://make.xwp.co/2016/07/21/navigating-to-a-url-in-the-customizer-preview-when-a-section-is-expanded/
(function ( api ) {
    api.section( 'static_front_page', function( section ) {
        section.expanded.bind( function( isExpanded ) {
            var url;
            if ( isExpanded ) {
                url = api.settings.url.home;
                api.previewer.previewUrl.set( url );
            }
        } );
    } );
    api.section( 'pmthemes_homepage_colors', function( section ) {
        section.expanded.bind( function( isExpanded ) {
            var url;
            if ( isExpanded ) {
                url = api.settings.url.home;
                api.previewer.previewUrl.set( url );
            }
        } );
    } );
    api.section( 'pmthemes_section_slider', function( section ) {
        section.expanded.bind( function( isExpanded ) {
            var url;
            if ( isExpanded ) {
                url = api.settings.url.home;
                api.previewer.previewUrl.set( url );
            }
        } );
    } );
    api.section( 'pmthemes_featured_content', function( section ) {
        section.expanded.bind( function( isExpanded ) {
            var url;
            if ( isExpanded ) {
                url = api.settings.url.home;
                api.previewer.previewUrl.set( url );
            }
        } );
    } );
} ( wp.customize ) );