var VideoForm=new Class({Extends:LaunchPad.Base,options:{url:"/video/ajax_post/",video_found:false,video_id:false,content_type_id:false,object_id:false,form_mode:"flv_url"},initialize:function(a){this.setOptions(a);this.parent(this.options);var b={method:"video_form",content_type_id:this.options.content_type_id,object_id:this.options.object_id};if(this.options.video_id){$extend(b,{video_id:this.options.video_id})}this.addEvent("openComplete",this.manageForm.bind(this));this.open("post",b)},manageForm:function(){if(this.options.form_mode=="embed"){if(this.options.video_id){this.show_fields()}else{var c=this.options.stage.getElement("#id_embed");var b=this.options.stage.getElement(".jsFind");b.addEvent("click",function(){this.get_video_details_from_embed(c.value)}.bind(this));b.removeClass("dn")}}else{var a=this.options.stage.getElement(".jsAdd");a.removeClass("dn")}var a=this.options.stage.getElement(".jsAdd");a.addEvent("click",this.submit.bind(this))},get_video_details_from_embed:function(a){this.toggleLoading(true,this);this.options.stage.getElement(".jsEmbedError").setHTML("");var c={method:"embed_details",embed:a};var b=new VinesAjax(this.options.url,{method:"post",data:c,onFailure:function(){this.options.stage.getElement(".jsEmbedError").setHTML("Sorry, I cannot compute that emebed code.");this.toggleLoading(false,this)}.bind(this),onComplete:function(f){var f=JSON.decode(f);this.options.video_found=true;this.show_fields();var g=this.options.stage.getElement("#id_name");var e=this.options.stage.getElement("#id_deck");var j=this.options.stage.getElement("#id_embed");var d=this.options.stage.getElement("#jsSingleImageSrc");var h=this.options.stage.getElement("#thumbnail_input");if(g.value.trim()==""){g.value=f.name}if(e.innerHTML.trim()==""){e.setHTML(f.deck)}d.src=f.thumbnail_url;d.setProperties({width:"100px",height:"100px"});h.value=f.thumbnail_url;var i=this.options.stage.getElement(".jsEmbed");i.setHTML(j.value);this.toggleLoading(false,this)}.bind(this)});b.request()},submit:function(){var d="";var a=this.options.stage.getElement("#id_name");var i=this.options.stage.getElement("#id_deck");var g=this.options.stage.getElement("#id_embed");var b=this.options.stage.getElement("#id_url");var c=this.options.stage.getElement("#id_video_type");if(this.options.form_mode=="embed"){if(g.value==""){d+="You need to embed some flash code\n"}if(!this.options.video_found&&g.value!==""){d+="The video embed code was not recognized."}}else{if(b.value==""){d+="You need a link to an FLV file\n"}}if(a.value==""){d+="You need to fill in a name\n"}if(i.value==""){d+="You need to fill in a summary\n"}if(c.selectedIndex==0){d+="You need to select a type\n"}if(d!==""){d="Sorry "+VINES_USER_NAME+":\n"+d;alert(d);return false}this.toggleLoading(true,this.options.stage);var e={method:"video_save",content_type_id:this.options.content_type_id,object_id:this.options.object_id};if(this.options.stage.getElement("#jsForm")){e=this.options.stage.getElement("#jsForm")}var f;var h=new VinesAjax(this.options.url,{method:"post",update:this.options.stage,evalScripts:true,data:e,onFailure:function(){alert("Sorry, there was an error");this.toggleLoading(false,this.options.stage)}.bind(this),onComplete:function(j){this.toggleLoading(false,this.options.stage)}.bind(this)});h.request()}});VideoForm.implement(new Options());VideoPlayer=new Class({options:{playerId:null,playerWrapperEl:null,endEl:null,ageGateEl:null,playerKey:"",downloadType:"streaming",quality:"medium",imageUrl:"",playerSwf:"",rtmpSwf:"",contentSwf:"",videoUrl:"",streamingPrefix:"",progressivePrefix:"",ctId:"",videoId:"",adSlot:"",ageGate:false,minimumAge:18,ageGateTooYoungMessage:"You're too young to watch the filth in this video. Go to church instead.",qualityCookie:"video_quality",downloadTypeCookie:"video_download_type",cookieOpts:{path:"/",duration:365},allQualities:["low","medium","high"],allDownloadTypes:["streaming","progressive"],qualityMap:{low:"700",medium:"700",high:"1500"},controls:null,loadTimer:null,ageGatePassed:false,playerSetup:false,prerollFilled:false,prerollClip:null,playbackSkipped:false,questUrl:"",metricsStartSent:false,metricsEndSent:false},initialize:function(a){this.setOptions(a);if(Browser.Platform.ipod){this.initHTML5();return}this.detectClientPrefs();this.options.playerWrapperEl.getElements(".js-video-downloadtype").each(function(b){b.addEvent("click",function(){this.changeDownloadType(b.getProperty("type"));this.togglePrefDisplay()}.bind(this))}.bind(this));this.options.playerWrapperEl.getElements(".js-video-quality").each(function(b){b.addEvent("click",function(){this.changeQuality(b.getProperty("type"));this.togglePrefDisplay()}.bind(this))}.bind(this));this.options.playerWrapperEl.getElements(".js-video-play").each(function(b){b.addEvent("click",function(){if(this.options.loadTimer!=null){return}if(this.options.ageGate&&!this.options.ageGatePassed&&this.options.ageGateEl.value.toInt()<this.options.minimumAge){alert(this.options.ageGateTooYoungMessage);return}this.options.ageGatePassed=true;this.fillAd();this.options.endEl.addClass("dn");this.options.loadTimer=this.pollPlayer.periodical(100,this)}.bind(this))}.bind(this));this.options.playerWrapperEl.getElements(".js-video-embed").each(function(b){b.addEvent("click",function(){b.select()})}.bind(this))},togglePrefDisplay:function(){this.options.playerWrapperEl.getElements(".js-video-downloadtype").each(function(a){if(a.getProperty("type")==this.options.downloadType){a.addClass("selected")}else{a.removeClass("selected")}}.bind(this));this.options.playerWrapperEl.getElements(".js-video-quality").each(function(a){if(a.getProperty("type")==this.options.quality){a.addClass("selected")}else{a.removeClass("selected")}}.bind(this))},detectClientPrefs:function(){var a=Cookie.read(this.options.downloadTypeCookie)||this.options.downloadType;if(!this.options.allDownloadTypes.contains(a)){a=this.options.downloadType}this.options.downloadType=a;var b=Cookie.read(this.options.qualityCookie)||this.options.quality;if(!this.options.allQualities.contains(b)){b=this.options.quality}this.options.quality=b;this.togglePrefDisplay()},pollPlayer:function(){if(this.options.playerSetup){$f(this.options.playerId).play(0);return}if(!this.options.prerollFilled){return}this.options.loadTimer=$clear(this.options.loadTimer);this.setupPlayer()},setupPlayer:function(){var a={playlist:this.getClipPlaylist(),clip:{onStart:this.clipStarted.bind(this),onFinish:this.clipFinished.bind(this),onBeforeSeek:this.clipSeekedTo.bind(this),scaling:"fit"},canvas:{background:"#000000",backgroundGradient:"none"},plugins:{cf:{netConnectionUrl:this.options.streamingPrefix,url:this.options.rtmpSwf}}};if(this.options.playerKey){a.key=this.options.playerKey}if(this.options.controls){a.plugins["controls"]=this.options.controls}$f(this.options.playerId,{src:this.options.playerSwf,wmode:"transparent"},a);$f(this.options.playerId).play();this.options.playerSetup=true},changeQuality:function(a){if(this.options.allQualities.contains(a)){this.options.quality=a;Cookie.write(this.options.qualityCookie,a,this.options.cookieOpts)}},changeDownloadType:function(a){if(this.options.allDownloadTypes.contains(a)){this.options.downloadType=a;Cookie.write(this.options.downloadTypeCookie,a,this.options.cookieOpts)}},getClipPlaylist:function(){var e={};var c=this.options.videoUrl;if(this.options.downloadType=="progressive"){c=this.options.progressivePrefix+c;e.provider="http"}else{c="video/"+c;e.provider="cf"}var b=this.options.qualityMap[this.options.quality];var d=c.split(".");c=d.slice(0,d.length-1).join(".")+"_"+b;if(this.options.downloadType=="progressive"){c+="."+d[d.length-1]}else{c=d[d.length-1]+":"+c}e.url=c;var a=[];if(this.options.prerollClip){a.push(this.options.prerollClip)}a.push(e);return a},fillAd:function(){if(!this.options.prerollFilled){if(typeof(vinesAds)!="undefined"){vinesAds.fillPreroll(this.options.adSlot,this.prerollCallback.bind(this))}else{this.options.prerollFilled=true}}},prerollCallback:function(a){this.options.prerollFilled=true;if(a){a.onStart=function(){if(a.trackingUrl){new Element("img",{styles:{height:1,width:1},src:a.trackingUrl}).inject(document.body)}};a.onBeforePause=function(){return false};a.onBeforeSeek=function(){return false};a.onBeforeFinish=function(){return false};a.onFinish=function(){var b=$f(this.options.playerId);b.stop();b.play(b.getPlaylist().slice(1));return false}.bind(this);this.options.prerollClip=a}},createMetricsUrl:function(a){a={start:"1",end:"3"}[a];return"/metrimatics/add_event/?event_type=watch_video&value="+a+"&value2="+this.options.qualityMap[this.options.quality]+"&value3=0&content_type_id="+this.options.ctId+"&object_id="+this.options.videoId},clipStarted:function(a){if(!a.isAd&&!this.options.metricsStartSent){new Request({url:this.createMetricsUrl("start"),method:"GET"}).send();this.options.metricsStartSent=true}},clipFinished:function(a){if(!a.isAd){if(!this.options.metricsEndSent){new Request({url:this.createMetricsUrl("end"),method:"GET"}).send();this.options.metricsEndSent=true}if(this.options.questUrl&&!this.options.playbackSkipped){new Request({url:this.options.questUrl,method:"GET"}).send()}this.options.endEl.removeClass("dn")}},clipSeekedTo:function(b,c){var a=$f(this.options.playerId);if(a.getStatus()["time"]<c){this.options.playbackSkipped=true}},initHTML5:function(){this.options.playerWrapperEl.getElements(".js-video-downloadtype, .js-video-quality").remove();this.options.playerWrapperEl.getElements(".js-video-play").addEvent("click",function(){var b=this.options.playerWrapperEl.getElement(".player");var a=this.options.videoUrl.split(".")[0]+"_ip.m4v";var c=new Element("video",{src:this.options.progressivePrefix+a,width:640,height:360,controls:"controls",autoplay:"autoplay",poster:this.options.posterUrl||""});c.replaces(b)}.bind(this))}});VideoPlayer.implement(new Options());function editVideosJs(a){a.titleTextStr="Edit Video";new VideoForm(a)}function addVideosJs(a){a.titleTextStr="Add Video";new VideoForm(a)}function toggleVidAssoc(){toggleDiv("js-content-obj-assoc");toggleDiv("js-topic-assoc");if($("js-content-obj-assoc").hasClass("dn")){}};
