text: !function(e,t,l,o){function s(t,l){this.element=t,this.options=e.extend({},u,l),this.$player,this.$overlay,this.self,this.subtitles,this.movieId,this.$movieTitle,this.$moviePoster,this.totalTime,this.$progressBar,this.$playedTime,this.$currentVolume,this.$playerButton,this.$volumeIcon,this.$volumeControl,this.$progressControl,this.$normalScreenButton,this.buffer,this.$fullScreenButton,this.fullScreenStatus,this.updatedTime,this.$closeButton,this.$movieHolder,this.$playerControls,this.subtitleMenuButton,this.subtitleMenu,this.subtitleDisplay,this.subtitleHolder,this.$controlsHolder,this.init()}function n(){$player.on("loadstart",function(){e("body").addClass("loading"),self.showControls("show",!0)}),$player.on("canplay",function(){e("body").removeClass("loading"),self.showControls("hide",!1)})}function a(){var t=$player[0].currentTime,l={"function":"saveCurrentTime",current_time:t,movie_id:movieId};e.ajax({type:"POST",url:"bootstrap.php",data:l,dataType:"json"}),e.data(this,"plugin_"+r,null),e(".PopStopPlayer").remove()}var r="PopStopPlayer",u={movieId:"",autoPlay:"",resumeTime:"",posterPath:"",title:"",overview:"",year:"",stars:""};s.prototype={init:function(){$player=e(this.element),fullScreenStatus=!1,movieId=this.options.movieId,moviePoster=this.options.posterPath,movieTitle=this.options.title,movieOverview=this.options.overview,movieYear=this.options.year,movieRating=this.options.stars;var o=!1,i=!1;subtitleEnd=0,self=this,this.createPlayer(),this.getControls(),this.getSubtitles(),n(),this.options.resumeTime.length>0&&($player[0].currentTime=this.options.resumeTime),this.options.autoPlay===!0&&self.playerStatus(),$player.on("loadedmetadata",function(){$totalTime.html(self.timeFormat($player[0].duration)),$currentVolume.css("height",100*$player[0].volume+"%")}),$player.on("timeupdate",function(){var e=$player[0].currentTime,t=$player[0].duration;$player[0].buffered.end(0);$playedTime.text(self.timeFormat(e)),$progressBar.css("width",self.toPercentage(e,t)+"%"),$subtitleDisplay.find("li").hasClass("selected")?self.setSubtitles(e):$subtitleHolder.css("opacity",0)}),$player.on("ended",function(){$player[0].currentTime=null,a()}),$volumeControl.mousedown(function(e){i=!0,$player[0].muted=!1,self.updateVolume(e.pageY)}),$volumeControl.mouseup(function(e){i&&(i=!1,self.updateVolume(e.pageY))}),$volumeControl.mousemove(function(e){i&&self.updateVolume(e.pageY)}),$progressControl.mousedown(function(e){o=!0,self.updateBar(e.pageX)}),$progressControl.mouseup(function(e){o&&(o=!1,self.updateBar(e.pageX))}),$progressControl.mousemove(function(e){o&&self.updateBar(e.pageX)}),$volumeIcon.on("click",function(){self.muteSound()}),$fullScreenButton.on("click",function(){self.fullscreenToggle()}),$closeButton.on("click",function(){a()}),$controlsHolder.mouseenter(function(){self.showControls("show")}),$controlsHolder.mouseleave(function(){self.showControls("hide")}),$controlsHolder.on("click","#playerButton",function(){self.playerStatus()}),$overlay.on("click","#resumeButton",function(){self.playerStatus()}),$controlsHolder.on("click",".subtitle-item",function(){var t=e(this),l=t.find("span").attr("data-path");t.hasClass("selected")?$subtitleDisplay.find("li").removeClass("selected"):(t.toggleClass("selected"),self.showSubTitles(l))}),e(l).unbind("keydown").bind("keydown",function(e){var t=e.keyCode;switch(t){case 32:self.playerStatus();break;case 70:self.fullscreenToggle();break;case 27:a()}}),e(t).on("beforeunload",function(){a()})},getControls:function(){$overlay=e("#overlay"),$totalTime=e("#totalTime"),$progressBar=e("#played"),$playedTime=e("#playingTime"),$currentVolume=e("#currentVolume"),$playerButton=e("#playerButton"),$volumeIcon=e("#volumeIcon"),$volumeControl=e("#volumeControl"),$progressControl=e("#progressBar"),$normalScreenButton=e("#normalScreenButton"),$loadedBar=e("#loadedBar"),$fullScreenButton=e("#fullScreenButton"),$closeButton=e("#closeButton"),$movieHolder=e("#movieHolder"),$playerControls=e("#controls"),$controlsHolder=e(".holder"),$subtitleMenu=e("#subtitleMenu"),$subtitleDisplay=e("#subtitleDisplay"),$subtitleHolder=e("#subtitleHolder")},showControls:function(e){switch(e){case"show":$playerControls.animate({opacity:1},1500);break;case"hide":$playerControls.delay(4e3).animate({opacity:0},1500);break;case"play":$closeButton.animate({top:"-60px"}),$overlay.animate({opacity:0});break;case"pause":$closeButton.animate({top:"10px"}),this.overlayWindow()}},createPlayer:function(){e(this.element).wrap('<div class="PopStopPlayer" />');var t=e(".PopStopPlayer"),l='<div class="holder"><div id="controls"><div class="control-bar"><div id="progressBar"><div id="played"></div><div id="loadedBar"></div></div><ul class="left"><li><div class="play" id="playerButton"></div></li><li><div class="time-holder"><span id="playingTime">00:00</span><span>/</span> <span id="totalTime">00:00</span></div></li></ul><ul class="right"><li><div id="volume"><div id="volumeIcon" class="volume-max"><span></span></div><div id="volumeControl"><div id="volumePosition"><div id="currentVolume"></div></div></div></div></li><li><div id="subtitleMenu"><div id="subtitleMenuIcon"></div><div id="subtitleDisplay"></div></div></li><li><div id="fullScreenButton"><span></span></div></li></ul></div></div></div><div id="subtitleHolder"></div><div id="overlay"></div><span id="closeButton"></span>';t.append(l)},updateVolume:function(e){var t=e-$volumeControl.offset().top,l=100-100*t/$volumeControl.height();l>100&&(l=100),0>l&&(l=0),$player[0].volume=l/100,$currentVolume.css("height",l+"%"),this.speakerChange(l)},playerStatus:function(){$playerButton.removeClass($playerButton.attr("class")),$player[0].paused?(this.showControls("play"),$player[0].play(),$playerButton.addClass("pause")):(this.showControls("pause"),$player[0].pause(),$playerButton.addClass("play"))},overlayWindow:function(){var e=this.timeRemaining($player[0].duration-$player[0].currentTime),t='<div class="window"><div class="left"><div class="cover" style="background-image: url('+moviePoster+');"></div></div><div class="right"><h1>'+movieTitle+" ("+movieYear+')</h1><div class="rating">'+movieRating+'</div><div class="overview"><p>'+movieOverview+'</p></div><div class="remaining">Remaining: '+e+'</div></div><div class="button" id="resumeButton"><i class="fa fa-play-circle"></i> RESUME</div></div></div></div></div>';$overlay.animate({opacity:1}).html(t)},muteSound:function(){$player.get(0).muted?($volumeIcon.toggleClass("mute volume-max"),$currentVolume.css("height","100%"),$player.get(0).muted=!1):($volumeIcon.toggleClass("volume-max mute"),$currentVolume.css("height","0%"),$player.get(0).muted=!0)},updateBar:function(e){var t=$player.get(0).duration,l=e-$progressControl.offset().left,o=100*l/$progressControl.width();o>100&&(o=100),0>o&&(o=0),$progressBar.css("width",o+"%"),$player[0].currentTime=t*o/100},speakerChange:function(e){$volumeIcon.removeClass($volumeIcon.attr("class")),e>60?$volumeIcon.addClass("volume-max"):e>30?$volumeIcon.addClass("volume-mid"):0===e?($volumeIcon.addClass("mute"),$player[0].muted=!0):$volumeIcon.addClass("volume-min")},fullscreenToggle:function(){fullScreenStatus?(fullScreenStatus=!1,l.exitFullscreen?l.exitFullscreen():l.webkitExitFullscreen?l.webkitExitFullscreen():l.mozCancelFullScreen?l.mozCancelFullScreen():l.msExitFullscreen&&l.msExitFullscreen()):(fullScreenStatus=!0,$player[0].requestFullscreen?$player[0].requestFullscreen():$player[0].webkitRequestFullscreen?$player[0].webkitRequestFullscreen():$player[0].mozRequestFullScreen?$player[0].mozRequestFullScreen():$player[0].msRequestFullscreen&&$player[0].msRequestFullscreen())},toPercentage:function(e,t){return(e/t*100).toFixed(2)},timeFormat:function(e){var t=Math.floor(e/3600);t=10>t?"0"+t:t,e-=3600*t;var l=Math.floor(e/60);return l=10>l?"0"+l:l,e-=60*l,e=e.toFixed(0),e=10>e?"0"+e:e,t+":"+l+":"+e},getSubtitles:function(){var t={"function":"getMovieSubtitles",id:this.options.movieId};e.ajax({type:"GET",url:"bootstrap.php",data:t,dataType:"json"}).done(function(t){var l="<ul>";t.length>0?e.each(t,function(e,t){l+='<li class="subtitle-item"><span data-path="'+t.path+'">'+t.name+"</span></li>"}):l+="<li>No subtitles</li>",l+="</ul>",$subtitleDisplay.html(l)})},showSubTitles:function(t){var l=e.ajax({type:"GET",url:t,async:!1}).responseText;l=e.trim(l.replace(/\r\n|\r|\n/g,"\n")).split("\n\n"),subtitles=new Array(l.length);for(var o=0;o<l.length;o++)if(string=l[o].split("\n"),string.length>=2){var i=(string[0],string[1].split(" --> ")),s=this.toSeconds(e.trim(i[0])),n=this.toSeconds(e.trim(i[1])),a=string[2];if(string.length>2)for(var r=3;r<string.length;r++)a+="<br />"+string[r];subtitles[o]={start:s,end:n,text:a}}},setSubtitles:function(e){subtitleEnd<e&&$subtitleHolder.css("opacity",0);for(var t,l=0;l<subtitles.length;l++)if(subtitles[l].end>e){t=l;break}t>=0&&e>subtitles[t].start&&e<subtitles[t].end&&($subtitleHolder.html("<p>"+subtitles[t].text+"</p>").css("opacity",1),subtitleEnd=subtitles[t].end)},toSeconds:function(e){var t=0;if(e){var l=e.split(":");for(i=0;i<l.length;i++)t=60*t+parseFloat(l[i].replace(",","."))}return t},timeRemaining:function(e){var t=parseInt(e,10),l=Math.floor(t/3600),o=Math.floor((t-3600*l)/60),i=t-3600*l-60*o,s=l+"h "+o+"m";return 0==l&&o>0?s=o+"m":0==l&&0==o&&(s=i+"s"),s}},e.fn[r]=function(t){return this.each(function(){e.data(this,"plugin_"+r)||e.data(this,"plugin_"+r,new s(this,t))})}}(jQuery,window,document);