/**
 * @author Alexander Zerr
 * @version 1.2
 */
(function(){var A=window.jYoup=function(C){this._id="jyoup";this._playList=[];this._lastState=-1;this._currVideo=0;this._repeatState=-1;this._showTimer=null;this._updateTimer=null;this.showedElm=0;this.leftElm=0;this._fsWin=null;this._parent=null;this._base=null;this._player=null;this._fullSize=0;this._opt={width:425,height:null,style:"red",layout:"default"};this._elm={bar:null,over:null,play:null,next:null,prev:null,mute:null,repeat:null,go:null,go_link:null,load_bar:null,loaded:null,played:null,time:null,play_line:null,fs:null};return(this instanceof A?this.init.apply(this,C.callee?C:arguments):new A(arguments))};A.prototype={init:function(C){if(typeof C.playList!="undefined"){this.loadPlayList(C.playList)}if(typeof C.fullSize!="undefined"){this._fullSize=C.fullSize}this.prepareOptions(C);this.prepareParent();this.addHeadStyle();this.createPlayer();this.setSizes();this.initEvents();this._player.jYoup=this;B.addEvent(window,"load",this.centerMenuBar.bind_scope(this))},prepareOptions:function(D){for(var C in this._opt){if(typeof D[C]!="undefined"){this._opt[C]=D[C]}}},prepareParent:function(D){if(this._fullSize){var C=opener.eListener.player[this._id+"_"+window.name.replace(/^.*_/,"")];this._parent=C;this._currVideo=C._currVideo;window.onresize=this.setSizes.bind_scope(this);this.loadPlayList(C._playList);this.prepareOptions(C._opt)}this._id+="_"+B.time()},createPlayer:function(){var D="http://www.youtube.com/apiplayer?enablejsapi=1&playerapiid="+this._id;document.write('<div id="'+this._id+'" class="jyp_player"><object id="player_'+this._id+'" data="'+D+'" type="application/x-shockwave-flash"><param name="allowScriptAccess" value="always"/><param name="movie" value="'+D+'"></object><ul id="bar_'+this._id+'" class="jyp_bar"><li id="prev_'+this._id+'" class="jyp_prev" title="Previous Video"></li><li id="play_'+this._id+'" class="jyp_play" title="Play/Pause"></li><li id="next_'+this._id+'" class="jyp_next" title="Next Video"></li><li id="repeat_'+this._id+'" title="Repeat/one/all"></li><li id="load_bar_'+this._id+'" class="jyp_load_bar"><div id="play_line_'+this._id+'" class="jyp_lb_m"><div id="loaded_'+this._id+'" class="jyp_lb_l"></div><div id="played_'+this._id+'" class="jyp_lb_p"></div><div id="time_'+this._id+'" class="jyp_lb_t"></div></div></li><li id="go_'+this._id+'" class="jyp_go" title="Go to Source"><a id="go_link_'+this._id+'" target="_blank"></a></li><li id="fs_'+this._id+'" class="jyp_max" title="Fullsize"></li><li id="mute_'+this._id+'" class="jyp_mute" title="Mute/Umute"></li></ul></div>');this._base=B.elm(this._id);this._player=B.elm("player_"+this._id);for(var C in this._elm){this._elm[C]=B.elm(C+"_"+this._id)}},addHeadStyle:function(){B.addCss("/jyoup/"+this._opt.layout+"/layout.css");B.addCss("/jyoup/"+this._opt.layout+"/"+this._opt.style+"/style.css");if(B.isIe()){B.addCss("/jyoup/"+this._opt.layout+"/"+this._opt.style+"/ie_style.css")}},setSizes:function(){if(this._fullSize){this._opt.width=document.body.offsetWidth;this._opt.height=document.body.offsetHeight-this._parent._elm.bar.offsetHeight;this.centerMenuBar()}this._opt.height=this._opt.height===null?(this._opt.width/(4/3)):this._opt.height;B.size(this._player,this._opt.width,this._opt.height);B.size(this._base,this._opt.width)},centerMenuBar:function(){var E=(this._playList.length>1)?this._elm.play.offsetLeft:this._elm.repeat.offsetLeft;var C=E-this._elm.play.offsetWidth;var D=(this._opt.width-((this.showedElm*this._elm.play.offsetWidth)+C*this.showedElm))+C;B.size(this._elm.load_bar,D);B.show(this._elm.load_bar)},initEvents:function(){B.show(this._elm.play).onclick=this.playOnState.bind_scope(this);B.show(this._elm.repeat).onclick=this.repeatSwitch.bind_scope(this);B.show(this._elm.go);B.show(this._elm.mute).onclick=this.mute.bind_scope(this);this.showedElm=4;this.leftElm=2;if(!B.isIe()){B.show(this._elm.fs).onclick=this.switchFullSize.bind_scope(this);this.showedElm++;this.leftElm++}if(this._playList.length>1){B.show(this._elm.next).onclick=this.nextVideo.bind_scope(this);B.show(this._elm.prev).onclick=this.prevVideo.bind_scope(this);this.showedElm+=2;this.leftElm+=2}if(this._fullSize){B.css("set",this._elm.fs,"jyp_min")}this._elm.load_bar.onmousedown=this.mouseDown.bind_scope(this)},setVolume:function(C){this._player.setVolume(C)},getVolume:function(){return this._player.getVolume()},getPlayerState:function(){return this._player.getPlayerState()},playOnState:function(){switch(this.getPlayerState()){case 2:case 5:case 0:this.play();break;case 1:this.pause();break}},play:function(){this._player.playVideo()},playSwitch:function(C){switch(C){case"play":B.css("set",this._elm.play,"jyp_play");break;case"pause":B.css("set",this._elm.play,"jyp_pause");break}},pause:function(){this._player.pauseVideo()},nextVideo:function(){this._currVideo=(++this._currVideo==this._playList.length)?0:this._currVideo;if(this._lastState==1){this.loadVideo()}else{this.cueVideo()}},prevVideo:function(){this._currVideo=(--this._currVideo<0)?(this._playList.length-1):this._currVideo;if(this._lastState==1){this.loadVideo()}else{this.cueVideo()}},cueVideo:function(){this._player.cueVideoById(this._playList[this._currVideo],0)},loadVideo:function(){this._player.loadVideoById(this._playList[this._currVideo],0)},mute:function(){vol=this.getVolume();switch(vol){case 0:this.setVolume(100);this.muteSwitch("unmute");break;case 100:this.setVolume(0);this.muteSwitch("mute");break}},muteOnState:function(){switch(this.getVolume()){case 0:return this.muteSwitch("mute");case 100:return this.muteSwitch("unmute")}},muteSwitch:function(C){switch(C){case"mute":B.css("set",this._elm.mute,"jyp_unmute");break;case"unmute":B.css("set",this._elm.mute,"jyp_mute");break}},switchFullSize:function(){switch(this._fullSize){case 1:self.close();break;case 0:this._fsWin=window.open("/jyoup/fullsize.html","fullsize"+this._id,"width="+screen.availWidth+",height="+screen.availHeight+",resizeable=yes,screenX=0,screenY=0");this.pause()}},repeatSwitch:function(){switch(this._repeatState){case -1:case 2:B.css("set",this._elm.repeat,"jyp_repeat");this._repeatState=0;break;case 0:B.css("set",this._elm.repeat,"jyp_repeat_one");this._repeatState=2;break;case 1:B.css("set",this._elm.repeat,"jyp_repeat_all");this._repeatState=2;break}},repeat:function(){if(this._repeatState<=0){return }switch(this._repeatState){case 1:if(this.getPlayerState()==0&&this._lastState==1){this.play()}if(this.getPlayerState()==0&&this._lastState==0){this.play()}break}},getVideoUrl:function(){return this._player.getVideoUrl()},loadPlayList:function(C){if(typeof C=="string"){if(C.indexOf(",")){this._playList=this._playList.concat(C.split(","))}else{this._playList.push(C)}}if(typeof C=="array"||typeof C=="object"){this._playList=C}return this},setLink:function(){this._elm.go_link.href=this.getVideoUrl()},playerReady:function(){this._player.addEventListener("onStateChange","eListener.onState."+this._id);this._player.addEventListener("onError","eListener.onError."+this._id);this.repeatSwitch();this.muteOnState();this.cueVideo();this.updatePlayer()},onState:function(C){switch(C){case 1:this.playSwitch("pause");break;case 2:case 5:case 0:this.playSwitch("play");if(C==5){this.setLink()}this.repeat()}this._lastState=C},onError:function(){},updatePlayer:function(){this.setLoadedSize();this.setPlayedSize();setTimeout(this.updatePlayer.bind_scope(this),250)},setLoadedSize:function(){var C=(this.getBt()<0)?0:Math.round(((this.getSb()+this.getBl())/this.getBt())*100);B.sizeP(this._elm.loaded,C)},setPlayedSize:function(){var D=(this.getDu()<1)?0:Math.ceil((this.getCt()/this.getDu())*100);B.sizeP(this._elm.played,D);var C=this._playList.length<2?"":(this._currVideo+1)+"-"+this._playList.length+" : ";this._elm.time.innerHTML=C+B.toTime(this.getCt())+"/"+B.toTime(this.getDu())+"&nbsp;"},getBl:function(){return this._player.getVideoBytesLoaded()},getBt:function(){return this._player.getVideoBytesTotal()},getCt:function(){return this._player.getCurrentTime()},getDu:function(){return this._player.getDuration()},getSb:function(){return this._player.getVideoStartBytes()},mouseDown:function(F){var C=F||window.event;var G=C.target||C.srcElement;var D=Math.round(((C.offsetX||C.layerX)/this._elm.play_line.offsetWidth)*100);var E=(this.getDu()/100)*D;this._player.seekTo(E,true)}};var B={ls:[],elm:function(C){return document.getElementById(C)||null},time:function(){return +new Date()},toTime:function(C){C=Math.round(C);return(C<60)?"0."+(C<10?"0"+C:C):(C/60).toFixed(2)},show:function(C){C.style.display="block";return C},hide:function(C){C.style.display="none";return C},size:function(E,C,D){if(typeof C!="undefined"){E.style.width=C+"px"}if(typeof D!="undefined"){E.style.height=D+"px"}},sizeP:function(E,C,D){if(typeof C!="undefined"){E.style.width=C+"%"}if(typeof D!="undefined"){E.style.height=C+"%"}},isIe:function(){return(typeof event!="undefined"&&typeof opera=="undefined"&&typeof XMLHttpRequest=="undefined")},css:function(F,G,D,C){switch(F){case"set":G.className=D;break;case"swap":G.className=!B.css("check",G,D)?G.className.replace(C,D):G.className.replace(D,C);break;case"add":if(!B.css("check",G,D)){G.className+=G.className?" "+D:D}break;case"remove":var E=G.className.match(" "+D)?" "+D:D;G.className=G.className.replace(E,"");break;case"check":return new RegExp("\\b"+D+"\\b").test(G.className)}},addCss:function(C){if(this.ls[C]===1){return }var D=document.createElement("link");D.setAttribute("rel","stylesheet");D.setAttribute("type","text/css");D.setAttribute("href",C);document.getElementsByTagName("head")[0].appendChild(D);this.ls[C]=1},getStyle:function(D,C){if(document.defaultView&&document.defaultView.getComputedStyle){return document.defaultView.getComputedStyle(D,"").getPropertyValue(C)}else{if(D.currentStyle){C=C.replace(/\-(\w)/g,function(E,F){return F.toUpperCase()});return D.currentStyle[C]}}},addEvent:function(E,C,D){if(E.addEventListener){E.addEventListener(C,D,false)}else{if(E.attachEvent){E.attachEvent("on"+C,D)}}}};window.eListener={onError:{},onState:{},player:{}};window.onYouTubePlayerReady=function(C){var D=B.elm("player_"+C).jYoup;D.playerReady();eListener.onState[D._id]=D.onState.bind_scope(D);eListener.onError[D._id]=D.onError.bind_scope(D);eListener.player[D._id]=D};Function.prototype.bind_scope=function(E){var C=this;var D=function(){var F=Array.prototype.slice.call(arguments);return C.apply(E,F)};return D}})();