"use strict";let YTAPI=!1,ytPlyaerInterval;function GS_Videos_Init(e=document){let t=e.getElementsByClassName("gs-video-element");for(let a of t){var o,s=a.dataset.provider,r=a.dataset.overlay,i=(a.dataset.lightbox,a.nextSibling);if("false"===r)switch(s){case"video":let d=document.body;a.getAttribute("src")?getGSHostedVideo(a):(d.addEventListener("mouseover",getGSHostedVideo(a),{once:!0}),d.addEventListener("touchmove",getGSHostedVideo(a),{once:!0}),d.addEventListener("scroll",getGSHostedVideo(a),{once:!0}),d.addEventListener("keydown",getGSHostedVideo(a),{once:!0}));break;case"youtube":getGSYoutubeVideo(a);break;case"vimeo":getGSVimeoVideo(a)}else i.onclick=function(){let e=this.previousSibling,t=this.dataset.type,a=this.dataset.lightbox,s=this;if("true"!==a){switch(t){case"video":getGSHostedVideo(e);break;case"youtube":getGSYoutubeVideo(e);break;case"vimeo":getGSVimeoVideo(e)}this.remove()}else{let r=e.closest(".gs-video"),i=r.getAttribute("id"),d=SimpleLightbox.open({content:e,elementClass:"gs-video-popup "+i,beforeClose:function(a){lightboxCloseHanlder(t,e,d,o),s.parentNode.insertBefore(e,s)}});switch(t){case"video":getGSHostedVideo(e,r,d);break;case"youtube":getGSYoutubeVideo(e,d);break;case"vimeo":getGSVimeoVideo(e,d)}}}}}function getGSHostedVideo(e,t="",a){let o=t||e.closest(".gs-video");if(o){let s="vidload"+o.getAttribute("id");if(!document.getElementById(s)){var r=document.createElement("video");r.setAttribute("class","gs-video-element"),r.setAttribute("src",e.dataset.src),r.setAttribute("id",s),r.setAttribute("poster",e.dataset.poster),r.autoplay="true"===e.dataset.autoplay,r.playsInline="true"===e.dataset.playsinline,r.controls="true"===e.dataset.controls,r.loop="true"===e.dataset.loop,r.muted="true"===e.dataset.mute,e.replaceWith(r),"true"===e.dataset.autoplay&&playHtml5Video(r,e,a)}}}function getGSVideoIDFromURL(e,t){var a=e.match(t);return a&&a[1]}function getGSYoutubeRegex(){return/^(?:https?:\/\/)?(?:www\.)?(?:m\.)?(?:youtu\.be\/|youtube\.com\/(?:(?:watch)?\?(?:.*&)?vi?=|(?:embed|v|vi|user)\/|shorts\/|live\/))([^?&"'>]+)/}function getGSYoutubeVideo(e,t){var a=e.dataset.src;a||(a=e.getAttribute("data-data-src"));let o=getGSVideoIDFromURL(a,getGSYoutubeRegex());var s="https://www.youtube.com/embed/"+o+"?autoplay="+("true"===e.dataset.autoplay?"1":"0")+"&loop="+("true"===e.dataset.loop?"1":"0")+"&playsinline="+("true"===e.dataset.playsinline?"1":"0")+"&controls="+("true"===e.dataset.controls?"1":"0")+"&modestbranding="+("true"===e.dataset.modestbranding?"1":"0")+"&rel="+("true"===e.dataset.rel?"1":"0")+"&mute="+("true"===e.dataset.mute?"1":"0")+(e.dataset.start&&"false"===e.dataset.loop?"&start="+e.dataset.start:"")+(e.dataset.end&&"false"===e.dataset.loop?"&end="+e.dataset.end:"")+"&enablejsapi=1"+("true"===e.dataset.loop?"&playlist="+o:"");e.setAttribute("allow","autoplay"),e.setAttribute("src",s),"true"==e.dataset.lightbox&&initYTapi(e,t)}function getGSVimeoRegex(){return/^(?:https?:\/\/)?(?:www|player\.)?(?:vimeo\.com\/)?(?:video\/|external\/)?(\d+)([^.?&#"'>]?)/}function getGSVimeoVideo(e,t){var a={id:getGSVideoIDFromURL(e.dataset.src,getGSVimeoRegex()),autoplay:"true"===e.dataset.autoplay?1:0,loop:"true"===e.dataset.loop?1:0,playsinline:"true"===e.dataset.playsinline?1:0,muted:"true"===e.dataset.mute?1:0,controls:"true"===e.dataset.controls?1:0,title:"true"===e.dataset.title?1:0,portrait:"true"===e.dataset.portrait?1:0,byline:"true"===e.dataset.byline?1:0};let o=new Vimeo.Player(e,a);isNaN(e.dataset.start)||o.setCurrentTime(parseInt(e.dataset.start));let s,r=0;"true"==e.dataset.lightbox&&o.on("timeupdate",e=>{s=e.duration,r=e.seconds,t.elaspedTime=parseInt(r)<parseInt(s-5)?r:0})}function playHtml5Video(e,t,a){try{if(e){e.currentTime=t?.dataset?.start?t.dataset.start:0;let o=e.play();if(void 0!==o&&o.then(()=>{}).catch(t=>{e.muted=!0,e.play()}),"true"==t.dataset.lightbox){let s,r=0;e.ontimeupdate=e=>{r=e.target.duration,s=e?.target?.currentTime?parseInt(e.target.currentTime):0,a.elaspedTime=s<parseInt(r-5)?s:0}}}}catch(i){}}function initYTapi(e,t,a){if(!YTAPI){var o=document.createElement("script");o.src="//www.youtube.com/iframe_api";var s=document.getElementsByTagName("script")[0];s.parentNode.insertBefore(o,s)}new Promise(e=>{YTAPI?e():window.onYouTubeIframeAPIReady=function(){e(),YTAPI=!0}}).then(function(){(a=new YT.Player(e,{})).addEventListener("onStateChange",e=>{if(e.data===YT.PlayerState.PLAYING){let o=a?.playerInfo?.duration,s=0;ytPlyaerInterval=window.setInterval(()=>{s=a?.playerInfo?.currentTime?a.playerInfo.currentTime:0,t.elaspedTime=parseInt(s)<parseInt(o-5)?s:0},900,e.target)}else window.clearInterval(ytPlyaerInterval)})})}function lightboxCloseHanlder(e,t,a,o){let s=a?.elaspedTime?a.elaspedTime:0;switch(t.setAttribute("data-start",parseInt(s)),e){case"video":break;case"youtube":window.clearInterval(ytPlyaerInterval),t.removeAttribute("src");break;case"vimeo":new Vimeo.Player(t).destroy().then(function(){}).catch(e=>console.log(e))}}GS_Videos_Init();