(function(window,document,undefined){'use strict';var mindshapeYoutube={classes:{wrapper:'.msh-youtube',image:'.play-image',button:'.play-button',player:'.yt-player'},ids:{player:'yt-player-',image:'play-image-',button:'play-button-'},elements:null,numElements:0,players:{},images:{},buttons:{},urlApi:'https://www.youtube.com/iframe_api',hideImageAndPlayButton:function(that,index){document.getElementById(that.ids.image+index).style.display="none";document.getElementById(that.ids.button+index).style.display="none"},playVideoByIndex:function(that,index){if(typeof that.players[index].playVideo==="function"){that.players[index].playVideo()}},stopVideos:function(that,index){var _index;for(_index in that.players){if(_index!==index){if(typeof that.players[_index].pauseVideo==="function"){that.players[_index].pauseVideo()}}}},getPlayerIndexFromEvent:function(event){let index=null;try{index=event.target.getIframe().parentElement.dataset.index}catch(e){console.error("mindshapy_youtube_lazyloading: could determine element index");return!1}
return index},onPlayerStateChange:function(that,event){if(event.data===YT.PlayerState.PLAYING){var index=that.getPlayerIndexFromEvent(event);that.stopVideos(that,index)}},onPlayerReady:function(that,event){var index=that.getPlayerIndexFromEvent(event);that.playVideoByIndex(that,index);that.hideImageAndPlayButton(that,index)},createPlayer:function(element){var that=this;var playerOptions={height:'360',width:'640',host:element.dataset.url,playerVars:{autoplay:1,rel:element.dataset.related,start:element.dataset.start,controls:element.dataset.controls,showInfo:element.dataset.showinfo,},events:{'onReady':that.onPlayerReady.bind(null,that),'onStateChange':that.onPlayerStateChange.bind(null,that)}};if(element.dataset.type==='playlist'){playerOptions.playerVars.listType='playlist';playerOptions.playerVars.list=element.dataset.id}else{playerOptions.videoId=element.dataset.id}
that.images[element.dataset.index].addEventListener("click",function(){if(typeof that.players[element.dataset.index]==='undefined'){that.players[element.dataset.index]=new YT.Player(that.ids.player+element.dataset.index,playerOptions)}});that.buttons[element.dataset.index].addEventListener("click",function(){if(typeof that.players[element.dataset.index]==='undefined'){that.players[element.dataset.index]=new YT.Player(that.ids.player+element.dataset.index,playerOptions)}})},createPlayers:function(){if(this.numElements>0){var that=this;this.elements.forEach(function(element){that.images[element.dataset.index]=Array.prototype.slice.call(element.querySelectorAll(that.classes.image),0)[0];that.buttons[element.dataset.index]=Array.prototype.slice.call(element.querySelectorAll(that.classes.button),0)[0];that.createPlayer(element)})}},loadApi:function(){if(this.numElements>0){var script=document.createElement('script');script.src=this.urlApi;document.body.appendChild(script)}},removeEventListeners:function(){this.elements=Array.prototype.slice.call(document.querySelectorAll(this.classes.wrapper),0);this.numElements=this.elements.length;if(this.numElements>0){this.elements.forEach(function(element){element.classList.remove("cookie-consent-open");var newElement=element.cloneNode(!0);element.parentNode.replaceChild(newElement,element)})}},initElements:function(){this.elements=Array.prototype.slice.call(document.querySelectorAll(this.classes.wrapper),0);this.numElements=this.elements.length},init:function(){this.removeEventListeners();this.initElements();this.loadApi()}};window.cookieConsentLoadedMediaYouTubeLazyLoading=!1;window.addEventListener('cookieConsent',function(event){if(!1===window.cookieConsentLoadedMediaYouTubeLazyLoading&&event.detail.hasOption('youtube')){window.cookieConsentLoadedMediaYouTubeLazyLoading=!0;mindshapeYoutube.init();mindshapeYoutube.createPlayers()}})})(window,document)