!function($){"use strict";class WCGSGallery{constructor(){this.namespace=".wcgsGallery",this.players=[],this.wcgs_spswiper_thumb=null,this.wcgs_spswiper_gallery=null,this.settings=wcgs_object.wcgs_settings,this.wcgs_body_font_size=parseInt(wcgs_object.wcgs_body_font_size),this.playbackTimes={},this.publicUrl=wcgs_object.wcgs_public_url,this.fancyLoaded=!1,this.spswiperLoaded=!1,this.lazyAttr=this.settings.wcgs_image_lazy_load&&"ondemand"==this.settings.wcgs_image_lazy_load?'loading = "lazy"':"",this.$gallery=$("#wpgs-gallery"),this.$summary=this.$gallery.next(".summary"),this.bindEventHandlers(),jQuery(()=>this.initialize())}bindEventHandlers(){this.handleResize=this.handleResize.bind(this),this.handleLightboxClick=this.handleLightboxClick.bind(this),this.handleVariationChange=this.handleVariationChange.bind(this),this.handleYouTubeStateChange=this.handleYouTubeStateChange.bind(this),this.handleSlideChange=this.handleSlideChange.bind(this)}initialize(){this.setupImageLoading(),this.initializeYouTube(),this.setupEventHandlers(),this.initializeGallery(),this.$gallery.wpgspimagesLoaded().then(()=>{this.hidePreloader()}),this.addGrayscale()}SPSwiperSlide(selector,options){return"undefined"!=typeof SPSwiper?new SPSwiper(selector,options):"undefined"!=typeof SPSwiper?new SPSwiper(selector,options):(console.log("SPSwiper is undefined"),!1)}setupImageLoading(){$.fn.wpgspimagesLoaded=function(){const $imgs=this.find('img[src!=""]');if(!$imgs.length)return $.Deferred().resolve().promise();const dfds=[];return $imgs.each((function(index){if(1==index){const dfd=$.Deferred();dfds.push(dfd);const img=new Image;img.onload=()=>dfd.resolve(),img.onerror=()=>dfd.resolve(),img.src=this.src}})),$.when.apply($,dfds)}}initializeYouTube(){"inline"===this.settings.video_popup_place&&(this.addYouTubeScript(),this.checkYouTubeReady())}addYouTubeScript(){const scriptId="youtube-api";if(!document.getElementById(scriptId)){const tag=document.createElement("script");tag.src="https://www.youtube.com/iframe_api",tag.id=scriptId,document.getElementsByTagName("script")[0].parentNode.insertBefore(tag,document.getElementsByTagName("script")[0])}}checkYouTubeReady(){const interval=setInterval(()=>{"object"==typeof YT&&"function"==typeof YT.Player&&(clearInterval(interval),this.initializeYouTubePlayers())},300)}initializeYouTubePlayers(){$(".wcgs-youtube-video").each((index,element)=>{const videoId=$(element).data("video-id");this.players[videoId]=new YT.Player(element,{videoId:videoId,playerVars:{modestbranding:1,showinfo:0,fs:1},events:{onStateChange:this.handleYouTubeStateChange}})})}initializeFancyboxScript(){const fancyboxScriptId="wcgs-fancybox-js";if(!document.getElementById(fancyboxScriptId)){const jsTag=document.createElement("script");jsTag.src=this.publicUrl+"js/fancybox-bundle.min.js",jsTag.id=fancyboxScriptId,jsTag.defer=!0;const firstScript=document.getElementsByTagName("script")[0];firstScript.parentNode.insertBefore(jsTag,firstScript)}}initializeSwiperScript(){const swiperScriptId="wcgs-swiper-js";if(!document.getElementById(swiperScriptId)){const jsTag=document.createElement("script");jsTag.src=this.publicUrl+"js/swiper.min.js",jsTag.id=swiperScriptId,jsTag.defer=!0;const firstScript=document.getElementsByTagName("script")[0];firstScript.parentNode.insertBefore(jsTag,firstScript)}}checkSPSwiperAPIReady(){if("undefined"!=typeof SPSwiper)return this.spswiperLoaded=!0,void this.initializeSPSwipers();const checkInterval=setInterval(()=>{this.initializeSwiperScript(),"function"==typeof SPSwiper&&(clearInterval(checkInterval),this.spswiperLoaded=!0,this.initializeSPSwipers())},300);setTimeout(()=>{clearInterval(checkInterval),this.spswiperLoaded||console.log("SPSwiper script failed to load")},1e4)}checkFancyboxReady(){if("undefined"!=typeof Fancybox)return this.fancyLoaded=!0,void this.initializeLightbox();const checkInterval=setInterval(()=>{this.initializeFancyboxScript(),"undefined"!=typeof Fancybox&&(clearInterval(checkInterval),this.fancyLoaded=!0,this.initializeLightbox())},300);setTimeout(()=>{this.fancyLoaded||clearInterval(checkInterval)},5e3)}handleYouTubeStateChange(event){const videoId=event.target.getIframe().id;[YT.PlayerState.PAUSED,YT.PlayerState.ENDED].includes(event.data)&&(this.playbackTimes[videoId]=event.target.getCurrentTime())}setupEventHandlers(){$(window).off(this.namespace),$(document).off(this.namespace),$(window).on(`resize${this.namespace}`,this.handleResize),$(document).on(`click${this.namespace}`,".wcgs-carousel .wcgs-lightbox, .wcgs-carousel .wcgs-video-icon, .wcgs-carousel .wcgs-photo",this.handleLightboxClick),$(document).on(`change${this.namespace}`,"form.variations_form .variations select, form.variations_form .variations input[type=radio]",this.handleVariationChange),this.settings.zoom&&$(".wcgs-slider-image").off(this.namespace).on(`mouseenter${this.namespace} mouseleave${this.namespace} mousemove${this.namespace}`,e=>this.handleZoom(e)),"1"!==this.settings.navigation&&!0!==this.settings.navigation||(this.$gallery.find(".gallery-navigation-carousel .wcgs-spswiper-button-next").off(this.namespace).on(`click${this.namespace}`,()=>{this.$gallery.find(".wcgs-carousel .wcgs-spswiper-button-next").trigger("click")}),this.$gallery.find(".gallery-navigation-carousel .wcgs-spswiper-button-prev").off(this.namespace).on(`click${this.namespace}`,()=>{this.$gallery.find(".wcgs-carousel .wcgs-spswiper-button-prev").trigger("click")}))}initializeGallery(){this.videoIcon(),this.calculateDimensions(),this.checkSPSwiperAPIReady(),this.checkFancyboxReady()}calculateDimensions(){let gallery_w=this.settings.gallery_width;if($("body").hasClass("et_divi_builder")||$("body").hasClass("theme-Divi")){var gallery_divi_width=$(".wcgs-gallery-slider.et-db #et-boc .et-l .et_pb_gutters3 .et_pb_column_1_2").width();"number"==typeof gallery_divi_width&&(gallery_w=gallery_divi_width)}if($("body").hasClass("theme-flatsome")){var gallery_flatsome_width=$(".single-product .product .row.content-row .product-gallery").width();"number"==typeof gallery_flatsome_width&&(gallery_w=gallery_flatsome_width)}if($(".wcgs-woocommerce-product-gallery").parents(".hestia-product-image-wrap").length){var gallery_hestia_width=$(".wcgs-woocommerce-product-gallery").parents(".hestia-product-image-wrap").width();"number"==typeof gallery_hestia_width&&(gallery_w=gallery_hestia_width)}if(!$("#wpgs-gallery ~ .summary").length){let gallery_width=this.$gallery.parent("*").outerWidth();"number"==typeof gallery_width&&gallery_width>50&&(gallery_w=gallery_width)}$(window).width()<992&&this.settings.gallery_responsive_width.width>0&&(gallery_w=this.settings.gallery_responsive_width.width),$(window).width()<768&&(gallery_w=this.settings.gallery_responsive_width.height),$(window).width()<480&&(gallery_w=this.settings.gallery_responsive_width.height2);let widthUnit=this.getWidthUnit();if(gallery_w>100){widthUnit="px";let currentGLWidth=this.$gallery.parent().outerWidth();gallery_w=currentGLWidth>gallery_w?gallery_w:currentGLWidth}if(this.$gallery.css({minWidth:"auto",maxWidth:`${gallery_w}${widthUnit}`}),this.updateSummaryWidth(gallery_w),"vertical"==this.settings.gallery_layout||"vertical_right"==this.settings.gallery_layout){let maxHeight=this.getMaxImageHeight();this.$gallery.find(".gallery-navigation-carousel-wrapper").css({maxHeight:maxHeight})}setTimeout(()=>{if("vertical"==this.settings.slide_orientation){let maxHeight=this.getMaxImageHeight();this.$gallery.find(".wcgs-carousel .spswiper-slide, .wcgs-carousel").css({height:maxHeight})}if("vertical"==this.settings.gallery_layout||"vertical_right"==this.settings.gallery_layout){let maxHeight=this.getMaxImageHeight();this.$gallery.find(".gallery-navigation-carousel-wrapper").css({maxHeight:maxHeight})}},1e3)}getMaxImageHeight(){let maxHeight=0;const thumbnails_sliders_space=this.settings.thumbnails_sliders_space?this.settings.thumbnails_sliders_space.width:6;let gallery;const actualWidth=this.$gallery.find(".wcgs-carousel").width();return this.$gallery.find(".wcgs-carousel img").each((function(){if($(this).attr("height")&&$(this).attr("width")){const attrWidth=parseInt($(this).attr("width"),10),attrHeight=parseInt($(this).attr("height"),10);if(attrWidth&&attrHeight){const ratio=attrHeight/attrWidth,estimatedHeight=actualWidth*ratio;estimatedHeight>maxHeight&&(maxHeight=estimatedHeight)}}else $(this).innerHeight()>maxHeight&&(maxHeight=$(this).innerHeight())})),maxHeight}getWidthUnit(){return window.innerWidth<768?this.settings.gallery_responsive_width.unit:"%"}updateSummaryWidth(galleryWidth){const summaryWidth=100-galleryWidth;this.$summary.css("maxWidth",summaryWidth>20?`calc(${summaryWidth}% - 30px)`:"")}getThumbAutoplaySettings(){return"1"==this.settings.autoplay&&{delay:parseInt(this.settings.autoplay_interval)||3e3,pauseOnMouseEnter:!1}}handleAutoplayEvents(){this.settings.autoplay&&"1"==this.settings.autoplay&&this.$gallery.on({mouseenter:()=>{this.wcgs_spswiper_gallery&&this.wcgs_spswiper_gallery.autoplay&&this.wcgs_spswiper_gallery.autoplay.stop()},mouseleave:()=>{this.wcgs_spswiper_gallery&&this.wcgs_spswiper_gallery.autoplay&&this.wcgs_spswiper_gallery.autoplay.start()}})}initializeSPSwipers(){const thumbnail_nav="1"===this.settings.thumbnailnavigation||!0===this.settings.thumbnailnavigation,navigation="1"===this.settings.navigation||!0===this.settings.navigation,thumbnails_sliders_space=this.settings.thumbnails_sliders_space?this.settings.thumbnails_sliders_space.width:6,slider_autoplay=!(!this.settings.autoplay||"1"!=this.settings.autoplay)&&this.getThumbAutoplaySettings();let $swiperThumbContainer=this.$gallery.find(".gallery-navigation-carousel"),$mainSliderContainer=this.$gallery.find(".wcgs-carousel"),wcgs_img_count=this.$gallery.find(".wcgs-carousel .spswiper-slide").length;const galleryLayout="vertical"==this.settings.gallery_layout||"vertical_right"==this.settings.gallery_layout?"vertical":"horizontal",thumbnails_item_to_show="vertical"==this.settings.gallery_layout||"vertical_right"==this.settings.gallery_layout?"auto":parseInt(this.settings.thumbnails_item_to_show);this.wcgs_spswiper_thumb=this.SPSwiperSlide($swiperThumbContainer[0],{slidesPerView:thumbnails_item_to_show,direction:galleryLayout,watchSlidesVisibility:!0,watchSlidesProgress:!0,autoHeight:!1,watchOverflow:!0,lazyPreloadPrevNext:1,loop:"1"===this.settings.infinite_loop,spaceBetween:parseInt(thumbnails_sliders_space),freeMode:"1"===this.settings.free_mode,mousewheel:"1"===this.settings.mouse_wheel,on:{afterInit:()=>this.handleSPSwiperInit()}}),"top_line"==this.settings.thumbnail_style&&this.setupThumbnailBottomLine();let adaptive_height=!(!this.settings.slider_height_type||"adaptive"!=this.settings.slider_height_type);this.wcgs_spswiper_gallery=this.SPSwiperSlide($mainSliderContainer[0],{autoHeight:adaptive_height,direction:this.settings.slide_orientation||"horizontal",loop:"1"===this.settings.infinite_loop,thumbs:{spswiper:this.wcgs_spswiper_thumb},autoplay:slider_autoplay,lazyPreloadPrevNext:1,slidesPerView:1,spaceBetween:1,effect:this.settings.fade_slide,speed:parseInt(this.settings.autoplay_speed)||300,observer:!0,watchOverflow:!0,observeParents:!0,a11y:"1"===this.settings.accessibility&&{prevSlideMessage:"Previous slide",nextSlideMessage:"Next slide"},navigation:navigation?{nextEl:".wcgs-carousel .wcgs-spswiper-button-next",prevEl:".wcgs-carousel .wcgs-spswiper-button-prev"}:!!thumbnail_nav&&{nextEl:".gallery-navigation-carousel .wcgs-spswiper-button-next",prevEl:".gallery-navigation-carousel .wcgs-spswiper-button-prev"},pagination:"1"===this.settings.pagination&&{el:".wcgs-carousel .spswiper-pagination",type:"bullets",dynamicBullets:"dynamic"===this.settings.pagination_type,clickable:!0},on:{slideChange:this.handleSlideChange}}),this.wcgs_spswiper_gallery.init(),setTimeout(()=>{this.$gallery.removeClass("wcgs-spswiper-before-init"),this.handleAutoplayEvents()},400),this.checkArrowsVisibility(),"hide_thumb"!==this.settings.gallery_layout&&(wcgs_img_count<=1?(this.$gallery.find(".gallery-navigation-carousel-wrapper").addClass("wcgs-hidden").hide(),this.$gallery.find(".wcgs-spswiper-arrow").hide()):(this.$gallery.find(".gallery-navigation-carousel-wrapper").removeClass("wcgs-hidden").show(),this.$gallery.find(".wcgs-spswiper-arrow:not(.swiper-button-lock)").show()))}navigationVisibility(){let navigation_visibility="hover"==this.settings.navigation_visibility,$gallery=this.$gallery,thumb_navigation_visibility;var pagination_visibility;navigation_visibility&&($gallery.find(".wcgs-carousel .wcgs-spswiper-arrow").hide(),$gallery.find(".wcgs-carousel .wcgs-spswiper-arrow").css("opacity",1),$gallery.find(".wcgs-carousel").on({mouseenter:()=>{this.$gallery.find(".wcgs-carousel .wcgs-spswiper-arrow:not(.spswiper-button-lock)").show()},mouseleave:()=>{this.$gallery.find(".wcgs-carousel .wcgs-spswiper-arrow:not(.spswiper-button-lock)").hide()}})),"hover"==this.settings.thumb_nav_visibility&&(this.$gallery.find(".gallery-navigation-carousel .wcgs-spswiper-arrow").hide(),this.$gallery.find(".gallery-navigation-carousel").on({mouseenter:()=>{this.$gallery.find(".gallery-navigation-carousel .wcgs-spswiper-arrow:not(.spswiper-button-lock)").show()},mouseleave:()=>{this.$gallery.find(".gallery-navigation-carousel .wcgs-spswiper-arrow").hide()}})),"hover"==this.settings.pagination_visibility&&(this.$gallery.find(".spswiper-pagination").hide(),this.$gallery.find(".wcgs-carousel").on({mouseenter:()=>{this.$gallery.find(".spswiper-pagination").show()},mouseleave:()=>{this.$gallery.find(".spswiper-pagination").hide()}}))}handleSPSwiperInit(){setTimeout(()=>{this.$gallery.removeClass("wcgs-spswiper-before-init")},400)}checkArrowsVisibility(){setTimeout(()=>{var allowSlidePrev=void 0!==this.wcgs_spswiper_thumb.allowSlidePrev&&this.wcgs_spswiper_thumb.allowSlidePrev,allowSlideNext=void 0!==this.wcgs_spswiper_thumb.allowSlideNext&&this.wcgs_spswiper_thumb.allowSlideNext;allowSlidePrev||allowSlideNext?this.$gallery.find(".gallery-navigation-carousel-wrapper .wcgs-spswiper-arrow:not(.spswiper-button-lock)").show():this.$gallery.find(".gallery-navigation-carousel-wrapper .wcgs-spswiper-arrow").addClass("spswiper-button-lock").hide(),this.navigationVisibility()},300)}handleSlideChange(){setTimeout(()=>{this.pausePreviousVideo()},500)}pausePreviousVideo(){if(this.wcgs_spswiper_gallery&&void 0!==this.wcgs_spswiper_gallery.previousIndex){const prevIndex=this.wcgs_spswiper_gallery.previousIndex,$prevSlide=$(`.wcgs-carousel .spswiper-slide:eq(${prevIndex})`),videoId=$prevSlide.find(".wcgs-youtube-video").data("video-id");videoId&&this.players[videoId]&&this.players[videoId].pauseVideo()}}handleZoom(e){var scale_level=this.settings.zoom_type&&"zoom_2x"==this.settings.zoom_type?2:1.5;if("1"!=this.settings.zoom)return;if($(window).width()<480&&"1"!=this.settings.mobile_zoom)return;const $target=$(e.currentTarget),scale="mouseenter"===e.type||"mousemove"===e.type?scale_level:1;this.initializeZoomElement($target),$target.find(".wcgs-photo").css({transform:`scale(${scale})`,transformOrigin:this.getTransformOrigin(e)})}getTransformOrigin(e){const offset=$(e.currentTarget).offset(),x=(e.pageX-offset.left)/$(e.currentTarget).width()*100,y=(e.pageY-offset.top)/$(e.currentTarget).height()*100;return`${x}% ${y}%`}initializeZoomElement(element){const $element=element;$element.find(".wcgs-photo").length||$element.append('
'),$element.find(".wcgs-photo").css("background-image",`url(${$element.find("img").attr("src")})`)}getLightboxButtons(){const buttons=["zoom"];return"1"===this.settings.gallery_fs_btn&&buttons.push("fullscreen"),buttons.push("close"),buttons}addGrayscale(){if("gray_off"!==this.settings.grayscale){let grayClass=this.settings.grayscale;$(".wcgs-slider-image img").addClass(""+grayClass)}}initializeLightbox(){if("undefined"==typeof Fancybox)return;let lightbox_thumb_style="classic",gallery_middle_btn="1";Fancybox.bind("[data-fancybox]",{backdropClick:"close",mainClass:"wcgs-fancybox-wrapper",animated:!0,animationDuration:1e3,Toolbar:{display:{left:"1"==this.settings.l_img_counter?["infobar"]:"",middle:[],right:this.getLightboxButtons()}},Thumbs:!1,Carousel:{Panzoom:{decelFriction:.5},transition:this.settings.lightbox_sliding_effect||"slide",transitionDuration:1e3},Image:{zoom:!0,preload:3,click:"toggleZoom",wheel:"zoom",imageProtection:!0},Video:{autoplay:!0,loop:!0,mute:!0,ratio:16/9},caption:(fancybox,slide)=>{if("1"==this.settings.lightbox_caption){const caption=slide.caption||"";return caption}return""},dragToClose:!0,on:{reveal:(fancybox,slide)=>{$(document).find(".wcgs-carousel .wcgs-slider-image img").each((i,img)=>{const imageUrl=$(img).attr("data-lazy"),thumbnailSelector=$(".wcgs-fancybox-wrapper .fancybox-thumbs__list a:nth("+i+")"),thumbnailUrl=thumbnailSelector.attr("style");imageUrl&&thumbnailSelector.length>0&&thumbnailUrl.indexOf("spinner.svg")>=0&&thumbnailSelector.css("background-image","url("+imageUrl+")")}),$(".wcgs-fancybox-wrapper ~ .elementor-lightbox").remove()}}})}handleResize(){this.calculateDimensions(),this.wcgs_spswiper_thumb&&this.wcgs_spswiper_thumb.update(),this.wcgs_spswiper_gallery&&this.wcgs_spswiper_gallery.update()}handleLightboxClick(e){if(e.preventDefault(),$(e.currentTarget).hasClass("wcgs-video-icon")){let current_selector=$(e.currentTarget).parents(".wcgs-carousel").find(".spswiper-slide-active a.wcgs-slider-lightbox");return void(current_selector.length>0&¤t_selector[0].click())}const lightboxEnabled="1"===this.settings.lightbox||!0===this.settings.lightbox;if(!lightboxEnabled)return;let current_selector=$(e.currentTarget).parents(".wcgs-carousel").find(".spswiper-slide-active a.wcgs-slider-lightbox");current_selector.length>0&¤t_selector[0].click()}setupGridLightbox(){if(!this.settings.lightbox)return;let is_only_popup=this.state.videoOnlyPopup;$(document).off("click.wcgsLb"),$(document).on(`click${this.namespace}`,".wcgs-carousel .wcgs-lightbox, .wcgs-carousel .wcgs-video-icon, .wcgs-carousel .wcgs-photo",(function(e){if(e.preventDefault(),$(e.target).hasClass("wcgs-video-icon")&&!is_only_popup)return;let current_selector=$(this).parents(".wcgs-slider-image").find("a.wcgs-slider-lightbox");current_selector.length>0&¤t_selector[0].click()}))}videoIcon(){$(".wcgs-slider-image, .wcgs-thumb").each((i,el)=>{$(el).find("img").data("type")&&$(el).append('')})}handleVariationChange(e){const data=wcgs_object.wcgs_data||[],$variations_table=$(e.target).closest(".variations"),variations=this.getSelectedVariations($variations_table);this.updateGalleryBasedOnVariations(variations,data)}updateGalleryBasedOnVariations(variationsArray,data){const matchingItems=this.findMatchingVariations(data,variationsArray);matchingItems.length&&this.rebuildGallery(matchingItems)}getSelectedVariations($variations_table){let variationsArray={};return $variations_table.find("tr, .aux-dropdown").each((index,element)=>{let attributeName=$(element).find("select").data("attribute_name"),attributeValue=$(element).find("select").val();$(element).find("input[type=radio]").length>0&&(attributeName=$(element).find("input[type=radio]:checked").attr("name"),attributeValue=$(element).find("input[type=radio]:checked").val()),!attributeName||attributeName in variationsArray||(variationsArray[attributeName]=attributeValue)}),this.areAllAttributesEmpty(variationsArray)?{}:variationsArray}areAllAttributesEmpty(variation){for(let key in variation)if(variation[key]&&""!==variation[key].trim())return!1;return!0}isMatch(variation_attributes,attributes){let match=!0;for(let attr_name in variation_attributes)if(variation_attributes.hasOwnProperty(attr_name)){let val1=variation_attributes[attr_name],val2=attributes[attr_name];void 0!==val1&&void 0!==val2&&0!==val1.length&&0!==val2.length&&val1!==val2&&(match=!1)}return match}findMatchingVariations(variations,attributes){let matching=[];for(let i=0;i