Ext.namespace('Ext.ux');Ext.ux.YoutubePlayer=Ext.extend(Ext.ux.MediaPanel.Flash,{player:null,videoId:null,initComponent:function(){var oytpr=function(playerId){var cmpId=Ext.ux.YoutubePlayer.Players[playerId];if(cmpId){var panel=Ext.getCmp(cmpId);var player=document.getElementById(playerId);panel._setPlayer(player);player.addEventListener('onStateChange',"Ext.getCmp('"+panel.id+"')._delegateStateEvent");player.addEventListener('onError',"Ext.getCmp('"+panel.id+"')._delegateErrorEvent");player.addEventListener('onButtonPlayClick',"Ext.getCmp('"+panel.id+"')._delegateButtonPlayClick");player.addEventListener('onButtonPauseClick',"Ext.getCmp('"+panel.id+"')._delegateButtonPauseClick");player.addEventListener('onButtonShuffleClick',"Ext.getCmp('"+panel.id+"')._delegateButtonShuffleClick");player.addEventListener('onButtonRepeatClick',"Ext.getCmp('"+panel.id+"')._delegateButtonRepeatClick");player.addEventListener('onButtonHdClick',"Ext.getCmp('"+panel.id+"')._delegateButtonHdClick");player.addEventListener('onButtonPreviousClick',"Ext.getCmp('"+panel.id+"')._delegateButtonPreviousClick");player.addEventListener('onButtonNextClick',"Ext.getCmp('"+panel.id+"')._delegateButtonNextClick");player.addEventListener('onFullScreenStateChange',"Ext.getCmp('"+panel.id+"')._delegateFullScreenStateChange");player.addEventListener('onVolumeChange',"Ext.getCmp('"+panel.id+"')._delegateVolumeChange");player.addEventListener('onMuteChange',"Ext.getCmp('"+panel.id+"')._delegateMuteChange");panel.adjustRatio(panel.getInnerWidth(),panel.getInnerHeight());panel.fireEvent('ready',panel,player);}};window.onYouTubePlayerReady=oytpr;this.ratioMode=this.ratioMode||'normal';this.playerUrl=this.playerUrl|| "http://gdata.youtube.com/apiplayer";this.additionalParams=this.additionalParams||"&enablejsapi=1";var wmode="window";if(this.assertVersion("9.0.115")){wmode="transparent";}this.mediaCfg={};var defMediaCfg={mediaType:'SWF',url:this.playerUrl+"?key="+this.developerKey+this.additionalParams+"&playerapiid="+this.playerId,id:this.playerId,start:false,controls:false,params:{wmode:wmode,allowFullScreen:true,allowScriptAccess:"always",bgcolor:this.bgColor||"#cccccc"}};Ext.apply(this.mediaCfg,defMediaCfg);this.addEvents('ready','stateChange','error','play','pause','shuffle','repeat','hd','previous','next','fullscreen','volume','mute');if(!Ext.ux.YoutubePlayer.Players){Ext.ux.YoutubePlayer.Players=[];}Ext.ux.YoutubePlayer.Players[this.playerId]=this.id;Ext.ux.YoutubePlayer.superclass.initComponent.call(this);},_setPlayer:function(player){this.player=player;},_delegateStateEvent:function(state){switch(state){case-1:state='unstarted';break;case 0:state='ended';break;case 1:state='playing';break;case 2:state='paused';break;case 3:state='buffering';break;case 5:state='video_cued';break;default:state='unknown';break;}this.fireEvent('stateChange',state,this,this.player);},_delegateErrorEvent:function(errorCode){switch(errorCode){case 100:errorCode='video_not_found';break;case 102:errorCode='video_ld';break;default:errorCode='unknown';break;}this.fireEvent('error',errorCode,this,this.player);},_delegateButtonPlayClick:function(){this.fireEvent('play',this,this.player);},_delegateButtonPauseClick:function(){this.fireEvent('pause',this,this.player);},_delegateButtonShuffleClick:function(){this.fireEvent('shuffle',this,this.player);},_delegateButtonRepeatClick:function(){this.fireEvent('repeat',this,this.player);},_delegateButtonHdClick:function(){this.fireEvent('hd',this,this.player);},_delegateButtonPreviousClick:function(){this.fireEvent('previous',this,this.player);},_delegateButtonNextClick:function(){this.fireEvent('next',this,this.player);},_delegateFullScreenStateChange:function(value){this.fireEvent('fullscreen',value,this,this.player);},_delegateVolumeChange:function(value){this.fireEvent('volume',value,this,this.player);},_delegateMuteChange:function(value){this.fireEvent('mute',value,this,this.player);},onResize:function(w,h){Ext.ux.YoutubePlayer.superclass.onResize.call(this,w,h);if(this.playerAvailable()){this.adjustRatio(w,h);}},adjustRatio:function(width,height){var pStyle=this.player.style;switch(this.ratioMode){case'strict':if(width<400||height<320){var newHeight=Math.floor(width*0.8);if(newHeight>height){width=Math.floor(height/0.8);}else{height=newHeight;}}else{if(height>320){height=320;width=400;}}pStyle.marginTop=-Math.floor(height/2)+'px';pStyle.marginLeft=-Math.floor(width/2)+'px';pStyle.height=height+'px';pStyle.width=width+'px';pStyle.top='50%';pStyle.left='50%';pStyle.position='absolute';this.setPlayerSize(width,height);break;case'stretch':pStyle.margin='auto';pStyle.height=height+'px';pStyle.width=width+'px';this.setPlayerSize(width,height);break;}},playerAvailable:function(){return(this.player&&this.player.getPlayerState)?true:false;},loadVideoById:function(videoId,startSeconds){this.videoId=videoId;this.player.loadVideoById(videoId,startSeconds);},cueVideoById:function(videoId,startSeconds){this.videoId=videoId;this.player.cueVideoById(videoId,startSeconds);},setPlayerSize:function(width,height){this.player.setSize(width,height);},playVideo:function(){this.player.playVideo();},pauseVideo:function(){this.player.pauseVideo();},stopVideo:function(){this.player.stopVideo();},clearVideo:function(){this.player.clearVideo();},getVideoBytesLoaded:function(){return this.player.getVideoBytesLoaded();},getVideoBytesTotal:function(){return this.player.getVideoBytesTotal();},getVideoStartBytes:function(){return this.player.getVideoStartBytes();},mute:function(mute){if(mute===false){this.player.unMute();this.setVolume(this.getVolume());}else{this.player.mute();}},isMuted:function(mute){return this.player.isMuted();},setVolume:function(volume){this.player.setVolume(volume);},getVolume:function(){return this.player.getVolume();},seekTo:function(seconds,allowSeekAhead){this.player.seekTo(seconds,allowSeekAhead);},getPlayerState:function(){var state=this.player.getPlayerState();switch(state){case-1:state='unstarted';break;case 0:state='ended';break;case 1:state='playing';break;case 2:state='paused';break;case 3:state='buffering';break;case 5:state='video_cued';break;default:state='unknown';break;}return state;},getCurrentTime:function(){return this.player.getCurrentTime();},getDuration:function(){return this.player.getDuration();},getVideoUrl:function(){return this.player.getVideoUrl();},getVideoEmbedCode:function(){return this.player.getVideoEmbedCode();},setHd:function(value){return this.player.setHd(value);},getHd:function(){return this.player.getHd();},setRepeat:function(value){return this.player.setRepeat(value);},getRepeat:function(){return this.player.getRepeat();},setShuffle:function(value){return this.player.setShuffle(value);},getShuffle:function(){return this.player.getShuffle();},setLoaded:function(){return this.player.setLoaded();},getAndResetClear:function(){return this.player.getAndResetClear();}});