var PodcastPlayer=new Class({Implements:Options,options:{loadTimeout:6000,playerWidth:440,playerHeight:279,tweenDuration:500,osdDelay:2500,playerSkin:null,marqueeIncrement:1,marqueeGap:50,marqueeSpeed:28,marqueeAttributeDisplay:["type","title","author","summary","published","copyright"],commentsPerPage:5,defaultMarqueeText:"Powered by PrimaryPodcast...",extensionRewrites:{mp4:["lighttpd",{3:/(.*)/,5:/(\d+)\./},"streamPort"]},videoCallbackBase:"/download/register-play/",fileIdRegex:/(\d+)\.[a-z0-9]+$/,scale:"uniform",mode:"legacy"},listeners:{PLAY:["Controller"],PLAYLIST:["Controller"],ITEM:["Controller"],STATE:["Model"],ERROR:["Model","View","Controller"],VOLUME:["Controller"],MUTE:["Controller"]},currentState:"IDLE",oldState:false,eventToLoad:false,playlist:[],playlistPos:-1,id3Pos:-1,id3Request:false,infoMarquee:false,queuedEvents:[],cookieDurationDays:365,cookieUpdateTimer:null,commentEventAdded:false,initialize:function(A){if(!window.console){window.console={log:function(){}}}this.setOptions(A);console.log("Initialising player, options: ",A);this.initJPlayer();this.initMarquee();this.initControls();this.initComments();this.initOSD();window.addEvent("domready",function(){this.fixBrowser()}.bind(this))},fixBrowser:function(){if(Browser.Engine.name=="trident"&&Browser.Engine.version<=4){for(var G=0;G<document.images.length;G++){var D=document.images[G];var F=D.src.toUpperCase();if(F.substring(F.length-3,F.length)=="PNG"){var B=(D.id)?"id='"+D.id+"' ":"";var E=(D.className)?"class='"+D.className+"' ":"";var H=(D.title)?"title='"+D.title+"' ":"title='"+D.alt+"' ";var C="display:inline-block;"+D.style.cssText;if(D.align=="left"){C="float:left;"+C}if(D.align=="right"){C="float:right;"+C}if(D.parentElement.href){C="cursor:hand;"+C}var A="<span "+B+E+H+' style="width:'+D.width+"px; height:"+D.height+"px;"+C+";filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+D.src+"', sizingMethod='scale');\"></span>";D.outerHTML=A;G=G-1}}}},initOSD:function(){if(this.osdElement){this.osdElement.empty();this.osdElement.setOpacity(0);this.osdElement.setStyle("display","block");this.osdElement.addEvent("mouseenter",function(A){this.pauseOSD()}.bind(this));this.osdElement.addEvent("mouseleave",function(A){this.resumeOSD()}.bind(this))}},flashOSD:function(A){if(this.osdElement){this.osdElement.empty();this.osdElement.set("html",A);this.osdElement.tween("opacity",1);this.resumeOSD()}},hideOSD:function(){this.osdElement.tween("opacity",0)},pauseOSD:function(A){if(this.osdElement){this.osdElement.tween("opacity",1);$clear(this.osdTimer)}},resumeOSD:function(A){$clear(this.osdTimer);this.osdTimer=this.hideOSD.delay(this.options.osdDelay,this)},initComments:function(){if(this.options.mode=="ng"){this.commentsHideElement=this.commentsElement.getElement(".hide");this.commentsSlide=new Fx.Slide(this.commentsHideElement);this.commentsSlide.slideOut();this.toggleElements=this.commentsElement.getElements(".show");this.toggleElements.setStyle("display","none");this.toggleElements.addEvent("click",this.toggleComments.bindWithEvent(this));this.addCommentElements=this.commentsElement.getElements(".add");this.addCommentElements.addEvent("click",this.addComment.bindWithEvent(this));var A=this.commentsElement.getElement("form");if(A){this.commentsForm=A;this.commentsForm.addEvent("submit",this.submitCommentsForm.bindWithEvent(this))}this.formElement=this.commentsHideElement.getElement(".commentForm");this.formElement.setStyle("display","none");this.updateComments();return }if(this.commentsElement&&this.options.commentsBaseUrl){this.commentsElement.setOpacity(0);var B=this.controlsElement.getElement(".commentB");if(B){this.interfaceSize=this.interfaceElement.getSize();this.commentsButton=B;this.commentsSlide=new Fx.Morph(this.commentsElement);this.commentsElement.setStyle("display","block");this.commentsWidth=this.commentsElement.getSize().x;this.commentsElement.setStyle("width",this.interfaceSize.x);this.resizeComments(true);B.setStyle("display","block");B.setStyle("opacity",0);B.getElement("a").empty();new Element("span").inject(B.getElement("a"))}var A=this.commentsElement.getElement("form");if(A){this.commentsForm=A;this.commentsForm.addEvent("submit",this.submitCommentsForm.bindWithEvent(this));this.commentsElement.getElements("a.close-link").addEvent("click",this.toggleComments.bindWithEvent(this))}}},closeCommentsForm:function(A){if(A){new Event(A).stop()}this.commentsForm.getParent().setStyle("display","none");this.resizeComments.delay(50,this)},showCommentsForm:function(B){if(this.commentsForm){var A=this.commentsForm;this.commentsForm.getParent().setStyle("display","block");A.getElement(".comment-errors").setStyle("display","none");A.getElement(".elements").setStyle("display","block");A.getElements("input").className="";this.resizeComments.delay(50,this)}},checkCommentsResponse:function(G,F){var E=this.commentsForm;if(G.result=="error"){var B=new Element("ul",{"class":"errors"});for(field in G.errors){var C=E.getElement("[name="+field+"]");if(C){C.addClass("error");var A=new Element("li");A.set("html",G.errors[field]);A.inject(B)}}var C=E.getElement(".comment-errors");C.empty();var D="<p>Sorry, we could not add your comment. Please correct the errors below.";C.set("html",D);B.inject(C);C.setStyle("display","block");this.resizeComments(false);if(this.options.mode=="ng"){this.commentsSlide.slideIn()}}else{E.getElement(".elements").setStyle("display","none");var C=E.getElement(".comment-errors");E.getElements("input").set("value","");E.getElements("input[name=comm-submit]").set("value","Submit Comment");E.getElements("textarea").set("html","");C.addClass("success");C.addClass("noneOnChange");p=new Element("p");p.set("html","Thank you, your comment has been submitted for approval. It will appear on the comments list when it is approved by a teacher.");C.empty();p.addClass("success");p.inject(C);C.setStyle("display","block");this.updateComments()}},submitCommentsForm:function(B){new Event(B).stop();this.resizeComments();var A=this.playlist[this.playlistPos];if(A){try{var F=this.fileToId(A.file);this.commentsForm.getElement("[name=podcast-id]").set("value",F)}catch(E){console.log(E);return }var D=this.commentsForm.toQueryString();var C=this.commentsForm.get("action");this.commentsForm.getElement(".comment-errors").setStyle("display","none");this.commentsForm.getElements("input").className="";if(this.commentsRequest){this.commentsRequest.cancel()}this.commentsRequest=new Request.JSON({url:C,method:"post",data:D,onComplete:this.checkCommentsResponse.bind(this)});this.commentsRequest.send()}},toggleComments:function(A){if(this.options.mode=="ng"){if(A){new Event(A).stop()}if(this.commentsShown){this.commentsShown=false;this.toggleElements.set("html","Show Comments");this.commentsSlide.slideOut();this.formElement.setStyle("display","none");this.formElement.getElement(".comment-errors").empty();this.commentsFormShown=false}else{this.commentsShown=true;this.formElement.setStyle("display","block");this.formElement.getElement(".submitCommentBttn").set("value","Submit Comment");this.toggleElements.set("html","Hide Comments");this.formElement.getElement(".elements").setStyle("display","block");(function(){this.commentsSlide.slideIn()}).delay(100,this)}return }if(A){new Event(A).stop()}if(this.commentsShown){this.commentsButton.removeClass("comments-shown");this.commentsShown=false;this.resizeComments(true)}else{this.commentsButton.addClass("comments-shown");this.commentsShown=true;this.resizeComments()}},resizeComments:function(B){if(this.options.mode=="ng"){return }if(B){this.commentsSlide.start({height:0,width:this.interfaceSize.x}).chain(function(E){this.commentsElement.getElement(".podcastComments").setStyle("display","none");this.commentsElement.setStyle("display","none")}.bind(this));this.interfaceElement.getParent().tween("height",this.interfaceSize.y);this.commentsShown=false}else{this.commentsElement.setOpacity(1);this.commentsElement.setStyle("left",-10000);var D=this.commentsElement.getParent();this.commentsElement.getElement(".comment-errors").setStyle("display","none");this.commentsElement.getElement(".podcastComments").setStyle("display","block");this.commentsElement.dispose();this.commentsElement.inject($$("body")[0]);this.commentsElement.setStyle("display","block");var A=this.commentsElement.getSize().x;var C=this.commentsElement.getSize().y;this.commentsElement.setStyle("width","100%");this.commentsElement.setStyle("height","auto");this.commentsSize=this.commentsElement.getSize();console.log(this.commentsSize);this.commentsElement.dispose();this.commentsElement.setStyle("left","");this.commentsElement.inject(D);this.commentsElement.setStyle("width",A);this.commentsElement.setStyle("height",C);this.commentsSlide.start({height:this.commentsSize.y,width:this.commentsWidth});this.interfaceElement.getParent().tween("height",this.interfaceSize.y+this.commentsSize.y);this.commentsShown=true}},commentsNext:function(){this.updateComments(false,this.commentsPage+1)},commentsPrev:function(){this.updateComments(false,this.commentsPage-1)},addComment:function(C){var B=new Event(C);B.stop();var A=1;if(this.commentsShown){this.toggleComments();A=600}this.formElement.getElement(".comment-errors").setStyle("display","none");this.formElement.setStyle("display","block");this.formElement.getElement(".elements").setStyle("display","block");(function(){this.commentsSlide.slideIn();this.toggleElements.set("html","Hide Comments");this.toggleElements.setOpacity(0);this.toggleElements.setStyle("display","");this.toggleElements.tween("opacity",1);this.commentsShown=true;(function(){window.location=B.target.get("href")}).delay(500)}).delay(A,this)},clearComments:function(){this.prepareComments({num:0,num_unapproved:0,comments:[]})},prepareComments:function(R){if(this.options.mode=="ng"){var H=R.num.toInt();var M=R.num_unapproved.toInt();if(H){if(!this.commentsShown){this.toggleElements.setOpacity(0);this.toggleElements.setStyle("display","");this.toggleElements.tween("opacity",1)}}else{if(!this.commentsShown){this.toggleElements.tween("opacity",0);this.toggleElements.setStyle("display","none")}}var S=this.commentsHideElement.getElement(".info");var D=((R.page-1)*this.options.commentsPerPage)+1;var C=D+R.comments.length-1;var E=H+" comment"+(H!=1?"s":"")+" ("+M+" unapproved)";var F="Currently viewing "+D+"-"+C+" of "+R.num+" comments.";if(!R.comments.length){F="There are currently no comments on this podcast."}S.set("html",F);this.commentsElement.getElement(".numbers").set("html",E);var K=C<R.num.toInt();var I=D>1;S.getElements(".cont").dispose();if(I){var O=new Element("a",{"class":"prev cont",href:"#"});O.set("html","Previous Page");O.addEvent("click",function(W){this.commentsPrev();new Event(W).stop()}.bind(this));O.inject(S)}if(K){var O=new Element("a",{"class":"next cont",href:"#"});O.set("html","Next Page");O.addEvent("click",function(W){this.commentsNext();new Event(W).stop()}.bind(this));O.inject(S)}var U=this.commentsHideElement.getElement(".podcastComments");U.empty();var J,N,A,P,Q,L;R.comments.each(function(X){try{J=new Element("div",{"class":"comment"});L=new Element("div",{"class":"wrapper"});L.inject(J);P=new Element("div",{"class":"message",html:X.message});A=new Element("div",{"class":"date"});Q="By ";if(X.email){Q+="<a href='mailto:"+X.email+"'>"}Q+=X.from;if(X.email){Q+="</a> ("+X.email+")"}Q+=", on ";Q+=X.created.substring(8,10)+"/"+X.created.substring(5,7)+"/"+X.created.substring(0,4)+" at "+X.created.substring(11,13)+":"+X.created.substring(14,16);A.set("html",Q);P.set("html",X.message);P.inject(L);A.inject(L);J.inject(U)}catch(W){console.log(W)}});if(this.commentsShown){this.commentsSlide.slideIn()}return }var B=this.commentsElement.getElement(".podcastComments");var G=new Element("div",{"class":"commentDetail"});var S=new Element("div",{"class":"commentInfo"});var D=((R.page-1)*5)+1;var C=D+R.comments.length-1;var E="Currently viewing "+D+"-"+C+" of "+R.num+" comments.";if(!this.commentEventAdded){this.commentsButton.tween("opacity",1);this.commentsButton.getElement("a").addEvent("click",function(W){new Event(W).stop();this.toggleComments()}.bind(this));this.commentEventAdded=true}if(R.num_unapproved.toInt()){E+=" ("+R.num_unapproved+" unapproved comment"+(R.num_unapproved.toInt()>1?"s":"")+")";if(R.last_unapproved){var T=R.last_unapproved;E+=" Last comment waiting to be approved added on "+T+".";console.log(E)}}S.set("html",E);var K=C<R.num.toInt();var I=D>1;this.commentsButton.getElement("span").set("html",R.num);if(I){var O=new Element("a",{"class":"prev",href:"#"});O.set("html","Previous Page");O.addEvent("click",function(W){this.commentsPrev();new Event(W).stop()}.bind(this));O.inject(S)}if(K){var O=new Element("a",{"class":"next",href:"#"});O.set("html","Next Page");O.addEvent("click",function(W){this.commentsNext();new Event(W).stop()}.bind(this));O.inject(S)}if(!B){return }B.empty();if(R.comments.length>0){S.inject(B)}R.comments.each(function(W){this.createComment(W).inject(G)}.bind(this));if(R.comments.length==0){var T="";if(R.last_unapproved){var V=R.last_unapproved;T=" Last comment waiting to be approved added "+V+"."}var E=R.num_unapproved.toInt()?"There "+(R.num_unapproved.toInt()>1?"are":"is")+" currently "+R.num_unapproved+" unapproved comment"+(R.num_unapproved.toInt()>1?"s":"")+" on this podcast. "+T:"There are currently no comments on this podcast.";new Element("div",{"class":"comment",html:E}).inject(G)}G.inject(B);if(this.commentsShown&&R.comments.length+R.num_unapproved.toInt()!=this.lastComments){this.resizeComments();this.lastComments=R.comments.length+R.num_unapproved.toInt()}},createCommentNew:function(B){var F=new Element("div",{"class":"nComment"});var D=new Element("div",{"class":"date"});var A=B.created.substring(8,10)+"/"+B.created.substring(5,7)+"/"+B.created.substring(0,4)+" at "+B.created.substring(11,13)+":"+B.created.substring(14,16);var C="By ";if(B.email){C+="<a href='mailto:"+B.email+"'>"+B.from+"</a> ("+B.email+")"}else{C+=B.from}C+=" on "+A;D.set("html",C);var E=new Element("div",{"class":"c_message"});E.set("html",B.message.replace("\n","<br />"));E.inject(F);D.inject(F);return F},createComment:function(A){var E=new Element("div",{"class":"comment"});var C=new Element("div",{"class":"date"});C.set("html",A.created.substring(8,10)+"/"+A.created.substring(5,7)+"/"+A.created.substring(0,4)+" "+A.created.substring(11,13)+":"+A.created.substring(14,16));var B=new Element("div",{"class":"from"});if(A.email){B.set("html","<a href='mailto:"+A.email+"'>"+A.from+"</a> ("+A.email+")")}else{B.set("html",A.from)}var D=new Element("div",{"class":"c_message"});D.set("html",A.message.replace("\n","<br />"));C.inject(E);B.inject(E);D.inject(E);return E},storeCookie:function(){if(this.swiff&&this.swiff.object.getConfig){var A=this.swiff.object.getConfig()["volume"];var B={v:A,s:this.shuffle?1:0,m:this.mute?1:0};Cookie.write("PS_"+this.options.JPlayer.ID,JSON.encode(B),{duration:this.cookieDurationDays});console.log("Write state cookie: ",B," ("+this.cookieDurationDays+" days)")}},readCookie:function(){var B=Cookie.read("PS_"+this.options.JPlayer.ID);if(B){var A=JSON.decode(B);console.log("Read state cookie: ",A);if(A){if(this.swiff&&this.swiff.object.sendEvent){this.swiff.object.sendEvent("VOLUME",A.v);if(A.mute){this.swiff.object.sendEvent("MUTE",true)}this.shufflePlaylist(A.s)}}}},initJPlayerEvents:function(B){console.log("Initialising player listeners:",this.swiff.instance);window[this.swiff.instance]=this;var A=this.swiff.object;for(id in this.listeners){this.listeners[id].each(function(C){A["add"+C+"Listener"](id,"window."+this.swiff.instance+".JPlayer"+id)}.bind(this))}},updateComments:function(C,B){if(this.options.mode=="ng"){if(!B){B=1}this.commentsPage=B;if(this.commentsRequest){this.commentsRequest.cancel()}var A=this.playlist[this.playlistPos];if(A){try{var E=this.fileToId(A.file);if(!E){return }this.commentsRequest=new Request.JSON({url:this.options.commentsBaseUrl+E+"/page="+this.commentsPage,onSuccess:function(F,H){try{this.prepareComments(F,H,C)}catch(G){console.log(G)}}.bind(this)});this.commentsRequest.get();console.log("Loading Comments: ",this.options.commentsBaseUrl+E)}catch(D){console.log(D)}}return }if(!B){B=1}this.commentsPage=B;if(!this.options.commentsBaseUrl){console.log("No options.commentsBaseUrl set, cannot load comments.");return }if(this.commentsRequest){this.commentsRequest.cancel()}var A=this.playlist[this.playlistPos];if(A){try{var E=this.fileToId(A.file);if(!E){return }this.commentsRequest=new Request.JSON({url:this.options.commentsBaseUrl+E+"/page="+this.commentsPage,onSuccess:function(F,G){this.prepareComments(F,G,C)}.bind(this)});this.commentsRequest.get();console.log("Loading Comments: ",this.options.commentsBaseUrl+E)}catch(D){console.log(D)}}},updateId3Details:function(D){if(!this.options.id3BaseUrl){console.log("No options.id3BaseUrl set, cannot update file info.");return }if(this.id3Pos==-1||this.id3Pos!=this.playlistPos||D){if(this.id3Request){this.id3Request.cancel()}var F=this.playlist[this.playlistPos];if(F){try{var I=this.parseUrl(F.file);var A=null;var G=I.file.split(".");var B=I.path.split("/");var E=G[G.length-1];this.videoCallbackComplete=false;if(E=="mp4"){this.currentIsVideo=this.options.videoCallbackBase+B[B.length-2]+"/"+B[B.length-1]}else{this.currentIsVideo=false}var C=this.fileToId(F.file);if(!C){return }this.id3Request=new Request.JSON({url:this.options.id3BaseUrl+C,onSuccess:function(J,K){this.loadId3Details(J,K,D)}.bind(this)});this.id3Request.get();console.log("Loading Id3 Details: ",this.options.id3BaseUrl+C)}catch(H){console.log(H)}}}},loadId3Details:function(A,D,C){var D="";if(A){this.options.marqueeAttributeDisplay.each(function(F){if(A[F]){var E=A[F].match(/^(video|audio)/);D+="<span class='mq-"+(E?E[0]:F)+"'>"+A[F]+"</span>"}})}D+="<span class='default'>"+this.options.defaultMarqueeText+"</span>";var B=0;if(A){if(A.rating){B=Math.round(A.rating.toFloat());if(B<0){B=0}if(B>5){B=5}}}if(this.ratingElement){this.ratingElement.className="rating";if(B>0){this.ratingElement.addClass("cr"+B)}}this.flashOSD(D);this.setMarqueeText(D,C)},updateRating:function(C){if(this.playlistPos>=0&&this.playlist){var B=this.playlist[this.playlistPos];if(B){if(this.ratingRequest){this.ratingRequest.cancel()}if(!this.options.submitBaseUrl){console.log("Cannot submit rating, as options.submitBaseUrl has not been specified.");return }var A=this.options.submitBaseUrl+this.fileToId(B.file)+"/"+C;this.ratingRequest=new Request({url:A,onSuccess:function(D){this.loadRating(D)}.bind(this)});this.ratingRequest.get()}}},loadRating:function(C){this.updateId3Details(true);if(this.infoElement){var A=new Element("div",{"class":"message",html:"<span>"+C+"</span>"});A.setOpacity(0);A.inject(this.controlsElement);var B=new Fx.Tween(A);B.start("opacity",1).chain(function(){B.start.delay(3000,B,["opacity",0]);(function(){A.destroy()}).delay(4000)})}},initControls:function(){var C=this.controlsElement.getElement(".rating");this.ratingElement=C;if(C){var B=new Element("li");B.setOpacity(0);B.setStyle("position","absolute");B.inject(C);for(i=1;i<=5;i++){B.addClass("r"+i);B.addClass("cr"+i)}B.destroy();C.getElements("li").addEvent("mouseenter",function(E){["1","2","3","4","5"].each(function(F){C.removeClass("r"+F)});C.addClass("highlighted");C.addClass("r"+this.getElement("span").get("html"))});C.getElements("li").each(function(E){E.addEvent("click",function(G){new Event(G).stop();var F=E.getElement("span").get("html").toInt();this.updateRating(F)}.bind(this))}.bind(this));C.addEvent("mouseleave",function(E){["1","2","3","4","5"].each(function(F){C.removeClass("r"+F)});C.removeClass("highlighted")})}var A=this.controlsElement.getElement(".shuffle");this.shuffleElement=A;if(A){A.getElement("a").addEvent("click",function(E){new Event(E).stop();this.toggleShuffle()}.bind(this))}var D=this.controlsElement.getElement(".fullscreen");this.fullscreenElement=D;if(D){D.getElement("a").addEvent("click",function(E){new Event(E).stop();this.toggleFullscreen()}.bind(this))}},initMarquee:function(){this.infoMarquee=this.interfaceElement.getElement(".playerInfo");if(this.infoMarquee){this.infoMarquee.setStyle("overflow","hidden");var A={x:this.infoMarquee.getStyle("width").toInt(),y:this.infoMarquee.getStyle("height").toInt()};var B=new Element("table");B.set("html","<tr><td class='content'><div>"+this.options.defaultMarqueeText+"</div></td></tr>");B.setStyles({position:"absolute",top:0,left:10,width:10000,margin:0,padding:0,"text-align":"left"});B.inject(this.infoMarquee);B.addEvent("mouseenter",function(C){this.stopMarquee()}.bind(this));B.addEvent("mouseleave",function(C){this.startMarquee()}.bind(this));this.marquee=B;this.marqueeSize=A;this.marqueePos=A.x;this.startMarquee()}},stopMarquee:function(){$clear(this.marqueeTimer)},startMarquee:function(){$clear(this.marqueeTimer);this.marqueeTimer=this.scrollMarquee.periodical(51-this.options.marqueeSpeed,this)},scrollMarquee:function(){if(this.marquee){this.marqueePos-=this.options.marqueeIncrement;var A=this.infoMarquee.getElement("table");A.setStyle("left",this.marqueePos);var B=this.marquee.getElement("div").getSize();var C=this.infoMarquee.getSize();if(this.marqueePos+B.x<-this.options.marqueeGap){this.marqueePos=C.x}}else{$clear(this.marqueeTimer)}},resetMarquee:function(){if(this.marquee){this.marqueePos=this.marqueeSize.x}},setMarqueeText:function(A,B){if(this.marquee){if(!this.marqueeTween){this.marqueeTween=new Fx.Tween(this.marquee)}this.marqueeTween.start("opacity",0).chain(function(){if(!B){this.resetMarquee()}this.marquee.getElement("div").set("html",A);this.marqueeTween.start("opacity",1)}.bind(this))}},JPlayerITEM:function(A){console.log("JPlayer Playlist Item: ",A.index);this.playlistPos=A.index;this.updateId3Details();this.updateComments()},JPlayerERROR:function(A){console.log("JPlayer Error: ",A,A.message);this.sendEvent("LOAD",this.options.errorLoad);this.sendEvent("PLAY");this.ignoreState=true},JPlayerPLAYLIST:function(A){console.log("Loaded Playlist: ",A);this.playlist=A.playlist;this.playlistPos=0;this.updateId3Details();this.updateComments()},JPlayerSTATE:function(A){this.currentState=A.newstate;this.oldState=A.oldstate;console.log("Current JPlayer State: ",this.currentState,"(Prev: "+this.oldState+")");if(this.currentState=="PLAYING"&&!this.videoCallbackComplete){if(this.currentIsVideo&&this.options.videoCallbackBase){this.videoCallbackComplete=true;new Request.HTML({url:this.currentIsVideo}).get()}}if(this.eventToLoad){var B=false;if(this.currentState=="IDLE"||this.currentState=="COMPLETED"){B=true}if(B){ev=this.eventToLoad;this.eventToLoad=null;console.log("JPlayer state idle/completed, running delayed event: ",this.eventToLoad);this.sendEvent(ev[0],ev[1])}}},JPlayerVOLUME:function(A){if(this.cookieUpdateTimer){$clear(this.cookieUpdateTimer)}this.flashOSD("<span class='mq-volume'>Volume "+A.percentage+"%</span>");this.cookieUpdateTimer=this.storeCookie.delay(1000,this)},JPlayerMUTE:function(A){if(this.cookieUpdateTimer){$clear(this.cookieUpdateTimer)}this.mute=A.state;this.flashOSD("<span class='mq-volume'>Mute "+(A.state?"On":"Off")+"</span>");this.cookieUpdateTimer=this.storeCookie.delay(1000,this)},initJPlayer:function(){console.log("Loading JPlayer SWF...");if(!window.playerReady){window.playerReady=this.JPlayerCallback.bind(this)}var A=new Swiff(this.options.JPlayer.URL,{id:this.options.JPlayer.ID,width:352,height:306,container:$(this.options.playerElement),params:{allowfullscreen:"true",allowscriptaccess:"always",wmode:"transparent"},vars:{allowfullscreen:"true",controlbar:"bottom",autostart:"false",skin:this.options.playerSkin?this.options.playerSkin:"",id:this.options.JPlayer.ID,name:this.options.JPlayer.ID,scale:this.options.scale,plugins:this.options.JPlayer.flashvars}});this.swiff=A;this.playerElement=$(this.options.playerElement);this.controlsElement=$(this.options.controlsElement);this.commentsElement=$(this.options.commentsElement);this.controlsElement.setStyle("display","none");this.interfaceElement=$(this.options.interfaceElement);this.interfaceElement.setOpacity(0);this.interfaceElement.getElement(".mainWrapper").setStyle("display","block");this.interfaceElement.getElement(".extControls").setStyle("display","block");this.errorElement=$(this.options.errorElement);this.infoElement=$(this.options.infoElement);this.osdElement=$(this.options.onscreenDisplayElement);console.log("Resultant element: ",this.playerElement.innerHTML,"\nEmbedding SWF...");this.loadTimer=this.loadTimeout.delay(this.options.loadTimeout,this)},fullscreen:function(A){if(A){this.fullscr=true;this.sendEvent("FULLSCREEN",true)}else{this.fullscr=false;this.sendEvent("FULLSCREEN",false)}},toggleFullscreen:function(){this.fullscreen(!this.fullscr)},shufflePlaylist:function(A){if(A){if(!this.shuffle){this.shuffle=true;if(this.shuffleElement){this.shuffleElement.addClass("shuffled")}this.flashOSD("<span class='mq-shuffle-on'>Shuffle On</span>");if(this.currentList){this.loadPlaylist(this.currentList)}}}else{if(this.shuffle){if(this.shuffleElement){this.shuffleElement.removeClass("shuffled")}this.flashOSD("<span class='mq-shuffle-off'>Shuffle Off</span>");this.shuffle=false;if(this.currentList){this.loadPlaylist(this.currentList)}}}if(this.cookieUpdateTimer){$clear(this.cookieUpdateTimer)}this.cookieUpdateTimer=this.storeCookie.delay(1000,this)},toggleShuffle:function(){this.shufflePlaylist(!this.shuffle)},loadPlaylist:function(A){if(this.shuffle){if(A.contains("?")){A+="&shuffle=1"}else{A+="?shuffle=1"}}else{A=A.replace(/\&|\?shuffle\=1/,"")}console.log("Loading playlist ("+this.currentState+"): ",A);this.clearComments();if(this.currentState!="IDLE"&&this.currentState!="COMPLETED"&&!this.ignoreState){console.log("Delaying playlist load event until player idle.");this.eventToLoad=["LOAD",A]}else{this.ignoreState=false;this.sendEvent("LOAD",A);this.currentList=A}},loadTimeout:function(){this.interfaceElement.setOpacity(1);this.interfaceElement.setStyle("background-image","none");this.interfaceElement.getElement(".mainWrapper").setStyle("background-image","none");this.interfaceElement.getElement(".mainWrapper").setStyle("display","none");this.errorElement.setOpacity(0);this.errorElement.setStyle("display","block");this.errorElement.tween("opacity",1);this.active=false},JPlayerCallback:function(A){this.initJPlayerEvents();if(this.active){return }this.active=true;$clear(this.loadTimer);this.interfaceElement.setStyle("display","block");this.interfaceSize=this.interfaceElement.getSize();this.playerSize={x:this.options.playerWidth,y:this.options.playerHeight};this.playerElement.setStyle("display","block");this.playerElement.setStyle("position","relative");this.playerElement.setStyle("width",this.playerSize.x);this.playerElement.setStyle("height",this.playerSize.y);console.log("JPlayer Ready: ",A);this.controlsElement.setStyle("display","block");this.interfaceElement.set("tween",{duration:this.options.tweenDuration});this.interfaceElement.tween("opacity",1);this.activateJPlayer.delay(this.options.tweenDuration*1.5,this)},activateJPlayer:function(){this.swiff.object.width=this.options.playerWidth;this.swiff.object.height=this.options.playerHeight;if(!this.swiff.object.sendEvent){console.log("No send event command detected, delaying...");this.activateJPlayer.delay(2000,this);return }if(this.options.initialPlaylist){this.loadPlaylist(this.options.initialPlaylist)}this.readCookie()},fileToId:function(B){var A=B.match(this.options.fileIdRegex);if(A){return A[1]}return null},playUrl:function(E,T,B,M,I,O){var Q=this.parseUrl(E);var J=null;var L=Q.file.split(".");var R=Q.path.split("/");var F=L[L.length-1];var C=this.fileToId(Q.file);for(var N=0;N<this.playlist.length;N++){var P=this.playlist[N];var A=this.parseUrl(P.file);var K=this.fileToId(A.file);if(K==C){console.log("File already in playlist - changing item instead of loading new.");this.sendEvent("ITEM",N);return }}if(this.options.extensionRewrites[F]){var D=this.options.extensionRewrites[F];var H=[];var G=null;for(k in D[1]){while(k>R.length-1){H[H.length-1]=this.options.defaultVideoSlug;R.push(R[R.length-1])}var S=R[k].match(D[1][k]);if(S){H.push(S[1])}G=k}Q.path="/"+H.join("/")+"."+F;if(D[2]){Q.port=this.options[D[2]]}if(D[0]){J={type:D[0]}}}var K=this.fileToId(Q.file);if(K){var E=this.options.podcastImageUrl+K;if(J){J.image=E}else{J={image:E}}}E=Q.protocol+"://"+Q.host+(Q.port?":"+Q.port:"")+Q.path+Q.query;if(J){J.file=E}else{J=E}console.log("Playing: ",J);this.sendEvent("LOAD",J);this.sendEvent("PLAY")},sendEvent:function(A,B){if(!this.active){return }console.log("JPlayer Sending Event: ",A,B);this.swiff.object.sendEvent(A,B)},getPlaylist:function(){if(!this.active){return }console.log("JPlayer, asking for playlist: ",action,p1);JPlayers[this.options.JPlayer.ID].getPlaylist()},parseUrl:function(B){var A=document.createElement("a");A.href=B;return{source:B,protocol:A.protocol.replace(":",""),host:A.hostname,port:A.port,query:A.search,params:(function(){var E={},D=A.search.replace(/^\?/,"").split("&"),C=D.length,F=0,G;for(;F<C;F++){if(!D[F]){continue}G=D[F].split("=");E[G[0]]=G[1]}return E})(),file:(A.pathname.match(/\/([^\/?#]+)$/i)||[,""])[1],hash:A.hash.replace("#",""),path:A.pathname.replace(/^([^\/])/,"/$1"),relative:(A.href.match(/tp:\/\/[^\/]+(.+)/)||[,""])[1],segments:A.pathname.replace(/^\//,"").split("/")}}});
