"use strict";define(["notifications"],function(o){return function(e,t,n){n=n||".owl-wrapper";var i=$.extend({closeOnEnd:!0,autoplay:!1},t);return{elements:{$container:$(e),$youtube:$(e).find(".youtube-container"),$youtubeClose:$(e).find(".youtube-close"),$videoBg:$(e).find(".youtube-bg, .video-bg"),$textBlock:$(e).find(".text-block-container")},vars:{videoIndex:i.bannerIndex,everPlay:!1},constants:{userAgents:/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i},initYoutube:function(e){if(window.YT)this.onApiReady();else{var t,n=document.getElementsByTagName("script")[0],s="https://www.youtube.com/iframe_api";n.src!==s&&((t=document.createElement("script")).src=s,n.parentNode.insertBefore(t,n)),window.onYouTubeIframeAPIReady=function(){$.publish(o.YOUTUBE_API_READY)},$.subscribe(o.YOUTUBE_API_READY,$.proxy(this.onApiReady,this))}this.elements.$youtube.hasClass("autoplay")&&0===this.vars.videoIndex&&(i.autoplay=!0)},onApiReady:function(){var e=this.elements.$youtube.find(".youtube-player").attr("id");this.elements.player=new YT.Player(e,{height:this.elements.$youtube.height(),width:this.elements.$youtube.width(),videoId:this.elements.$youtube.attr("data-youtube-id"),playerVars:{autoplay:i.autoplay,modestbranding:1,autohide:1,iv_load_policy:3,showinfo:0,rel:0,html5:1,controls:1},events:{onStateChange:$.proxy(this.onYoutubeStateChange,this)}}),this.bindYoutube(),this.resizeYoutube()},resizeYoutube:function(){if(this.elements.player&&".owl-wrapper"!==n){var e=this.elements.$container.parents(n).height();this.elements.player.setSize(this.elements.$container.width(),e),this.elements.$container.height(e)}},bindYoutube:function(){this.elements.$container.on("click",'.youtube-play, [class*="-play"]',$.proxy(this.playYoutube,this)),this.elements.$container.on("click",".youtube-close",$.proxy(this.closeYoutube,this)),navigator.userAgent.match(this.constants.userAgents)?(this.elements.$youtube.show(),this.elements.$youtubeClose.hide()):i.autoplay||this.elements.$videoBg.fadeOut()},playYoutube:function(e){e&&e.preventDefault(),this.elements.player&&"function"==typeof this.elements.player.playVideo&&(this.elements.player.playVideo(),this.vars.everPlay=!0,$.publish(o.YOUTUBE_STARTED,{videoIndex:this.vars.videoIndex}))},pauseYoutube:function(e){e&&e.preventDefault(),this.elements.player&&"function"==typeof this.elements.player.pauseVideo&&this.elements.player.pauseVideo()},restartYoutube:function(){this.elements.player&&(this.elements.player.seekTo(0,!0),this.elements.player.playVideo())},muteYoutube:function(){this.elements.player&&"function"==typeof this.elements.player.mute&&this.elements.player.mute()},unMuteYoutube:function(){this.elements.player&&"function"==typeof this.elements.player.unMute&&this.elements.player.unMute()},getPlayerStatus:function(){switch(this.elements.player.data){case 3:return"buffering";case 5:return"cued";case 0:return"ended";case 2:return"paused";case 1:return"playing";case-1:return"unstarted";default:return null}},closeYoutube:function(e){e&&e.preventDefault(),this.elements.player&&"function"==typeof this.elements.player.pauseVideo&&(this.elements.player.pauseVideo(),this.elements.$youtube.fadeOut("slow"),$.publish(o.YOUTUBE_STOPPED,{videoIndex:this.vars.videoIndex}))},onYoutubeStateChange:function(e){this.elements.player.data=e.data,e.data===YT.PlayerState.ENDED?(i.closeOnEnd&&(this.elements.$youtube.fadeOut("slow"),this.elements.$youtubeClose.hide()),$.publish(o.YOUTUBE_STOPPED,{videoIndex:this.vars.videoIndex})):e.data===YT.PlayerState.PAUSED&&this.elements.$youtubeClose.show(),e.data===YT.PlayerState.PLAYING?(this.elements.$youtube.fadeIn(),this.elements.$youtubeClose.hide(),this.vars.everPlay=!0,$.publish(o.YOUTUBE_STARTED,{videoIndex:this.vars.videoIndex})):this.elements.$videoBg.length&&this.elements.$videoBg.fadeOut()},destroyYoutube:function(){this.elements.player.destroy()}}}});