jQuery(document).ready(function() {

 /* Move our focus widgets in the our focus panel */

	/*Documentation link and Upgrade to PRO link */
	if( !jQuery( ".novel-docs" ).length ) {
		jQuery('#customize-theme-controls > ul').prepend('<li class="accordion-section novel-docs">');
	}
	if( jQuery( ".novel-docs" ).length ) {

		jQuery('.novel-docs').append('<a style="width: 80%; margin: 5px auto 5px auto; display: block; text-align: center;" href="http://www.themehunk.com/docs/portfoilolite-theme/" class="button" target="_blank">{documentation}</a>'.replace('{documentation}', portfolioCustomizerObject.documentation));

	}
	jQuery('.preview-notice').append('<a class="novel-docs-to-pro-button" href="http://www.themehunk.com/all-themes" class="button" target="_blank">{pro}</a>'.replace('{pro}',portfolioCustomizerObject.pro));

	if ( !jQuery( ".novel-docs" ).length ) {
		jQuery('#customize-theme-controls > ul').prepend('</li>');
	}
    /* === Checkbox Multiple Control === */
    jQuery( '.customize-control-checkbox-multiple input[type="checkbox"]' ).on(
        'change',
        function() {
   // alert('');
            checkbox_values = jQuery( this ).parents( '.customize-control' ).find( 'input[type="checkbox"]:checked' ).map(
                function() {
                    return this.value;
                }
            ).get().join( ',' );

            jQuery( this ).parents( '.customize-control' ).find( 'input[type="hidden"]' ).val( checkbox_values ).trigger( 'change' );
        }
    );

        // section sorting
    jQuery( "#sortable" ).sortable({ 
            placeholder: "ui-sortable-placeholder" 
    });

    jQuery( "#sortable" ).sortable({
        cursor: 'move',
        opacity: 0.65,
        stop: function ( event, ui){
        var data = jQuery(this).sortable('toArray');
            //  console.log(data); // This should print array of IDs, but returns empty string/array      
            jQuery( this ).parents( '.customize-control').find( 'input[type="hidden"]' ).val( data ).trigger( 'change' );
        }
    });

    // testimonial widget
    wp.customize.section( 'sidebar-widgets-portfolio-testimonial-widget' ).panel('home_testimonial');
    wp.customize.section( 'sidebar-widgets-portfolio-testimonial-widget' ).priority('4');

    // team widget
    wp.customize.section( 'sidebar-widgets-portfolio-team-widget' ).panel('our_team_panel');
    wp.customize.section( 'sidebar-widgets-portfolio-team-widget' ).priority('4');
    // price widget
    wp.customize.section( 'sidebar-widgets-portfolio-price-widget' ).panel('our_price_panel');
    wp.customize.section( 'sidebar-widgets-portfolio-price-widget' ).priority('4');
    // social-icon widget
    wp.customize.section( 'sidebar-widgets-social-icon-widget' ).panel('footr_panel');
    wp.customize.section( 'sidebar-widgets-social-icon-widget' ).priority('4');



});