/**
  * @name: FD.video 
  * @package: Fairfax Digital Javascript Framework 
  * @version: 0.1 
  * @author: Dave Elkan 
  * @copyright: Copyright 2008. Fairfax Digital. 
  * * * * * * * * * * * * * * * * * * * * * * * * * * 
  *             DO NOT ALTER THIS FILE. 
  *                ---                  
  * If your requirements are not met by this widget 
  * or this widget does not work please ask 
  * Dave Elkan <delkan@fairfaxdigital.com.au>. 
  * This widget is designed to to be used across 
  * the Fairfax Digital Network and contains no  
  * site specific code. 
  * Altering this file will render it unsupportable. 
  * * * * * * * * * * * * * * * * * * * * * * * * * *  
  * Created: 2008-07-14T14:34:19+10:00  
  * Revision: 29  
  * * * * * * * * * * * * * * * * * * * * * * * * * *  
  **/
if(FD){FD.Video=new Class({Implements:Options,options:{id:"fdVideo",playerHost:"http://media.fairfax.com.au",speedImageSrc:"/res/images/media_62k.gif?rand=",playerPath:"/ddx/FairfaxFlashPlayer.swf",playerListPath:"/controller/playlist.mpl/",insertHeadline:true,insertWoff:true,suffixPlayer:"_player",suffixWof:"_wof",suffixAd:"_ad",wofClass:"wof",adClass:"videoAd",playerVars:{autofit:true,autoplay:true,clickme:true,nielsen_ci:true,autostart:false,overlaytype:"banner",fullscreenurl:"/ddx/view.html"}},speeds:{1:56,2:100,3:300,4:600},initialize:function(D){this.setOptions(D);
if(this.options.rid){this.id=this.options.id;this.options.playerVars.fullscreenurl=this.options.playerHost+this.options.playerVars.fullscreenurl;this.options.playerVars.mediatype=this.options.mediatype;this.options.playerVars.mediaurl=this.options.mediaurl;var C=this._getVideoBox();var B=this.options.id;if(this.options.adRid){this._setAdRid(this.options.adRid)}this.domain=document.domain;this.adHitCalled=false;
var E=this.options.channelId;var A=this.options.category.replace(/ /g,"").toLowerCase();this.options.referrer=this.domain+"/"+this.options.referrer;if(C&&window[B]){this._checkSpeed()}this.logHitCalled=false}},_checkSpeed:function(){var A=Cookie.get("playerrate");if(!A){var C=this.options.playerHost+this.options.speedImageSrc+Math.floor(Math.random()*1000+1);this.startTime=this._getCurrent();var B=new Element("img",{src:C,events:{load:this._getKBPS.bind(this)}})
}else{this._setupClip(A)}},_getKBPS:function(){var B=63372;var C=(this._getCurrent()-this.startTime)/1000;var A=Math.floor(B/C/1024*8);Cookie.set("playerrate",A,0.25);Cookie.set("st",this._generateRandomString(16));this._setupClip(A)},_setAdRid:function(A){this.adRid=A},_setupClip:function(A){if(A){var B=1,C=3,D;while(C=this.speeds[B]){if(A<C){D=B;break}B++}if(!D){B--}this.rate=B;this._insertPlayer()
}},_insertPlayer:function(){var J=this._getVideoBox();if(J){var E="";if(this.adRid){E=this.adRid+"."+this.rate+","+this.options.rid+"."+this.rate}else{E=[this.options.rid,this.rate].join(".")}var C=this.options.playerHost+this.options.playerListPath+this.options.rid+"_"+this.rate+".xml?pl="+E+"&showid="+this.options.category+"&sy="+this.options.skin.toLowerCase();if(this.options.section){C+="&section="+this.options.section
}if(this.options.context){C+="&context="+this.options.context}var G=this.options.playerVars;G.src=C;var A=this.options.playerHost+this.options.playerPath;var B=this.options.width;var K=this.options.height;if(!B||!K){B=J.getStyle("width").toInt();K=J.getStyle("height").toInt()}var I=new Swiff(A,{id:this.options.id+this.options.suffixPlayer,width:B,height:K,vars:G,container:J});if(this.options.insertWoff||this.options.insertHeadline){var H=$(this.id+this.options.suffixWof);
if(!H){H=new Element("div",{"class":this.options.wofClass,id:this.id+this.options.suffixWof});H.inject(J,"after")}if(this.options.insertWoff){var D=new Element("p",{html:this.options.description}).inject(H,"top")}if(this.options.insertHeadline){var F=new Element("h4",{html:this.options.title}).inject(H,"top")}}}},_generateRandomString:function(B){var D="0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz".split("");
var A="";for(var C=0;C<B;C++){A+=D[Math.floor(Math.random()*D.length)]}return A},_getVideoBox:function(){return $(this.id)},_getCurrent:function(){return new Date().getTime()},_playStateChanged:function(){if(!this.logHitCalled){this.logHitURL=this.options.playerHost+"/controller/inline_controller.mpl?rid="+this.options.rid+"&cid="+this.rate+"&referrer="+this.options.referrer+"&skin="+this.options.skin;
this.logHitCalled=true;var B=new Element("img",{src:this.logHitURL})}if(!this.adHitCalled){this.adHitCalled=true;if(this.options.vericount){var E=new Element("img",{src:this.options.vericount})}if(this.options.adClickThru&&this.options.adMinirec){var D=$(this.id+this.options.suffixAd);if(!D){var C=$(this.id+this.options.suffixWof)||$(this.id+this.options.suffixPlayer);D=new Element("div",{"class":this.options.adClass,id:this.id+this.options.suffixAd}).inject(C,"after")
}var A=new Element("a",{href:this.options.adClickThru,target:"_blank"}).adopt(new Element("img",{src:this.options.adMinirec})).inject(D,"inside")}}},_openStateChanged:function(){}});FD.VideoController=new Hash({players:new Hash(),init:function(){var A=$$("div.fdVideo"),B=0;while(A[B]){if(A[B].id&&window[A[B].id]){var C=window[A[B].id];this._initInlinePlayer(C,A[B].id)}B++}},_initInlinePlayer:function(A,C){if(A&&C){A.id=C;
var B=new FD.Video(A);PlayStateChanged=B._playStateChanged.bind(B);OpenStateChanged=B._openStateChanged.bind(B)}},createInlinePlayer:function(A,B){if(B&&!this.players.contains(B)){this.players.set(B,A)}}});function initFDVideo(){FD.VideoController.init()}FD.register("FDVideo",1);var PlayStateChanged;var OpenStateChanged};
