
FlashProxy.options.swfLocation="/javascripts/lib/FlashProxy/FlashProxy.swf";if(!window.console){var K=function(){};console={log:K,time:K,timeEnd:K}}
function Player(url,elmStart,elmStop,correctSecondDuration,isMovie,opt){var self=this;var opt=opt||{};this.correctSecondDuration=correctSecondDuration;this.isMovie=isMovie
this.url=url;this.stopButton=new Button(elmStop);this.startButton=new Button(elmStart,true);this.loadBar=new Bar({element:getElement('loadbar'),bgColor:'#eee',fgColor:'#ddd',height:15});this.elmVolumeController=opt['elmVolumeController'];this.elmPlayerBar=opt['elmPlayerBar'];this.elmPlayerClock=opt['elmClock'];addElementClass(elmStart,'not-ready');connect(this.startButton,'onClick',dynamicBind('start',this));connect(this.stopButton,'onClick',dynamicBind('stop',this));connect(window,'onbeforeunload',this,'onUnload');}
Player.DEFAULT_INTERVAL=150;Player.RATE_MAX=2.5;Player.RATE_MIN=0.4;State.make(Player,'plugin',{plain:{load:function(start){start=start||false;if(getPluguinVersion('QuickTime')!=0){this.changeState('plugin','quicktime');}
else if(getPluguinVersion('Flash')!=0){this.changeState('plugin','flash');}
else{this.changeState('plugin','noPlugin');}
this.load(start);}},quicktime:{load:function(start){var self=this;self.wait();var loading=function(qt){self.loadBar.setRatio(qt.getLoadedRatio());}
var opt={loadingInterval:loading,url:self.url,isMovie:self.isMovie,duration:self.correctSecondDuration,element_id:'emb',autoplay:true};var deffered=QT.create(opt);deffered.addCallback(function(sound){if(!self.correctSecondDuration){self.correctSecondDuration=sound.quicktime.GetDuration()/sound.getTimeScale();}
self.volumeController=new VolumeController(sound,self.elmVolumeController);self.playerBar=new UI.Slider(self.elmPlayerBar,0,self.correctSecondDuration);self.playerClock=new PlayerClock(self.correctSecondDuration,self.elmPlayerClock);var r=sound.getLoadedRatio();var refresh=function(pos){var pos=pos||sound.getPosition()/1000
self.playerBar.setValue(pos,true);self.playerClock.update(pos);if(r<1){r=sound.getLoadedRatio();self.loadBar.setRatio(sound.getLoadedRatio());}}
self.refresh=refresh;connect(self,'onStart',function(){if(!self.playerBar.timer){self.playerBar.timer=setInterval(function(){refresh();},500)}});connect(self,'onStop',function(){if(self.playerBar.timer){clearTimeout(self.playerBar.timer);self.playerBar.timer=null;}});connect(self.playerBar,'valueChanged',function(val){self.playerClock.update(val);editPage.player.movePosition(val);editPage.getCurrentPanel().atInterval(editPage.player)});self.sound=sound;self.onSoundReady(start);messagePanel.hide();});deffered.addErrback(function(err){console.log(err);self.error();});this.changeState('main','loading');},shiftRate:function(up){var rate=this.sound.getRate();this.sound.setRate(up?Math.min(rate+0.1,Player.RATE_MAX):Math.max(rate-0.1,Player.RATE_MIN));},setRate:function(rate){this.sound.setRate(rate);}},flash:{load:function(start){var self=this;if(!Cookie.get('alertPlugin')){Cookie.set('alertPlugin',true);alert(getMessage('info.useFlash'));}
FlashProxy.getFirstInstance({callback:function(){setTimeout(function(){var sound=self.sound=new FlashProxy.Library.Sound();sound.loadSound(self.url,true);sound.stop();self.onSoundReady(start);},500)}})
this.changeState('main','loading');}},noPlugin:{load:function(start){if(!Cookie.get('alertPlugin')){Cookie.set('alertPlugin',true);alert(getMessage('info.noPlugin'));}}}},'plain');State.make(Player,'main',{notLoaded:{start:function(){var self=this;this.load(true);}},loading:{onSoundReady:function(start){start=start||false;var self=this;var sound=this.sound;self.wait();var elmButton=this.startButton.elmButton;var error_count=0;var interval=300;var timeout=30*1000;var id=setInterval(function(){var duration=sound.getDuration();var loaded=sound.getBytesLoaded();var total=sound.getBytesTotal();if(sound.flash&&duration==0&&loaded==0&&!total){error_count++;if(error_count>(timeout/interval)){clearInterval(id);self.error();}
return;}
if(duration>self.offset||total==loaded){self.changeState('main','stopped');clearInterval(id);removeElementClass(elmButton,'not-ready');elmButton.style.cursor='';elmButton.innerHTML=getMessage('resource.play');self.startButton.enable();if(start){self.start();}}else{toggleElementClass('not-ready',elmButton);elmButton.innerHTML=Math.round(duration/self.offset*100)+'%';}},interval);}},stopped:{start:function(){if(this.sound.getDuration()<this.offset){this.changeState('main','loading');this.onSoundReady(true);return;}
signal(this,'onStart',this);this.setInterval();this.changeState('main','playing');this.sound.start(this.offset/1000);this.startButton.disable();this.stopButton.enable();},setInterval:function(){var self=this;this.intervalId=setInterval(function(){signal(self,'atInterval',self);},this.interval);}},playing:{stop:function(){this.clearInterval();this.changeState('main','stopped');this.sound.stop();this.setSecondOffset(this.getSecondPosition());signal(this,'onStop',this);this.startButton.enable();this.stopButton.disable();},clearInterval:function(){if(!this.intervalId)return;clearInterval(this.intervalId);this.intervalId=null;}}},'notLoaded');MochiKit.Base.update(Player.prototype,{url:'',sound:null,startButton:null,stopButton:null,offset:0,intervalId:null,interval:Player.DEFAULT_INTERVAL,delay:0,onUnload:function(){if(!this.sound)return;this.stop();},setSecondPosition:function(second){if(this.sound){return this.sound.setPosition(second*1000);}},getSecondPosition:function(){return this.sound.getPosition()/1000;},setSecondOffset:function(secondOffset){this.offset=secondOffset*1000;},isPlaying:function(){return this.state['main']=='playing';},toggle:function(){this.isPlaying()?this.stop():this.start();},error:function(){messagePanel.show(getMessage('error.mediaFile'),7);editPage.access_fail_report();},wait:function(){var elmButton=this.startButton.elmButton;elmButton.style.cursor='wait';},setDelay:function(delay){var diff=this.delay-delay
var sec=this.getSecondPosition()
this.delay=delay
var s=(sec-diff<0)?0:sec-diff;this.setSecondPosition(s);this.setSecondOffset(s);},getDelay:function(){return this.delay},movePosition:function(pos){this.setSecondPosition(pos);this.setSecondOffset(pos);},hideMovie:function(){if(this.isMovie&&this.sound&&this.sound.hideMovie){this.sound.hideMovie();}},showMovie:function(){if(this.isMovie&&this.sound&&this.sound.showMovie){this.sound.showMovie();}}});function VolumeController(sound,elm){this.element=elm?elm:document.createElement('div');this.sound=sound;this.volImg=createDOM('img',{src:'/images/sound.png'});this.volStatus=createDOM('span',{'class':'vol_status'},'');this.element.appendChild(this.volImg);this.element.appendChild(this.volStatus);var self=this;this.displayVolume();connect(this.element,'onclick',function(){self.down();})}
VolumeController.prototype.displayVolume=function(){var s='';var v=this.sound.getVolume();for(var i=0;i<Math.round(v/25);i++){s+='|';}
this.volStatus.innerHTML=s;}
VolumeController.prototype.down=function(){var v=this.sound.getVolume();var vv=(Math.round(v/25)+4)%5;this.sound.setVolume(vv*25);this.displayVolume();}
function PlayerClock(duration,elm){if(!duration){return;}
this.element=elm?elm:document.createElement('div');this.hasHour=duration>=60*60;this.elemCurrent=createDOM('span',{'class':'clock_duration'},ppsec(0,this.hasHour));this.elemDuration=createDOM('span',{'class':'clock_duration'},ppsec(duration));this.element.appendChild(this.elemCurrent);this.element.appendChild(createDOM('span',{},'/'));this.element.appendChild(this.elemDuration);}
PlayerClock.prototype.update=function(sec){var s=ppsec(sec,this.hasHour);if(this.elemCurrent&&s!=this.elemCurrent.innerHTML){this.elemCurrent.innerHTML=s;}}
function ppsec(sec,isDisplayHour){var s=typeof(sec)=='number'?sec:0;var format=function(num){var s=String(num);return s.length==1?'0'+s:s;}
var hour=Math.floor(s/(60*60));var minu=Math.floor((s-60*60*hour)/60);var seco=Math.floor(s%60);if(isDisplayHour||hour>0){return[format(hour),format(minu),format(seco)].join(':');}
else{return[format(minu),format(seco)].join(':');}}
function Bar(opt){var opt=opt?opt:{};this.width=opt.width||200;this.height=opt.height||20;this.onUpdate=opt.onUpdate;this.ratio=opt.defaultRatio||0;this.element=opt['element']?opt['element']:document.createElement('div');this.element.style.width=this.width+'px';this.element.style.height=this.height+'px';this.element.style.backgroundColor=opt.bgColor||'#ccc';this.element.style.padding=0;var inner=document.createElement('div');inner.style.width=(opt.defaultRatio||0)+'px';inner.style.height=this.height+'px';inner.style.backgroundColor=opt.fgColor||'#999';inner.style.padding=0;inner.style.margin=0;this.element.appendChild(inner);this.inner=inner;}
Bar.prototype.setRatio=function(ratio){var r=ratio>1?1:ratio;this.ratio=r;this.update();};Bar.prototype.addRatio=function(ratio){var r=this.ratio+ratio>1?1:this.ratio+ratio;this.ratio=r;this.update();};Bar.prototype.update=function(){this.inner.style.width=this.width*this.ratio+'px';};function NextPage(baseURL){this.baseURL=baseURL;var q=this.query=parseQueryString(location.search);q.page||(q.page=1);new PageExpnader(bind('expand',this));}
MochiKit.Base.update(NextPage.prototype,{query:null,expand:function(end,terminate){var self=this;showElement('indicator');this.query.page++;doXHR(this.baseURL+queryString(this.query)).addCallback(function(res){var elmPage=SPAN();elmPage.innerHTML=res.responseText;insertSiblingNodesBefore('indicator',elmPage);if(!getElementsByTagAndClassName('a','next_page',elmPage).length){terminate();}}).addErrback(function(err){terminate();}).addBoth(function(){hideElement('indicator');end();});}})