jQuery(document).ready(function () {


    jQuery('#banners').owlCarousel({
        loop: true,
        margin: 10,
        nav: false,
        dots: false,

        autoplay: true,
        autoPlaySpeed: 5000,
        autoplayTimeout: 5000,
        autoplayHoverPause: true,
        responsive: {
            0: {
                items: 1
            },
            600: {
                items: 2
            },
            1000: {
                items: 2
            }
        }
    });

    jQuery('#kinsta_banners').owlCarousel({
        loop: true,
        margin: 10,
        nav: false,
        dots: false,
        autoplay: true,
        autoPlaySpeed: 5000,
        autoplayTimeout: 5000,
        autoplayHoverPause: true,
        responsive: {
            0: {
                items: 2
            },
            600: {
                items: 3
            },
            1400: {
                items: 6
            }
        }
    });

    /* Save option data using ajax */
    jQuery('#pdfsubmit').click(function (e) {
        // jQuery("#wcbnl_overlay").fadeIn(300);
        e.preventDefault();
        var security_nonce = wcgen_vars.ajax_public_nonce;
        var form = jQuery("#pdfform").serialize(); // this will resolve to the form submitted		
        console.log(form);
        jQuery.ajax({
            type: "POST",
            global: false,
            dataType: "json",
            url: wcgen_vars.ajaxurl,
            data: { form_data: form, security_nonce: security_nonce, action: 'wcgen_save_option' }, //only input
            success: function (response) {
                if (response) {
                    location.reload();
                }
            }
        }).done(function () {
            setTimeout(function () {
                //jQuery("#wcbnl_overlay").fadeOut(300);
            }, 500);
        });
    });

    // wordpress image uploader
    jQuery('#upload-btn').click(function (e) {
        e.preventDefault();
        var image = wp.media({
            title: 'Upload Image',
            // mutiple: true if you want to upload multiple files at once
            multiple: false
        }).open()
            .on('select', function (e) {
                // This will return the selected image from the Media Uploader, the result is an object
                var uploaded_image = image.state().get('selection').first();
                // We convert uploaded_image to a JSON object to make accessing it easier
                // Output to the console uploaded_image
                console.log(uploaded_image);
                var image_url = uploaded_image.toJSON().url;
                // Let's assign the url value to the input field
                jQuery('#image_url').val(image_url);
            });
    });

    /* Select design */
    if (jQuery('input[name="chk_design_hdn"]')) {
        var chkdesing = jQuery('input[name="chk_design_hdn"]').val();
        jQuery('#' + chkdesing).prop('checked', true);
    }
    jQuery('.chkdesign').each(function () {
        // jQuery(this).prop('checked', false); 
        jQuery(this).click(function () {
            jQuery(this).prop('checked', true);
            jQuery('input[name="chk_design_hdn"]').val(jQuery(this).val());

            var pdfpath = wcgen_vars.pluginurl + jQuery(this).val();
            jQuery('#pdfform').attr('action', pdfpath + '.php');
        });
    });

    jQuery('#myTab li').each(function () {
        // jQuery(this).prop('checked', false); 
        jQuery(this).click(function () {
            if (jQuery(this).find('a').html() == 'Portrate Design') {
                jQuery('input[name="chk_design_hdn"]').val("designP1");
                var pdfpath = wcgen_vars.pluginurl + "designP1";
                jQuery('#pdfform').attr('action', pdfpath + '.php');
            } else {
                jQuery('input[name="chk_design_hdn"]').val("designL1");
                var pdfpath = wcgen_vars.pluginurl + "designL1";
                jQuery('#pdfform').attr('action', pdfpath + '.php');
            }
        });
    });


    jQuery('.zebra_tooltips').tooltip({
        position: {
            my: "center bottom-20",
            at: "center top",
            using: function (position, feedback) {
                jQuery(this).css(position);
                jQuery("<div>")
                    .addClass("arrow")
                    .addClass(feedback.vertical)
                    .addClass(feedback.horizontal)
                    .appendTo(this);
            }
        }
    });
    /* 
        var tabs =  jQuery(".tabs li a");
        
        tabs.click(function() {
            var content = this.hash.replace('/','');
            tabs.removeClass("active");
            jQuery(this).addClass("active");
        jQuery(".tab-content").find('p').hide();
        jQuery(content).fadeIn(200);
        }); */

    /*        var myOptions = {
            // you can declare a default color here,
            // or in the data-default-color attribute on the input
            defaultColor: false,
            // a callback to fire whenever the color changes to a valid color
            change: function(event, ui){
                var rgb = ui.color.toCSS( 'rgb' );
                var name = jQuery(this).attr("name");
                name = '#' + name + '_rgb';
                jQuery(name).val(rgb);
            },
            // a callback to fire when the input is emptied or an invalid color
            clear: function() {},
            // hide the color picker controls on load
            hide: true,
            // show a group of common colors beneath the square
            // or, supply an array of colors to customize further
            palettes: true
        };*/
    // jQuery('.color-picker').wpColorPicker(); 
});