var G5_Woocommerce=window.G5_Woocommerce||{};(function(a){"use strict";window.G5_Woocommerce=G5_Woocommerce;var b=a("body"),c=b.hasClass("gf-lazy-load"),d=b.hasClass("rtl");G5_Woocommerce={init:function(){this.productCatalogFilter(),this.initFilterAjax(),this.updateAjaxSuccess(),this.initFilterBellow(),this.initPerfectSroll(),this.addToWishlist(),this.addToCart(),this.quickView(),this.saleCountdown();var b=a(".woocommerce-product-gallery");0<b.length&&this.singleProductImage(b),this.addCartQuantity(),this.initSingleVideo(),setTimeout(function(){G5_Woocommerce.setCartScrollBar()},500),this.events(),a("select.country_to_state, input.country_to_state").trigger("change")},updateAjaxSuccess:function(){var a=this;b.on("gf_pagination_ajax_success",function(c,d,e,f){"product"===d.settings.post_type&&(G5_Core.pagination_ajax.updatePageTitle(d,e,f),G5_Core.pagination_ajax.updateSideBar(d,e,f),a.updateAboveCustomize(d,e,f),G5_Core.util.tooltip(),G5_Woocommerce.saleCountdown(),b.trigger("gf_woocommerce_ajax_success",[d,e,f]))}),b.on("gf_pagination_ajax_before_update_sidebar",function(b,c){"product"===c.settings.post_type&&a.initWidgetAjaxSuccess()})},initFilterAjax:function(){a(document).on("click",".clear-filter-wrap a, .gf-price-filter a, .gf-product-sorting a, .gf-attr-filter-content a, .gf-product-category-filter a, .product-categories a,.woocommerce-widget-layered-nav a",function(b){var c=a("[data-archive-wrapper]");if(0<c.length){b.preventDefault();var d=c.data("items-wrapper");G5_Core.pagination_ajax.loadPosts(d,this)}})},initFilterBellow:function(){var b=a("#primary-content"),c=a(".gsf-catalog-filter");c.length&&(c.detach().insertBefore(b),c.removeAttr("hidden")),a(document).off("click",".gf-filter-bellow").on("click",".gf-filter-bellow",function(){a("#gf-filter-content").slideToggle("500"),G5_Woocommerce.initPerfectSroll()})},updateAboveCustomize:function(b,c,d){var e=0<a(d).closest("[data-items-paging]").length&&(b.settings.post_paging===G5_Core.pagination_ajax.paging.loadMore||b.settings.post_paging===G5_Core.pagination_ajax.paging.infiniteScroll),f=a(".gsf-catalog-filter");if(0<f.length&&!e&&"undefined"!=typeof b.settings.isMainQuery&&!0===b.settings.isMainQuery){var g=c.find(".gsf-catalog-filter");0<g.length&&(f.replaceWith(g.removeAttr("hidden").prop("outerHTML")),a(".woocommerce-ordering").off("change").on("change","select.orderby",function(){a(this).closest("form").submit()}),a(".gsf-pretty-tabs").each(function(){a(this).gsfPrettyTabs()}),G5_Woocommerce.initPerfectSroll())}},initWidgetAjaxSuccess:function(){this.initPriceFilter()},initPriceFilter:function(){if("undefined"!=typeof a().slider){a("input#min_price, input#max_price").hide(),a(".price_slider, .price_label").show();var b=a(".price_slider_amount #min_price").data("min"),c=a(".price_slider_amount #max_price").data("max"),d=a(".price_slider_amount #min_price").val(),e=a(".price_slider_amount #max_price").val();a(".price_slider:not(.ui-slider)").slider({range:!0,animate:!0,min:b,max:c,values:[d,e],create:function(){a(".price_slider_amount #min_price").val(d),a(".price_slider_amount #max_price").val(e),a(document.body).trigger("price_slider_create",[d,e])},slide:function(b,c){a("input#min_price").val(c.values[0]),a("input#max_price").val(c.values[1]),a(document.body).trigger("price_slider_slide",[c.values[0],c.values[1]])},change:function(b,c){a(document.body).trigger("price_slider_change",[c.values[0],c.values[1]])}})}},initPerfectSroll:function(){a(".widget-product-category-filter ul.product-categories","#gf-filter-content").perfectScrollbar({wheelSpeed:.5,suppressScrollX:!0})},addToWishlist:function(){a(document).on("click",".add_to_wishlist",function(){var b=a(this),c=b.parent().parent();if(!c.parent().hasClass("single-product-function")){b.addClass("added-spinner");var d=c.parent().parent().parent().parent();if("undefined"==typeof d)return;d.addClass("active")}}),b.on("added_to_wishlist",function(){var b=a(".added-spinner.add_to_wishlist"),c=b.parent().parent();if(!c.parent().hasClass("single-product-function")){var d=c.parent().parent().parent().parent();if("undefined"==typeof d)return;setTimeout(function(){d.removeClass("active"),b.removeClass("added-spinner")},700)}})},addToCart:function(){a(document).on("click",".add_to_cart_button",function(){var b=a(this);if(b.hasClass("ajax_add_to_cart")){var c=b.closest(".product-item-wrap");if("undefined"==typeof c)return;c.addClass("active")}}),b.on("wc_cart_button_updated",function(b,c){var d=a(".header-sticky-wrapper .header-sticky"),e=a(".item-shopping-cart",d),f=c.hasClass("single_add_to_cart_button");if(!f){var g=c.parent(),h=g.find(".added_to_cart"),i=h.text(),j=g.closest(".product-item-inner");c.closest(".gf-product-swatched").length||c.remove(),g.data("toggle")&&(h.html("<i class=\"fa fa-check\"></i> "+i),setTimeout(function(){g.tooltip("hide").attr("title",i).tooltip("_fixTitle")},500)),setTimeout(function(){G5_Woocommerce.setCartScrollBar(function(){if(0<e.length){var a=0;d.hasClass("header-hidden")&&(d.removeClass("header-hidden"),a=500),setTimeout(function(){e.addClass("show-cart"),setTimeout(function(){e.removeClass("show-cart")},2e3)},a)}})},10),setTimeout(function(){j.removeClass("active")},700)}}),b.on("removed_from_cart",function(){setTimeout(function(){G5_Woocommerce.setCartScrollBar(),a(document.body).trigger("update_checkout");var b=a("[name=\"update_cart\"]");b.length&&b.removeAttr("disabled").trigger("click")},10)})},setCartScrollBar:function(b){a(".cart_list.product_list_widget").perfectScrollbar({wheelSpeed:.5,suppressScrollX:!0}),b&&b()},quickView:function(){var c=!1;a(document).on("click",".product-quick-view",function(d){if(d.preventDefault(),!c){c=!0;var e=a(this),f=e.data("product_id"),g=e.find("i"),h=g.attr("class"),i=e.closest(".product-item-wrap"),j=e;i.addClass("active"),j.addClass("active"),g.attr("class","fal fa-spinner fa-spin"),a.ajax({url:g5plus_variable.ajax_url,data:{action:"product_quick_view",id:f},success:function(d){i.removeClass("active"),j.removeClass("active"),g.attr("class",h);a(".modal-body","#popup-product-quick-view-wrapper");a("#popup-product-quick-view-wrapper").length&&a("#popup-product-quick-view-wrapper").remove(),b.append(d);var e=a(".quick-view-product-image","#popup-product-quick-view-wrapper");if("undefined"!=typeof a.fn.wc_variation_form){var f=a("#popup-product-quick-view-wrapper").find(".variations_form"),k=a("#popup-product-quick-view-wrapper").find(".variations_form .variations select");f.wc_variation_form(),f.trigger("check_variations"),k.change()}a("#popup-product-quick-view-wrapper").modal(),"undefined"!=typeof a.fn.wc_product_gallery&&setTimeout(function(){a(".woocommerce-product-gallery",e).wc_product_gallery(),G5_Woocommerce.singleProductImage(e),G5_Woocommerce.initSingleVideo()},200),G5_Core.util.tooltip(),G5_Woocommerce.saleCountdown(),G5_Core.util.magnificPopup(e),b.trigger("gf_quick_view_success"),G5_Woocommerce.addCartQuantity(),c=!1},error:function(){c=!1}})}})},saleCountdown:function(){function b(b,c){var d=parseInt(b.offset.seconds),e=parseInt(b.offset.minutes),f=parseInt(b.offset.hours),g=parseInt(b.offset.totalDays);10>g&&(g="0"+g),10>f&&(f="0"+f),10>e&&(e="0"+e),10>d&&(d="0"+d),a(".countdown-day",c).text(g),a(".countdown-hours",c).text(f),a(".countdown-minutes",c).text(e),a(".countdown-seconds",c).text(d)}a(".product-deal-countdown").each(function(){var c=a(this).data("date-end"),d=a(this);d.countdown(c,function(a){b(a,d)}).on("update.countdown",function(a){b(a,d)})}),G5_Woocommerce.saleCountdownWidth()},saleCountdownWidth:function(){a(".product-deal-countdown").each(function(){if(!a(this).parents().hasClass("gsf-product-deal")){var b=0;a(this).removeClass("small"),a(".countdown-section",a(this)).each(function(){b+=a(this).outerWidth()+parseInt(a(this).css("margin-right").replace("px",""),10)}),b>a(this).outerWidth()&&a(this).addClass("small")}else{var c=0;a(this).removeClass("small"),a(".countdown-section",a(this)).each(function(){c+=a(this).innerHeight()+parseInt(a(this).css("margin-top").replace("px",""),10)}),c>a(this).outerHeight()&&a(this).addClass("small")}})},singleProductImage:function(a){var e=a.find(".flex-control-thumbs"),f=4;e.length&&(e.attr("hidden","hidden"),0!==e.closest(".quick-view-product-image").length&&(f=3),e.closest(".product-single-layout-01").length?e.on("initialized.owl.carousel",function(){setTimeout(function(){e.removeAttr("hidden")},500)}).addClass("owl-carousel owl-theme").owlCarousel({nav:!1,dots:!1,rtl:d,lazyLoad:c,margin:10,responsive:{1200:{items:f},992:{items:3},768:{items:4},576:{items:4},0:{items:4}}}):(e.removeAttr("hidden"),b.hasClass("no-sidebar")&&(f=6),e.slick({swipeToSlide:!0,infinite:!1,slidesToShow:f,slidesToScroll:2,speed:400,arrows:!1,vertical:!0,verticalSwiping:!0,rtl:d,responsive:[{breakpoint:1400,settings:{slidesToShow:f,vertical:!1,verticalSwiping:!1}},{breakpoint:992,settings:{slidesToShow:3,vertical:!1,verticalSwiping:!1}},{breakpoint:768,settings:{slidesToShow:4,vertical:!1,verticalSwiping:!1}},{breakpoint:576,settings:{slidesToShow:4,vertical:!1,verticalSwiping:!1}},{breakpoint:320,settings:{slidesToShow:4,vertical:!1,verticalSwiping:!1}}]})))},addCartQuantity:function(){a(document).off("click",".quantity .btn-number").on("click",".quantity .btn-number",function(b){b.preventDefault();var c=a(this).data("type"),d=a("input",a(this).parent()),e=parseFloat(d.val()),f=parseFloat(d.attr("max")),g=parseFloat(d.attr("min")),h=parseFloat(d.attr("step")),i=0;0<d.attr("step").indexOf(".")&&(i=d.attr("step").split(".")[1].length),isNaN(f)&&(f=100),isNaN(g)&&(g=0),isNaN(h)&&(h=1,i=0),isNaN(e)?d.val(g):("minus"==c&&(e>g&&(e=(e-h).toFixed(i),d.val(e).change()),parseFloat(d.val())<=g&&(d.val(g).change(),a(this).attr("disabled",!0))),"plus"==c&&(e<f&&(e=(e+h).toFixed(i),d.val(e).change()),parseFloat(d.val())>=f&&(d.val(f).change(),a(this).attr("disabled",!0))))}),a("input",".quantity").on("focusin",function(){a(this).data("oldValue",a(this).val())}),a("input",".quantity").on("change",function(){var b=a(this),c=parseFloat(b.attr("max")),d=parseFloat(b.attr("min")),e=parseFloat(b.val()),f=parseFloat(b.attr("step"));isNaN(c)&&(c=100),isNaN(d)&&(d=0),isNaN(f)&&(f=1);var g=a(".add_to_cart_button",a(this).parent().parent().parent());e>=d?(a(".btn-number[data-type='minus']",a(this).parent()).removeAttr("disabled"),"undefined"!=typeof g&&g.attr("data-quantity",e)):(alert("Sorry, the minimum value was reached"),a(this).val(a(this).data("oldValue")),"undefined"!=typeof g&&g.attr("data-quantity",a(this).data("oldValue"))),e<=c?(a(".btn-number[data-type='plus']",a(this).parent()).removeAttr("disabled"),"undefined"!=typeof g&&g.attr("data-quantity",e)):(alert("Sorry, the maximum value was reached"),a(this).val(a(this).data("oldValue")),"undefined"!=typeof g&&g.attr("data-quantity",a(this).data("oldValue")))})},initSingleVideo:function(){var b=a(".product-gallery__video"),c=a(".woocommerce-product-gallery");b.length&&c.length&&(b=b.detach(),c.prepend(b),b.removeAttr("hidden"))},productCatalogFilter:function(){a(".gsf-catalog-filter").each(function(){var c=a(this).find(".gsf-catalog-filter-cat-filter");0!==c.length&&(c.closest(".gsf-catalog-filter-item").css("flex","1 0 0%").siblings().css("flex",""),setTimeout(function(){b.find(".gsf-pretty-tabs").gsfPrettyTabs()},10))})},events:function(){a(window).on("resize",function(){G5_Woocommerce.saleCountdown()})}},a(document).ready(function(){G5_Woocommerce.init()})})(jQuery);