var ClipClass=new Class({options:{attentechargementtimeout:5,attentechargementmax:15,startid:-1,defcategorie:"JOURNAUX",bwdetect:"bwdetect",bwdetecturl:"bwdetect.jpg",bwdetectsize:50,player:{container:"player",width:640,height:480,skin:"silverywhite.swf"},description:"description",note:"note",vue:"vue",avis:"avis",debit:"debit",carouselops:"",carousel:{liste:"liste",container:"container",thumbw:48},captcha:"captcha",captchaanswer:"captchaanswer",formulaire:"form",serverurl:""},initialize:function(panel,options){if($defined(options)){this.setOptions(options);}this.panel=$(panel);ApplySimplePanel(this.panel);this.flash=Browser.Plugins.Flash.version;this.player7=(this.flash<9);if(navigator.userAgent.match(/archos/i)){this.flash=9;this.player7=true;}if(!this.flash){if(navigator.userAgent.search("iPad")||navigator.userAgent.search("iPhone")||navigator.userAgent.search("Android")){this.panel.maximizePanel("mobile");(function(){location.href=baseOption.youtube;}).delay(baseOption.youtubeRedirect);return ;}this.panel.maximizePanel("noflash");return ;}this.tips=new Tips();this.formmatcher=new InputMatcher(this.options.formulaire,{autostart:false,timout:700});if(Browser.Engine.webkit){bwcookie=50;}else{bwcookie=Cookie.read("bwdetect");if(!$defined(bwcookie)||(bwcookie==false)){this.attentechargementcount=0;this.step="attentechargementpage";this.attentechargementtimer=(function(){this.doAction("timeout");}).periodical(this.options.attentechargementtimeout,this);return ;}}this.speed=bwcookie;this.step="liste";this.doAction("load",this.options.startid);},doAction:function(action,index){switch(this.step){case"attentechargementpage":switch(action){case"timeout":if($defined(window.isloaded)||(this.attentechargementcount>this.options.attentechargementmax)){try{$clear(this.attentechargementtimer);}catch(e){}this.step="detect";this.bwtime=$time();i=new Element("img");i.setProperty("src",this.options.bwdetecturl);i.addEvent("load",function(el){this.doAction("end",$time());}.bindWithEvent(this,i));i.injectInside($(this.options.bwdetect));this.panel.maximizePanel("detect");return ;}this.attentechargementcount++;break;}break;case"detect":switch(action){case"end":this.speed=(this.options.bwdetectsize*8192)/(index-this.bwtime);Cookie.write("bwvalue",index+"_"+this.bwtime+"_"+(index-this.bwtime),{duration:0});Cookie.write("bwdetect",this.speed,{duration:0});this.step="liste";this.doAction("load",this.options.startid);break;}break;case"attente":switch(action){case"ok":this.clip=index;s=false;for(i=0;i<this.clip.stream.length;i++){st=this.clip.stream[i];if(st.flash>this.flash){continue;}if(s==false){s=st;continue;}if((st.bitrate<=this.speed)&&(st.bitrate>s.bitrate)){s=st;continue;}}if(s==false){this.step="liste";this.panel.maximizePanel("versionflash");break;}this.pushPlayer(s,this.doautostart);this.setDebitListe(s.bitrate);l=$(this.options.description);l.empty();d=new Element("H1");d.appendText(this.clip.titre);d.injectInside(l);d=new Element("H2");d.appendText("Publié : "+this.clip.publication.formatDate(true));d.injectInside(l);d=new Element("H2");d.appendText("Durée : "+this.clip.duree.formatTime(true));d.injectInside(l);d=new Element("ul");for(i=0;i<this.clip.chapitre.length;i++){new Element("li").appendText(this.clip.chapitre[i].resume).injectInside(d);}d.injectInside(l);l=$(this.options.vue);l.empty();l.appendText(this.clip.nbvue);l=$(this.options.avis);l.empty();l.appendText(this.clip.commentaire.length);a=$(this.options.avis);a.empty();a.appendText(this.clip.commentaire.length+" avis");nn=0;if(this.clip.commentaire.length>0){for(j=0;j<this.clip.commentaire.length;j++){nn+=this.clip.commentaire[j].note;}nn=Math.floor(nn/this.clip.commentaire.length)+((nn%this.clip.commentaire.length)>=0.5?1:0);}for(ii=0;ii<this.options.note.length;ii++){$(this.options.note[ii]).setStyle("visibility",(ii==nn?"visible":"hidden"));}l=$(this.options.carousel.liste);l.empty();try{for(i=0;i<this.clip.chapitre.length;i++){r=this.clip.chapitre[i];s=new Element("span").injectInside(l);img=new Element("img").addClass("thumb").setProperties({src:baseOption.mediaurl+r.screenshot,width:baseOption.thumbw,height:baseOption.thumbh});img.store("chapitre",r.timecode);img.addEvent("click",function(el){this.doAction("seek",el.target.retrieve("chapitre"));}.bindWithEvent(this,img));img.injectInside(s);img.store("tip:title","Chapitre "+(i+1)+" ("+r.timecode.formatTime(true)+")");img.store("tip:text",r.resume);this.tips.attach(img);}this.carousel=new carousel(this.options.carousel.liste,this.options.carousel.container,this.options.carouselops);}catch(e){}try{favorisobj.pushVideoId(this.clip.id,this.clip.titre);}catch(e){}this.step="liste";this.panel.maximizePanel("liste");break;case"error":this.panel.maximizePanel("erreur");break;}break;case"liste":switch(action){case"playerReady":this.swiff.object.addModelListener("STATE","videoLaunghted");break;case"videoLaunghted":if($defined(this.clip.statistic)){break;}this.clip.statistic=true;JWebTv.incCounter(this.clip.id,{errorHandler:function(data){this.doAction("error",data);}.bind(this)});break;case"load":this.step="attente";this.panel.maximizePanel("attente");if(($defined(index)==false)||(index<=0)){this.doautostart=false;JWebTv.getLastClipFromSelection({callback:function(data){this.doAction("ok",data);}.bind(this),errorHandler:function(data){this.doAction("error",data);}.bind(this)});break;}this.doautostart=true;JWebTv.getClipById(index,{callback:function(data){this.doAction("ok",data);}.bind(this),errorHandler:function(data){this.doAction("error",data);}.bind(this)});break;case"seek":try{this.swiff.object.sendEvent("PLAY",true);this.swiff.object.sendEvent("SEEK",(index.getHours()*3600)+(index.getMinutes()*60)+(index.getSeconds()));}catch(e){}break;case"prev":try{this.carousel.prev();}catch(e){}break;case"next":try{this.carousel.next();}catch(e){}break;case"voter":this.step="voter";this.noteclient=index;$(this.options.formulaire).captchaanswer.value="";$(this.options.formulaire).com_nom.value="";$(this.options.formulaire).com_message.value="";$(this.options.erreur).empty();this.formmatcher.setActivate(true);this.panel.maximizePanel("voter");this.doAction("reload");break;case"debit":try{s=null;for(i=0;i<this.clip.stream.length;i++){if(this.clip.stream[i].bitrate==index){s=this.clip.stream[i];break;}}this.pushPlayer(s,true);this.setDebitListe(index);}catch(e){}break;case"error":break;}break;case"voter":switch(action){case"reload":$(this.options.captcha).empty();new Element("img").setProperty("src","/captcha/"+Math.ceil(Math.random()*100000)).injectInside($(this.options.captcha));break;case"ok":if(!this.formmatcher.isFormOk()){a=$(this.options.erreur);a.empty();a.appendText("Merci de corriger les champs marqués d'une croix rouge.");break;}this.step="waitvoter";this.panel.maximizePanel("attente");JWebTv.addComment(this.clip.id,$(this.options.formulaire).com_nom.value,$(this.options.formulaire).com_message.value,this.noteclient,$(this.options.formulaire).captchaanswer.value,{callback:function(data){this.doAction("ok",data);}.bind(this),errorHandler:function(data){this.doAction("error",data);}.bind(this),exceptionHandler:function(data){this.doAction("captcha",data);}.bind(this)});break;case"cancel":this.formmatcher.setActivate(false);this.step="liste";this.panel.maximizePanel("liste");break;}break;case"waitvoter":switch(action){case"ok":this.step="liste";this.formmatcher.setActivate(false);this.doAction("load",this.clip.id);break;case"captcha":if(index=="captchaerror"){a=$(this.options.erreur);a.empty();a.appendText("Le code ne correspond pas. Cliquez sur l'image pour afficher un nouveau code.");this.step="voter";this.panel.maximizePanel("voter");break;}case"error":this.formmatcher.setActivate(false);this.panel.maximizePanel("erreur");break;}break;}},pushPlayer:function(stream,autostart){p=$(this.options.player.container);p.empty();this.swiff=new Swiff(this.player7?"/mt/swf/player3.6.swf":"/mt/swf/player.swf",{id:"playerflash",width:this.options.player.width,height:this.options.player.height,container:p,params:{wmode:"opaque",bgcolor:"transparent",allowscriptaccess:"always",allowfullscreen:"true"},vars:{controlbar:this.player7?"bottom":"over",playlist:"none",enablejs:true,javascriptid:"mpl",skin:this.options.player.skin,autostart:autostart,bufferlength:5,streamer:this.options.serverurl+"/"+stream.clipAdr,file:this.player7?this.options.serverurl+"/"+stream.clipAdr:stream.clipId+".flv",id:stream.clipId,displayheight:this.options.player.height,plugins:"embed-1,googlytics-1","embed.code":baseOption.embedcode.substitute({vurl:encodeURIComponent(this.options.serverurl+"/"+stream.clipAdr),vid:stream.clipId}),"embed.title":"Ajouter cette video à votre site","embed.instruction":"Pour inclure cette video dans votre site, cliquez sur copier.","embed.close_text":"Fermer","embed.copy_text":"Copier","embed.copied_text":"Le code a été copié dans le presse-papier","embed.show_window_after_complete":true}});},setDebitListe:function(debit){try{d=$(this.options.debit);d.empty();a=[];for(i=0;i<this.clip.stream.length;i++){if(this.clip.stream[i].flash>this.flash){continue;}a.push(this.clip.stream[i].bitrate);}a.sort(function(x,y){return x-y;});if(Browser.Engine.webkit&&(a.length>1)){new Element("img",{src:baseOption.iconepath+"warning-16x16.png",title:"Il n'est pas possible de détecter la meilleure qualité avec ce navigateur. choix manuel obligatoire.","class":"mtips"}).injectInside(d);}for(i=0;i<a.length;i++){if(a[i]<1000){db=a[i]+"kb";}else{db=new Number(a[i]/1000).toFixed(1)+"Mb";}if(a[i]==debit){new Element("span",{"class":"select mtips",title:"Qualité actuelle"}).appendText(db).injectInside(d);continue;}l=new Element("a",{href:"javascript:void(0);",html:db,title:"Choisir cette qualité de vidéo.","class":"mtips",events:{click:function(){try{this.retrieve("objclip").doAction("debit",this.retrieve("bitrate"));}catch(e){}}}});l.store("bitrate",a[i]);l.store("objclip",this);l.injectInside(d);}}catch(e){}},doLoad:function(id){this.doAction("load",id);},prevChapitre:function(){this.doAction("prev");},nextChapitre:function(){this.doAction("next");},ok:function(){this.doAction("ok");},cancel:function(){this.doAction("cancel");},voter:function(val){this.doAction("voter",val);},refreshCaptcha:function(){this.doAction("reload");},hideErreur:function(){$(this.options.erreur).empty();},playerReady:function(){this.doAction("playerReady");},videoLaunghted:function(){this.doAction("videoLaunghted");}});ClipClass.implement(new Events,new Options);