// source --> https://www.musiccentar.com/wp-content/plugins/divi_woo_layout_injector/includes/js/imagesloaded.pkgd.min.js?ver=6.9.4 
/*!
 * imagesLoaded PACKAGED v4.1.3
 * JavaScript is all like "You images are done yet or what?"
 * MIT License
 */

!function(e,t){"function"==typeof define&&define.amd?define("ev-emitter/ev-emitter",t):"object"==typeof module&&module.exports?module.exports=t():e.EvEmitter=t()}("undefined"!=typeof window?window:this,function(){function e(){}var t=e.prototype;return t.on=function(e,t){if(e&&t){var i=this._events=this._events||{},n=i[e]=i[e]||[];return-1==n.indexOf(t)&&n.push(t),this}},t.once=function(e,t){if(e&&t){this.on(e,t);var i=this._onceEvents=this._onceEvents||{},n=i[e]=i[e]||{};return n[t]=!0,this}},t.off=function(e,t){var i=this._events&&this._events[e];if(i&&i.length){var n=i.indexOf(t);return-1!=n&&i.splice(n,1),this}},t.emitEvent=function(e,t){var i=this._events&&this._events[e];if(i&&i.length){var n=0,o=i[n];t=t||[];for(var r=this._onceEvents&&this._onceEvents[e];o;){var s=r&&r[o];s&&(this.off(e,o),delete r[o]),o.apply(this,t),n+=s?0:1,o=i[n]}return this}},t.allOff=t.removeAllListeners=function(){delete this._events,delete this._onceEvents},e}),function(e,t){"use strict";"function"==typeof define&&define.amd?define(["ev-emitter/ev-emitter"],function(i){return t(e,i)}):"object"==typeof module&&module.exports?module.exports=t(e,require("ev-emitter")):e.imagesLoaded=t(e,e.EvEmitter)}("undefined"!=typeof window?window:this,function(e,t){function i(e,t){for(var i in t)e[i]=t[i];return e}function n(e){var t=[];if(Array.isArray(e))t=e;else if("number"==typeof e.length)for(var i=0;i<e.length;i++)t.push(e[i]);else t.push(e);return t}function o(e,t,r){return this instanceof o?("string"==typeof e&&(e=document.querySelectorAll(e)),this.elements=n(e),this.options=i({},this.options),"function"==typeof t?r=t:i(this.options,t),r&&this.on("always",r),this.getImages(),h&&(this.jqDeferred=new h.Deferred),void setTimeout(function(){this.check()}.bind(this))):new o(e,t,r)}function r(e){this.img=e}function s(e,t){this.url=e,this.element=t,this.img=new Image}var h=e.jQuery,a=e.console;o.prototype=Object.create(t.prototype),o.prototype.options={},o.prototype.getImages=function(){this.images=[],this.elements.forEach(this.addElementImages,this)},o.prototype.addElementImages=function(e){"IMG"==e.nodeName&&this.addImage(e),this.options.background===!0&&this.addElementBackgroundImages(e);var t=e.nodeType;if(t&&d[t]){for(var i=e.querySelectorAll("img"),n=0;n<i.length;n++){var o=i[n];this.addImage(o)}if("string"==typeof this.options.background){var r=e.querySelectorAll(this.options.background);for(n=0;n<r.length;n++){var s=r[n];this.addElementBackgroundImages(s)}}}};var d={1:!0,9:!0,11:!0};return o.prototype.addElementBackgroundImages=function(e){var t=getComputedStyle(e);if(t)for(var i=/url\((['"])?(.*?)\1\)/gi,n=i.exec(t.backgroundImage);null!==n;){var o=n&&n[2];o&&this.addBackground(o,e),n=i.exec(t.backgroundImage)}},o.prototype.addImage=function(e){var t=new r(e);this.images.push(t)},o.prototype.addBackground=function(e,t){var i=new s(e,t);this.images.push(i)},o.prototype.check=function(){function e(e,i,n){setTimeout(function(){t.progress(e,i,n)})}var t=this;return this.progressedCount=0,this.hasAnyBroken=!1,this.images.length?void this.images.forEach(function(t){t.once("progress",e),t.check()}):void this.complete()},o.prototype.progress=function(e,t,i){this.progressedCount++,this.hasAnyBroken=this.hasAnyBroken||!e.isLoaded,this.emitEvent("progress",[this,e,t]),this.jqDeferred&&this.jqDeferred.notify&&this.jqDeferred.notify(this,e),this.progressedCount==this.images.length&&this.complete(),this.options.debug&&a&&a.log("progress: "+i,e,t)},o.prototype.complete=function(){var e=this.hasAnyBroken?"fail":"done";if(this.isComplete=!0,this.emitEvent(e,[this]),this.emitEvent("always",[this]),this.jqDeferred){var t=this.hasAnyBroken?"reject":"resolve";this.jqDeferred[t](this)}},r.prototype=Object.create(t.prototype),r.prototype.check=function(){var e=this.getIsImageComplete();return e?void this.confirm(0!==this.img.naturalWidth,"naturalWidth"):(this.proxyImage=new Image,this.proxyImage.addEventListener("load",this),this.proxyImage.addEventListener("error",this),this.img.addEventListener("load",this),this.img.addEventListener("error",this),void(this.proxyImage.src=this.img.src))},r.prototype.getIsImageComplete=function(){return this.img.complete&&void 0!==this.img.naturalWidth},r.prototype.confirm=function(e,t){this.isLoaded=e,this.emitEvent("progress",[this,this.img,t])},r.prototype.handleEvent=function(e){var t="on"+e.type;this[t]&&this[t](e)},r.prototype.onload=function(){this.confirm(!0,"onload"),this.unbindEvents()},r.prototype.onerror=function(){this.confirm(!1,"onerror"),this.unbindEvents()},r.prototype.unbindEvents=function(){this.proxyImage.removeEventListener("load",this),this.proxyImage.removeEventListener("error",this),this.img.removeEventListener("load",this),this.img.removeEventListener("error",this)},s.prototype=Object.create(r.prototype),s.prototype.check=function(){this.img.addEventListener("load",this),this.img.addEventListener("error",this),this.img.src=this.url;var e=this.getIsImageComplete();e&&(this.confirm(0!==this.img.naturalWidth,"naturalWidth"),this.unbindEvents())},s.prototype.unbindEvents=function(){this.img.removeEventListener("load",this),this.img.removeEventListener("error",this)},s.prototype.confirm=function(e,t){this.isLoaded=e,this.emitEvent("progress",[this,this.element,t])},o.makeJQueryPlugin=function(t){t=t||e.jQuery,t&&(h=t,h.fn.imagesLoaded=function(e,t){var i=new o(this,e,t);return i.jqDeferred.promise(h(this))})},o.makeJQueryPlugin(),o});
// source --> https://www.musiccentar.com/wp-content/plugins/divi_woo_layout_injector/includes/js/script.js?ver=6.9.4 
jQuery(document).ready(function () {

    if (jQuery('.single-product .sb_woo_product_image').length) {

        sb_woo_gen_hidden_images();

        jQuery('.single-product .sb_woo_product_image').each(function () {
            var large_url = jQuery(this).children('img').attr('src');

            if (!jQuery(this).hasClass('sb_woo_image_disable_zoom')) {
                jQuery(this).zoom({
                    callback: function () {
                        if (!jQuery(this).hasClass('sb_woo_image_disable_lightbox')) {

                            jQuery('.wli-clone').prepend(jQuery('<a href="' + large_url + '"></a>'))

                            jQuery(this).click(function() {
                                jQuery('.wli-clone a').colorbox({rel: 'wli-clone', open: true, maxWidth: '95%', maxHeight: '95%', onClosed: function() { sb_woo_cbox_close(); }});
                            });
                            //jQuery(this).colorbox({ href: large_url });
                        }
                    }
                });
            } else {
                if (!jQuery(this).hasClass('sb_woo_image_disable_lightbox')) {

                    jQuery('.wli-clone').prepend(jQuery('<a href="' + large_url + '"></a>'))

                    jQuery(this).click(function() {
                        jQuery('.wli-clone a').colorbox({rel: 'wli-clone', open: true, maxWidth: '95%', maxHeight: '95%', onClosed: function() { sb_woo_cbox_close(); } });
                    });
                    //jQuery(this).colorbox({ href: large_url });
                }
            }
        });
    }

    if (jQuery('.single-product .cart.variations_form')) {
        ////////////////////////////////////////////////
        jQuery('.single-product .cart.variations_form .variations .value select').each(function (index, attr) {
            jQuery(this).change(function () {
                sb_woo_variation_image();
            });
        });
        ////////////////////////////////////////////////
    }

    if (jQuery('.woocommerce-remove-coupon').length) {
        jQuery('.et_pb_woo_checkout_coupon').slideUp();
    }

    //to handle removing items from the cart with a blank response. Note to edit this if no empty cart layout specified
    //jQuery(document.body).on('wc_fragments_refreshed', function () {
        //if (jQuery('body.woocommerce-cart').length && (!jQuery('.woocommerce-cart-form').length && !jQuery('.sb_et_woo_li_cart_empty').length)) {
        //console.log('Woo Injector Refreshing Cart');
        //location.reload(); //refresh the page
        //}
    //});

    //to recalculate the product count in cart
    jQuery(document.body).on('wc_fragments_loaded', function () {
        wli_refresh_cart_count();
    });

    //to recalculate the product count in cart
    jQuery(document.body).on('wc_fragments_refreshed', function () {
        wli_refresh_cart_count();
    });

    if (jQuery('body').hasClass('wli_injected')) {

        if (jQuery('.wpcf7').length > 0) {
            var wli_post_id, matches = document.body.className.match(/(^|\s)postid-(\d+)(\s|$)/);
            if (matches) {
                jQuery("input[name='_wpcf7_container_post']").val(matches[2]);
                jQuery(".wpcf7-submit").addClass('button');
                jQuery(".wpcf7-form > p").addClass('form-row');
                jQuery(".wpcf7-form > p .wpcf7-form-control-wrap input").addClass('input-text');
            }
        }

        //to add class of button to thr add to cart ajax function for consistency
        jQuery(document.body).on('added_to_cart', function () {
            setTimeout(function () {
                jQuery('.added_to_cart').addClass('button');
            }, 50);
        });

        //to handle showing the coupon system in a lightbox
        jQuery(document.body).on("checkout_error", function () {

            if (jQuery('.woocommerce-NoticeGroup').length) {
                sb_woo_popup_notice(jQuery('.woocommerce-NoticeGroup').html());
                setTimeout(function () {
                    jQuery('.woocommerce-NoticeGroup').remove();
                }, 250);
            }
        });

        //to handle showing the coupon system in a lightbox
        jQuery(document.body).on("updated_wc_div", function () {

            if (jQuery('.woocommerce .woocommerce-error').length) {
                sb_woo_popup_notice(jQuery('.woocommerce .woocommerce-error'));
                jQuery('.entry-content .woocommerce .woocommerce-error').remove();
            }
            if (jQuery('.woocommerce .woocommerce-message').length) {
                sb_woo_popup_notice(jQuery('.woocommerce .woocommerce-message').clone().wrap("<div />"));
                jQuery('.entry-content .woocommerce .woocommerce-message').remove();
            }
            if (jQuery('.cart-empty').length > 0) {
                jQuery('.et_pb_woo_cart_totals').remove();
            }
        });

        //to handle showing the coupon system in a lightbox
        jQuery(document.body).on("applied_coupon", function () {

            if (jQuery('.woocommerce .woocommerce-error').length) {
                sb_woo_popup_notice(jQuery('.woocommerce .woocommerce-error'));
                jQuery('.entry-content .woocommerce .woocommerce-error').remove();
            }
        });

        //to handle showing the coupon removed in a lightbox
        jQuery(document.body).on("removed_coupon", function () {

            if (jQuery('.woocommerce .woocommerce-message').length) {
                sb_woo_popup_notice(jQuery('.woocommerce .woocommerce-message').clone().wrap("<div />"));
                jQuery('.entry-content .woocommerce .woocommerce-message').remove();
            }
        });

        //to handle showing the coupon system in a lightbox
        jQuery(document.body).on("update_checkout", function () {

            if (jQuery('.wli_wrapper_checkout-form-coupon .woocommerce-error').length) {
                sb_woo_popup_notice(jQuery('.wli_wrapper_checkout-form-coupon .woocommerce-error').clone().wrap("<div />"));
                jQuery('.et_pb_woo_checkout_coupon').slideDown();

            } else if (jQuery('.wli_wrapper_checkout-form-coupon .woocommerce-message').length) {
                sb_woo_popup_notice(jQuery('.wli_wrapper_checkout-form-coupon .woocommerce-message').clone().wrap("<div />"));
                jQuery('.coupon-module').val('');

                if (jQuery('.woocommerce-remove-coupon').length) {
                    jQuery('.et_pb_woo_checkout_coupon').slideDown();
                } else {
                    jQuery('.et_pb_woo_checkout_coupon').slideUp();
                }

            } else if (jQuery('.woocommerce .woocommerce-message').length) {
                sb_woo_popup_notice(jQuery('.woocommerce .woocommerce-message').clone().wrap("<div />"));
                setTimeout(function () {
                    jQuery('.entry-content > .woocommerce > .woocommerce-message').remove();
                }, 250);

            }

        });
    }

});

function wli_refresh_cart_count() {
    var wli_new_count = 0;

    if (jQuery('.sb_woo_mini_cart ul li').length) {
        jQuery('.sb_woo_mini_cart ul li').each(function () {
            var wli_quantity = jQuery(this).children('.quantity').text();
            var wli_quantity_nums = wli_quantity.split(' ');
            var wli_quantity_num = parseInt(wli_quantity_nums[0]);

            wli_new_count += wli_quantity_num;
        });
    }

    if (wli_new_count <= 0) {
        wli_new_count = '';
    }

    jQuery('.sb_woo_prod_cart_container .et-cart-info span').text(wli_new_count);
}

function sb_woo_popup_notice(popup_object) {
    jQuery('html, body').scrollTop(0);

    jQuery.colorbox({
        html: popup_object,
        width: "50%",
        className: "woocommerce"
    });
}

function sb_woo_maybe_submit_checkout_coupon() {
    jQuery(this).keypress(function (e) {
        if (e.which == 13) {
            sb_woo_submit_checkout_coupon();
        }
    });
}

function sb_woo_submit_checkout_coupon() {
    if (jQuery('.coupon-module').length) {
        jQuery('.coupon-module').parent().removeClass('woocommerce-invalid').removeClass('woocommerce-validated');

        var coupon = jQuery('.coupon-module').val();

        if (coupon != '') {
            jQuery('#coupon_code').val(coupon);
            jQuery('.checkout_coupon').submit();
        } else {
            jQuery('.coupon-module').parent().addClass('woocommerce-invalid').removeClass('woocommerce-validated');
        }
    }

    return false;
}

function sb_woo_variation_image() {
    //get variation data and store in sb_woo_attr_data
    var sb_woo_attr_data = jQuery('.single-product .cart.variations_form').data('product_variations');
    var sb_woo_attr_val = '';
    var sb_woo_attr_id = '';
    var sb_woo_attr_name = '';
    var sb_woo_attr_set = [];
    var sb_woo_attr_set_l = 0;
    var sb_woo_attr_set_matched = 0;
    var sb_woo_found_set = [];
    var sb_woo_large_image = '';

    ////////////////////////////////////////////////////

    //cache current variation choices in "sb_woo_attr_set"
    jQuery('.single-product .cart.variations_form .variations .value select').each(function (index2, attr2) {
        sb_woo_attr_val = jQuery(this).val();
        sb_woo_attr_id = jQuery(this).attr('id');
        sb_woo_attr_name = 'attribute_' + sb_woo_attr_id;

        if (sb_woo_attr_val) {
            sb_woo_attr_set.push([sb_woo_attr_name, sb_woo_attr_val]);
            sb_woo_attr_set_l++;
        }
    });

    ////////////////////////////////////////////////////

    if (sb_woo_attr_set_l > 0) { //foreach of the stored attribute variables
        jQuery(sb_woo_attr_data).each(function (index3, attr3) { //loop variation prices
            var sb_woo_attrs = attr3.attributes;
            sb_woo_attr_set_matched = 0; //reset to 0

            //loop attributes linked to this attribute set
            jQuery(sb_woo_attrs).each(function (index4, attr4) {
                jQuery(attr4).each(function (index4, attr4) {
                    jQuery(sb_woo_attr_set).each(function (index5, attr5) {
                        if (attr4[attr5[0]] == attr5[1] || attr4[attr5[0]] == "") {
                            sb_woo_attr_set_matched++;
                        }
                    });
                });
            });

            if (sb_woo_attr_set_matched >= sb_woo_attr_set_l) {
                sb_woo_found_set = attr3; //we found a matching set... store it!
            }
        });

        if (typeof sb_woo_found_set.image !== 'undefined') {
            sb_woo_large_image = sb_woo_found_set.image.full_src;
        } else {
            sb_woo_large_image = jQuery('.sb_woo_product_thumb_col_num_1 a').data('large_image');
        }

        if (jQuery('.sb_woo_product_image_container').length) {
            sb_woo_product_thumb_replace_by_url(sb_woo_large_image, jQuery('.sb_woo_product_image_container:first')); //we aren't selecting the same element here so just grab the image directly
        }

    }

}

function sb_woo_cbox_close() {
    //jQuery('a.wli-core').remove();
    //jQuery('a.wli-added').remove();
}

function sb_woo_gen_hidden_images() {
    //var $gallery = jQuery('<div>').appendTo('body');
    var $gallery = jQuery('<div class="wli-clone">').hide().appendTo('body');
    var arr = jQuery('a.sb-woo-images');
    var large_image = '';

    jQuery.each(arr, function (i) {

        if (large_image = jQuery(this).data('large_image')) {
            jQuery('<a class="wli-core wli-img-'+i+'" href="' + large_image + '"></a>').appendTo($gallery);
        }
    });

    //$gallery.find('a').colorbox({rel: 'wli-clone', open: true});
}

function sb_woo_product_thumb_replace_by_url(large_image, image_object) {
    if (jQuery('.single-product .sb_woo_product_image img').attr('src') == large_image) {
        return;
    }

    var parent_object = image_object.closest('.sb_woo_product_image_container');

    if (parent_object.length == 0) {
        var parent_object = jQuery('.sb_woo_product_image_container');
    }

    if (parent_object.length) {

        parent_object.find('.sb_woo_product_image img').trigger('zoom.destroy'); // remove zoom
        parent_object.find('.sb_woo_product_image img.zoomImg').remove(); //remove old zoom image

        var image_height = parent_object.find('.sb_woo_product_image img').height();

        parent_object.find('.sb_woo_product_image').css('height', image_height + 'px');

        parent_object.find('.sb_woo_product_image img').fadeOut(400, function () {
            parent_object.find('.sb_woo_product_image img').attr('src', large_image);

            parent_object.find('.sb_woo_product_image').imagesLoaded(function () {
                var image_height = parent_object.find('.sb_woo_product_image img').height();

                parent_object.find('.sb_woo_product_image').css('height', image_height + 'px');

                parent_object.find('.sb_woo_product_image img').fadeIn(400, function () {
                    if (!parent_object.find('.sb_woo_product_image').hasClass('sb_woo_image_disable_zoom')) {
                        parent_object.find('.sb_woo_product_image').zoom({
                            callback: function () {
                                if (!parent_object.find('.sb_woo_product_image').hasClass('sb_woo_image_disable_lightbox')) {

                                    jQuery.each(jQuery('.wli-clone a'), function() {
                                        if (jQuery(this).attr('href') == parent_object.find('.sb_woo_product_image img').attr('src')) {
                                            jQuery(this).remove();
                                        }
                                    });

                                    jQuery('.wli-clone').prepend(jQuery('<a class="wli-added" href="' + parent_object.find('.sb_woo_product_image img').attr('src') + '"></a>'));

                                    //jQuery(this).colorbox({ href: parent_object.find('.sb_woo_product_image img').attr('src') });

                                    parent_object.find('.sb_woo_product_image').click(function() {
                                        jQuery('.wli-clone a').colorbox({rel: 'wli-clone', open: true, maxWidth: '95%', maxHeight: '95%', onClosed: function() { sb_woo_cbox_close(); } });
                                    });
                                }
                            }
                        });
                    } else {
                        if (!parent_object.find('.sb_woo_product_image').hasClass('sb_woo_image_disable_lightbox')) {

                            jQuery.each(jQuery('.wli-clone a'), function() {
                                if (jQuery(this).attr('href') == parent_object.find('.sb_woo_product_image img').attr('src')) {
                                    jQuery(this).remove();
                                }
                            });

                            jQuery('.wli-clone').prepend(jQuery('<a class="wli-added" href="' + parent_object.find('.sb_woo_product_image img').attr('src') + '"></a>'))

                            parent_object.find('.sb_woo_product_image').click(function() {
                                jQuery('.wli-clone a').colorbox({rel: 'wli-clone', open: true, maxWidth: '95%', maxHeight: '95%', onClosed: function() { sb_woo_cbox_close(); }});
                            });

                            //jQuery('.sb_woo_product_image').colorbox({ href: parent_object.find('.sb_woo_product_image img').attr('src') });
                        }
                    }
                });
            });
        });
    } else {
        jQuery.colorbox({
            href: large_image
        });
    }
}

function sb_woo_product_thumb_replace(image_object) {
    var large_image = image_object.data('large_image');

    sb_woo_product_thumb_replace_by_url(large_image, image_object);
};