// Turner XMP, Release Build, © 2007 Turner Broadcasting System, Inc. A Time Warner Company.  File: xmp_net, Version: 0.1.567.2163

if(typeof(window)!=='undefined'){var deconcept;if(typeof deconcept==="undefined"){deconcept={};}
deconcept.hop=function(m,k){if(typeof(m.hasOwnProperty)==='undefined'){return true;}
return m.hasOwnProperty(k);};if(typeof deconcept.util==="undefined"){deconcept.util={};}
if(typeof deconcept.SWFObjectUtil==="undefined"){deconcept.SWFObjectUtil={};}
deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a,_b){if(!document.getElementById){return;}
this.DETECT_KEY=_b?_b:"detectflash";this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);this.params={};this.variables={};this.attributes=[];if(_1){this.setAttribute("swf",_1);}
if(id){this.setAttribute("id",id);}
if(w){this.setAttribute("width",w);}
if(h){this.setAttribute("height",h);}
if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}
this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();if(c){this.addParam("bgcolor",c);}
var q=_8?_8:"high";this.addParam("quality",q);this.setAttribute("useExpressInstall",_7);this.setAttribute("doExpressInstall",false);var _d=(_9)?_9:window.location;this.setAttribute("xiRedirectUrl",_d);this.setAttribute("redirectUrl","");if(_a){this.setAttribute("redirectUrl",_a);}};deconcept.SWFObject.prototype={setAttribute:function(_e,_f){this.attributes[_e]=_f;},getAttribute:function(aa){return this.attributes[aa];},addParam:function(ba,ca){this.params[ba]=ca;},getParams:function(){return this.params;},addVariable:function(da,ea){this.variables[da]=ea;},getVariable:function(fa){return this.variables[fa];},getVariables:function(){return this.variables;},getVariablePairs:function(){var ga=[];var ha;var ia=this.getVariables();for(ha in ia){if(deconcept.hop(ia,ha)){ga.push(ha+"="+ia[ha]);}}
return ga;},getSWFHTML:function(){var ja="";if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","PlugIn");}
ja="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\"";ja+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";var ka=this.getParams();for(var la in ka){if(deconcept.hop(ka,la)){ja+=[la]+"=\""+ka[la]+"\" ";}}
var ma=this.getVariablePairs().join("&");if(ma.length>0){ja+="flashvars=\""+ma+"\"";}ja+="/>";}else{if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");}
ja="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\">";ja+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";var na=this.getParams();for(var oa in na){if(deconcept.hop(na,oa)){ja+="<param name=\""+oa+"\" value=\""+na[oa]+"\" />";}}
var pa=this.getVariablePairs().join("&");if(pa.length>0){ja+="<param name=\"flashvars\" value=\""+pa+"\" />";}ja+="</object>";}
return ja;},write:function(qa){if(this.getAttribute("useExpressInstall")){var ra=new deconcept.PlayerVersion([6,0,65]);if(this.installedVer.versionIsValid(ra)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){this.setAttribute("doExpressInstall",true);this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));document.title=document.title.slice(0,47)+" - Flash Player Installation";this.addVariable("MMdoctitle",document.title);}}
if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){var n=(typeof qa==="string")?document.getElementById(qa):qa;n.innerHTML=this.getSWFHTML();return true;}else{if(this.getAttribute("redirectUrl")!==""){document.location.replace(this.getAttribute("redirectUrl"));}}
return false;}};deconcept.SWFObjectUtil.getPlayerVersion=function(){var sa;var ta=new deconcept.PlayerVersion([0,0,0]);if(navigator.plugins&&navigator.mimeTypes.length){var x=navigator.plugins["Shockwave Flash"];if(x&&x.description){ta=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}}else{try{sa=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}
catch(e){try{sa=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");ta=new deconcept.PlayerVersion([6,0,21]);sa.AllowScriptAccess="always";}
catch(e2){if(ta.major===6){return ta;}}try{sa=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}
catch(e3){}}if(sa!==null){ta=new deconcept.PlayerVersion(sa.GetVariable("$version").split(" ")[1].split(","));}}
return ta;};deconcept.PlayerVersion=function(ua){this.major=ua[0]!==null?parseInt(ua[0],10):0;this.minor=ua[1]!==null?parseInt(ua[1],10):0;this.rev=ua[2]!==null?parseInt(ua[2],10):0;};deconcept.PlayerVersion.prototype.versionIsValid=function(fv){if(this.major<fv.major){return false;}
if(this.major>fv.major){return true;}
if(this.minor<fv.minor){return false;}
if(this.minor>fv.minor){return true;}
if(this.rev<fv.rev){return false;}return true;};deconcept.util={getRequestParameter:function(va){var q=document.location.search||document.location.hash;if(q){var wa=q.substring(1).split("&");for(var i=0;i<wa.length;i++){if(wa[i].substring(0,wa[i].indexOf("="))===va){return wa[i].substring((wa[i].indexOf("=")+1));}}}
return"";}};deconcept.SWFObjectUtil.cleanupSWFs=function(){if(window.opera||!document.all){return;}
var xa=document.getElementsByTagName("OBJECT");for(var i=0;i<xa.length;i++){xa[i].style.display="none";for(var x in xa[i]){if(deconcept.hop(xa[i],x)){if(typeof xa[i][x]==="function"){xa[i][x]=function(){};}}}}};deconcept.SWFObjectUtil.prepUnload=function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){};if(typeof window.onunload==="function"){var ya=window.onunload;window.onunload=function(){deconcept.SWFObjectUtil.cleanupSWFs();ya();};}else{window.onunload=deconcept.SWFObjectUtil.cleanupSWFs;}};if(typeof window.onbeforeunload==="function"){var oldBeforeUnload=window.onbeforeunload;window.onbeforeunload=function(){deconcept.SWFObjectUtil.prepUnload();oldBeforeUnload();};}else{window.onbeforeunload=deconcept.SWFObjectUtil.prepUnload;}
if(Array.prototype.push===null){Array.prototype.push=function(za){this[this.length]=za;return this.length;};}
var getQueryParamValue=deconcept.util.getRequestParameter;var FlashObject=deconcept.SWFObject;var SWFObject=deconcept.SWFObject;}
var xmp;if(!xmp){xmp={};}else if(typeof xmp!=="object"){throw new Error("xmp already exists and is not an object");}
xmp=function(){};xmp._globalNamespace=this;xmp.getGlobalNamespace=function(){return xmp._globalNamespace;};xmp.isBrowserEnvironment=function(){return(typeof(window)!=='undefined');};xmp.createNamespace=function(ns){var Aa=ns.split(".");var Ba=xmp.getGlobalNamespace();for(var i=0;i<Aa.length;i++){if(typeof(Ba[Aa[i]])==="undefined"){Ba[Aa[i]]={};}
Ba=Ba[Aa[i]];}};xmp.extractErrorMessage=function(e){if(e instanceof Error){return('Error name: '+e.name+', Error message: '+e.message);}
else{return"UNKNOWN ERROR";}};xmp.chooseValueOrDefault=function(Ca,Da){if(!((arguments.length===2)&&(Da!==null)&&(typeof Da!=='undefined'))){throw new xmp.util.internals.InvalidArgsError("Invalid invalid 'defaultValue' (undefined or null).");}
return(typeof Ca===typeof Da)?Ca:Da;};xmp.trimString=function(Ea){return Ea.replace(/^\s*/,'').replace(/\s*$/,'');};xmp.isNonEmptyString=function(Fa){return((typeof(Fa)==='string')&&(Fa!==null)&&(Fa.length>0));};xmp.getNamespacedMethod=function(Ga){var Ha=xmp.splitMethodAndNamespace(Ga);var Ia=xmp.getObjectFromString(Ha.ns);return Ia[Ha.method];};xmp.splitMethodAndNamespace=function(Ja){var Ka=Ja.lastIndexOf('.');var La={};La.method=Ja;La.ns='';if(Ka!==-1){La.method=Ja.substring(Ka+1);La.ns=Ja.substring(0,Ka);}
return La;};xmp.getObjectFromString=function(Ma){var Na=Ma.split('.');var o=xmp.getGlobalNamespace();for(var i=0;i<Na.length;i++){o=o[Na[i]];}
return o;};xmp.isNumber=function(Oa,Pa){var Qa=0;for(var i=0;i<Oa.length;i++){var Ra=Oa.charCodeAt(i);if(Ra>=48&&Ra<=57){continue;}
if(Ra===45){if(i!==0){return false;}
continue;}
if(Ra===46){if(!Pa){return false;}
Qa++;if(Qa>1){return false;}
continue;}
return false;}
return true;};xmp.escapeHtml=function(Sa,Ta,Ua){var Va='';var Wa='@';for(var i=0;i<Sa.length;i++){var c=Sa.charAt(i);switch(c){case'&':Va+='&amp;';break;case'<':Va+='&lt;';break;case'>':Va+='&gt;';break;case'\"':Va+='&quot;';break;case'\'':if(false===Ta){Va+='&apos;';}break;case' ':if(Ua&&Wa===' '){Va+='&nbsp;';}
else{Va+=c;}
break;default:Va+=c;break;}
Wa=c;}
Va=Va.replace(/\r/g,'');if(Ua){Va=Va.replace(/\n/g,'<br>');Va=Va.replace(/\t/g,'&nbsp;&nbsp;&nbsp;&nbsp;');}
return Va;};xmp.validateArguments=function(Xa,Ya,Za){if((Xa.length>Ya.length)||Xa.length<Ya.length){throw new xmp.util.internals.InvalidArgsError("Invalid argument count \""+Xa.length+"\" for function/method \""+Za+"\".  Expected count was \""+Ya.length+"\".");}
for(var i=0;i<Xa.length;i++){if(Ya[i]===xmp.UNKNOWN_TYPE||typeof(Xa[i])===Ya[i]){continue;}
throw new xmp.util.internals.InvalidArgsError("Invalid \""+Za+"\" function/method argument \""+i+"\" data type \""+typeof(Xa[i])+"\".  Expected data type was \""+Ya[i]+"\".");}};xmp.isDefined=function($a){return(typeof($a)!==xmp.UNDEFINED_TYPE);};xmp.fatalErrorCallback=null;xmp.handleFatalError=function(e){if(xmp.fatalErrorCallback!==null){xmp.fatalErrorCallback.call(e);}
else{xmp.showFatalErrorMessage(e.message);}};xmp.showFatalErrorMessage=function(ab){xmp.showMessage(ab);};xmp.showMessage=function(bb){window.alert(bb);};xmp.escapeText=function(db){var eb=db.replace(/\"/g,"\\\"");eb=eb.replace(/\'/g,"\\\'");return eb.replace(/\n/g,"\\n");};xmp.formatTimeString=function(fb){xmp.validateArguments(arguments,[xmp.NUMBER_TYPE],"formatTimeString");var gb="";if(fb<60){gb="00:";if(fb===0){gb+="00";}
else{if(fb<10){gb+="0"+fb;}
else{gb+=fb;}}}
else{var hb=Math.floor(fb/60);gb=((hb<10)?"0"+hb+":":hb+":");var ib=(fb-(hb*60));if(ib===0){gb+="00";}
else{if(ib<10){gb+="0"+ib;}
else{gb+=ib;}}}
return gb;};xmp.getSWFRoot=function(){return xmp.util.RootUrlProvider.getInstance().getRootUrl('swf')+'/';};xmp.makeSWFVersionedFileName=function(jb){return xmp.util.Version.makeFileVersionString(jb,'swf');};xmp.makeSWFPath=function(kb,lb){var mb=xmp.getSWFRoot();if(lb){mb+=xmp.makeSWFVersionedFileName(kb);}
else{mb+=(kb+'.swf');}
return mb;};xmp.getImageRoot=function(){return xmp.util.RootUrlProvider.getInstance().getRootUrl('image');};xmp.getBrowserVersion=function(){return xmp.util.internals.BrowserDetect.version;};xmp.isWindowsOS=function(){return(xmp.util.internals.BrowserDetect.OS===xmp.WINDOWS_PLATFORM);};xmp.isWindowsVistaOS=function(){return(navigator.userAgent.toLowerCase().indexOf('windows nt 6.0')!==-1);};xmp.isMacOSX=function(){return(navigator.userAgent.toLowerCase().indexOf("mac os x")>=0);};xmp.isMacOS=function(){return(xmp.util.internals.BrowserDetect.OS===xmp.MAC_PLATFORM);};xmp.isIEBrowser=function(){return(navigator.appName.indexOf(xmp.MICROSOFT_BROWSER)!==-1);};xmp.isFirefoxBrowser=function(){return(xmp.util.internals.BrowserDetect.browser===xmp.FIREFOX_BROWSER);};xmp.isSafariBrowser=function(){return(xmp.util.internals.BrowserDetect.browser===xmp.SAFARI_BROWSER);};xmp.isOperaBrowser=function(){return(navigator.appName.indexOf(xmp.OPERA_BROWSER)!==-1);};xmp.findDomElement=function(nb){var el=((xmp.isIEBrowser()||xmp.isOperaBrowser())?window[nb]:document[nb]);if(!el){el=document.getElementById(nb);}
return el;};xmp.getDomParent=function(ob){var pb=((xmp.isIEBrowser()||xmp.isOperaBrowser())?ob.parentElement:ob.parentNode);return pb;};xmp.getEventDomTarget=function(qb){var rb=(xmp.isIEBrowser()?qb.srcElement:qb.currentTarget);return rb;};xmp.findDomAncestorByTagName=function(sb,tb){while(sb!==null){if(sb.tagName.toLowerCase()===tb.toLowerCase()){return sb;}
sb=xmp.getDomParent(sb);}
return null;};xmp.insertDomChildBefore=function(ub,vb,wb){wb=(wb)?wb:null;if(xmp.isIEBrowser()&&(wb===null)){ub.insertBefore(vb);}
else{ub.insertBefore(vb,wb);}};xmp.addComboOption=function(xb,yb){if(xmp.isIEBrowser()){xb.add(yb);}
else{xb.add(yb,null);}};xmp.addDynamicStyle=function(zb,Ab){var Bb=false;try{if(typeof(document.styleSheets[0].addRule)!=='undefined'){document.styleSheets[0].addRule(zb,Ab);Bb=true;}
else if(typeof(document.styleSheets[0].insertRule)!=='undefined'){document.styleSheets[0].insertRule(zb+'  '+Ab,0);Bb=true;}}
catch(e){}
return Bb;};xmp.getPixelUnits=function(Cb){return parseInt(Cb,10)+"px";};xmp.DERIVE_CLASS=function(Db,Eb){function Inheritance(){}
Inheritance.prototype=Db.prototype;Eb.prototype=new Inheritance();Eb.prototype.constructor=Eb;Eb.ctor=Db;Eb.base=Db.prototype;};xmp.getQueryArg=function(Fb){xmp.getQueryArg._fault();var Gb=xmp.getQueryArg._map[Fb];return(Gb)?Gb:null;};xmp.getQueryArgOpt=function(Hb,Ib){var Jb=xmp.getQueryArg(Hb);return(Jb)?Jb:Ib;};xmp.getQueryArg._map=null;xmp.getQueryArg._fault=function(){if(xmp.getQueryArg._map!==null){return;}
xmp.getQueryArg._map={};var Kb=window.location.search.substring(1);var Lb=Kb.split("&");for(var i=0;i<Lb.length;i++){var Mb=Lb[i].indexOf('=');if(Mb>0){var Nb=Lb[i].substring(0,Mb);var Ob=decodeURIComponent(Lb[i].substring(Mb+1));xmp.getQueryArg._map[Nb]=Ob;}}};xmp.trueTypeOf=function(Pb){var Qb=typeof(Pb);if(Pb===null){Qb='null';}
try{switch(Qb){case'undefined':case'null':case'string':case'boolean':case'number':break;case'object':case'function':switch(Pb.constructor){case String:Qb='String';break;case Boolean:Qb='Boolean';break;case Number:Qb='Number';break;case Array:Qb='Array';break;case RegExp:Qb='RegExp';break;case Function:Qb='Function';break;default:var m=Pb.constructor.toString().match(/function\s*([^( ]+)\(/);if(m){Qb=m[1];}
break;}
break;default:break;}}
finally{Qb=Qb.substr(0,1).toUpperCase()+Qb.substr(1);return Qb;}};xmp.zeroPad=function(Rb,Sb){var Tb='';Tb+=Rb;var Ub=Tb.length;for(var i=Ub;i<Sb;i++){Tb=('0'+Tb);}
return Tb;};xmp.MapIterator=function(Vb,Wb){this._map=Vb;this._keys=(Wb)?xmp.MapIterator.extractKeysSorted(Vb):xmp.MapIterator.extractKeys(Vb);this._current=-1;this.first();};xmp.MapIterator.create=function(Xb){return new xmp.MapIterator(Xb,false);};xmp.MapIterator.createSorted=function(Yb){return new xmp.MapIterator(Yb,true);};xmp.MapIterator.extractKeys=function(Zb){var $b=[];if(!Zb){return $b;}
var ac='';var bc=(typeof(Zb.hasOwnProperty)!=='undefined');for(ac in Zb){if((!bc)||(bc&&Zb.hasOwnProperty(ac))){$b.push(ac);}}
return $b;};xmp.MapIterator.extractKeysSorted=function(cc){return xmp.MapIterator.extractKeys(cc).sort();};xmp.MapIterator.prototype.first=function(){this._current=0;};xmp.MapIterator.prototype.hasNext=function(){return(!this.isDone());};xmp.MapIterator.prototype.isDone=function(){return(this._current>=this._keys.length);};xmp.MapIterator.prototype.next=function(){this._current++;};xmp.MapIterator.prototype.currentKey=function(){this._checkDone();return this._keys[this._current];};xmp.MapIterator.prototype.currentValue=function(){return this._map[this.currentKey()];};xmp.MapIterator.prototype.updateCurrentValue=function(dc){this._map[this.currentKey()]=dc;};xmp.MapIterator.prototype._checkDone=function(){if(this.isDone()){throw new Error('MapIterator out of bounds.');}};xmp.MapIterator.prototype.getKeyArray=function(){return this._keys;};xmp.MapIterator.prototype.getValueArray=function(){var ec=[];for(var i=0;i<this._keys.length;i++){ec.push(this._map[this._keys[i]]);}
return ec;};xmp.UNKNOWN_TYPE="unknown";xmp.OBJECT_TYPE="object";xmp.STRING_TYPE="string";xmp.BOOLEAN_TYPE="boolean";xmp.NUMBER_TYPE="number";xmp.FUNCTION_TYPE="function";xmp.UNDEFINED_TYPE="undefined";xmp.TRUE="true";xmp.FALSE="false";xmp.MICROSOFT_BROWSER="Microsoft";xmp.OPERA_BROWSER="Opera";xmp.FIREFOX_BROWSER="Firefox";xmp.SAFARI_BROWSER="Safari";xmp.WINDOWS_PLATFORM="Windows";xmp.MAC_PLATFORM="Mac";xmp.UNKNOWN_ERROR="UnknownError";xmp.ROOT_URL="rootUrl";xmp.NO_DEFAULT_VALUE="";xmp.DELIMITER="|";xmp.ID_ATTRIBUTE="id";xmp.NAME_ATTRIBUTE="name";xmp.DEFAULT_TIMER_INTERVAL=100;xmp.SYNCH_UNIT="SynchUnit";xmp.CONNECTING="Connecting";xmp.CONNECTED="Connected";xmp.OPEN="Open";xmp.BUFFERING="Buffering";xmp.FIRST_FRAME_RENDERED="FirstFrameRendered";xmp.MONITOR_INTERVAL=1000;xmp.DISPLAY_NONE="none";xmp.DISPLAY_BLOCK="block";xmp.DISPLAY_INLINE="inline";xmp.CONTEXT="context";xmp.VOLUME="volume";xmp.MUTE="mute";xmp.BLACK_BACKGROUND_COLOR="#000000";xmp.NO_TIME_LIMIT=-1;xmp.IS_AVAILABLE="IsAvailable";xmp.GET_POSITION="GetPosition";xmp.GET_DURATION="GetDuration";xmp.GET_VOLUME="GetVolume";xmp.SET_VOLUME="SetVolume";xmp.GET_MUTE="GetMute";xmp.SET_MUTE="SetMute";xmp.FULLSCREEN="Fullscreen";xmp.GET_FULLSCREEN="GetFullscreen";xmp.SET_FULLSCREEN="SetFullscreen";xmp.GET_BUFFERING_PROGRESS="GetBufferingProgress";xmp.TYPE="type";xmp.ON_DEMAND_STREAMING_MODE="vod";xmp.LIVE_STREAMING_MODE="live";xmp.CONTROL_STREAMING_MODE="control";xmp.AD_STREAMING_MODE="ad";xmp.WIDTH="width";xmp.HEIGHT="height";xmp.MT_PLAYER_BOOTSTRAP="bootstrap";xmp.MT_PLAYER_PLAYLIST_ENDED="playlist_ended";xmp.createNamespace("xmp.net");xmp.net.AbstractTransport=function(fc,gc,hc,ic,jc){this._requestId=fc;this._loadId=gc;this._callback=hc;this._cfg=ic;this._contentType=jc;this._response=new xmp.net.AjaxResponse(gc);this._timer=null;this._manager=xmp.net.AjaxRequestManager.getInstance();this._response.setFullUrl(this._cfg.rootUrl+this._response.getId());};xmp.net.AbstractTransport.prototype.getRequestId=function(){return this._requestId;};xmp.net.AbstractTransport.prototype.getLoadId=function(){return this._loadId;};xmp.net.AbstractTransport.prototype.getResponse=function(){return this._response;};xmp.net.AbstractTransport.prototype.getCallback=function(){return this._callback;};xmp.net.AbstractTransport.prototype.getConfiguration=function(){return this._cfg;};xmp.net.AbstractTransport.prototype.getContentType=function(){return this._contentType;};xmp.net.AbstractTransport.prototype.setLoadedData=function(kc){throw new Error("Not supported.");};xmp.net.AbstractTransport.prototype.request=function(lc,mc){throw new Error("Must override.");};xmp.net.AbstractTransport.prototype.makeReport=function(){var nc='';nc+=('Request ID: '+this.getRequestId()+', ');nc+=('Transport Type: '+xmp.net.TransportTypes.stringify(this.getConfiguration().transportType)+', ');nc+=('Load ID: '+this.getLoadId()+', ');nc+=('Root URL: '+this.getConfiguration().rootUrl+', ');nc+=('Content Type: '+xmp.net.ContentTypes.stringify(this.getContentType()));return nc;};xmp.net.AbstractTransport.prototype._getManager=function(){return this._manager;};xmp.net.AbstractTransport.prototype._handleTimeout=function(){throw new Error("Must override.");};xmp.net.AbstractTransport.prototype._startTimer=function(){if(this._timer){this._timer.start();}};xmp.net.AbstractTransport.prototype._stopTimer=function(){if(this._timer){this._timer.stop();}};xmp.net.AbstractTransport.prototype._checkAndCreateTimer=function(){if(this._timer){this._timer.stop();}
var oc=this.getConfiguration().timeout;if(oc!==-1){if(this._timer===null){this._timer=new xmp.util.Timer(this.getRequestId(),oc,1,new xmp.util.Callback(this.getRequestId(),this._handleTimer,this));}
return true;}
return false;};xmp.net.AbstractTransport.prototype._handleTimer=function(pc,qc){this._stopTimer();this._handleTimeout();};xmp.createNamespace("xmp.net");xmp.net.AbstractTagTransport=function(rc,sc,tc,uc,vc){xmp.net.AbstractTagTransport.ctor.call(this,rc,sc,tc,uc,vc);this._timedOut=false;};xmp.DERIVE_CLASS(xmp.net.AbstractTransport,xmp.net.AbstractTagTransport);xmp.net.AbstractTagTransport.prototype.setLoadedData=function(wc){this._completeResponse(wc);};xmp.net.AbstractTagTransport.prototype.request=function(xc,yc){try{this._timedOut=false;this._checkAndCreateTimer();var zc=this.getConfiguration().rootUrl+xc;if(yc!==null){throw new Error("Headers not supported");}
this._initTag(zc);this._startTimer();}
catch(e){this._finiTag();this._stopTimer();this.getResponse()._setError(e);this._getManager()._handleCompleteRequest(this);}};xmp.net.AbstractTagTransport.prototype._initTag=function(Ac){throw new Error("Must override this method!");};xmp.net.AbstractTagTransport.prototype._finiTag=function(){throw new Error("Must override this method!");};xmp.net.AbstractTagTransport.prototype._makeTagId=function(){throw new Error("Must override this method!");};xmp.net.AbstractTagTransport.prototype._getLogger=function(){throw new Error("Must override this method!");};xmp.net.AbstractTagTransport.prototype._completeResponse=function(Bc){try{this._stopTimer();if(this._timedOut){this._getLogger('Dropping data, request timed out.');return;}
if(this.getContentType()===xmp.net.ContentTypes.TEXT){if(typeof Bc!=='string'){throw new Error('Requested text but got data of type:'+(typeof Bc));}
this.getResponse()._setText(Bc);}
else if(this.getContentType()===xmp.net.ContentTypes.JSON){var Cc=null;if(typeof Bc==='string'){Cc=this._getManager()._parseJson(Bc);}
else if(typeof Bc==='object'&&Bc!==null){Cc=Bc;}
if(Cc!==null){this.getResponse()._setJsonObject(Cc);}
else{throw new Error('Requested JSON but got wrong data type:'+Bc);}}}
catch(e){this.getResponse()._setError(e);}
this._finiTag();this._getManager()._handleCompleteRequest(this);};xmp.net.AbstractTagTransport.prototype._handleTimeout=function(){this._timedOut=true;this.getResponse()._setTimedOut();this._finiTag();this._getManager()._handleCompleteRequest(this);};xmp.createNamespace("xmp.net");xmp.net.AdService=function(){this.p_AD_RESPONSE_EVENT="response";this.p_AD_ERROR_EVENT="error";this.p_initCallback={};this.p_responseCallback={};this.p_errorCallback={};this.p_requestTimeout=30000;this.p_FLASH_ADSERVICE_COMPONENT="AdServiceAdapter";this.p_FLASH_ADSERVICE_COMPONENT_NAME="xmpAdService";this.p_FLASH_ADSERVICE_COMPONENT_CONTAINER_NAME="xmpAdServiceContainer";this.p_FLASH_FABRIDGE_NAME="xmpAdServiceBridge";};xmp.net.AdService.p_singeltonInstance=null;xmp.net.AdService.i_getInstance=function(){if(xmp.net.AdService.p_singeltonInstance===null){xmp.net.AdService.p_singeltonInstance=new xmp.net.AdService();}
return xmp.net.AdService.p_singeltonInstance;};xmp.net.AdService.prototype.i_init=function(Dc,Ec){this.p_initCallback=Dc;if(Ec!==undefined){this.p_requestTimeout=Ec;}
this.p_createFlashAdService();xmp.FABridge.addInitializationCallback(this.p_FLASH_FABRIDGE_NAME,this.p_bridgeInitCallback);};xmp.net.AdService.prototype.p_createFlashAdService=function(){if(document.getElementById(this.p_FLASH_ADSERVICE_COMPONENT_CONTAINER_NAME)===null){var Fc=document.createElement("div");Fc.setAttribute(xmp.ID_ATTRIBUTE,this.p_FLASH_ADSERVICE_COMPONENT_CONTAINER_NAME);Fc.setAttribute(xmp.NAME_ATTRIBUTE,this.p_FLASH_ADSERVICE_COMPONENT_CONTAINER_NAME);xmp.insertDomChildBefore(document.body,Fc);var Gc=new SWFObject(this.p_makeSWFPath(),this.p_FLASH_ADSERVICE_COMPONENT_NAME,1,1,8,"#FFFFFF");Gc.addParam(xmp.ALLOW_SCRIPT_ACCESS,xmp.ALWAYS_ACCESS);Gc.addVariable('bridgeName',this.p_FLASH_FABRIDGE_NAME);Gc.write(this.p_FLASH_ADSERVICE_COMPONENT_CONTAINER_NAME);}};xmp.net.AdService.prototype.p_makeSWFPath=function(){return xmp.makeSWFPath(this.p_FLASH_ADSERVICE_COMPONENT,false);};xmp.net.AdService.prototype.i_setResponseCallback=function(Hc){this.p_responseCallback=Hc;};xmp.net.AdService.prototype.i_setErrorCallback=function(Ic){this.p_errorCallback=Ic;};xmp.net.AdService.prototype.p_bridgeInitCallback=function(){xmp.net.AdService.i_getInstance().p_setupBridge();};xmp.net.AdService.prototype.p_setupBridge=function(){this.p_flexApp=xmp.FABridge[this.p_FLASH_FABRIDGE_NAME].root();this.p_service=this.p_flexApp.createService(this.p_requestTimeout);this.p_service.addEventListener(this.p_AD_RESPONSE_EVENT,this.p_handleAdServiceResponse);this.p_service.addEventListener(this.p_AD_ERROR_EVENT,this.p_handleAdServiceError);this.p_initCallback.call();};xmp.net.AdService.prototype.p_handleAdServiceResponse=function(Jc){xmp.net.AdService.i_getInstance().p_responseCallback.call(Jc);};xmp.net.AdService.prototype.p_handleAdServiceError=function(Kc){xmp.net.AdService.i_getInstance().p_errorCallback.call(Kc);};xmp.net.AdService.prototype.i_createRequest=function(Lc,Mc,Nc,Oc,Pc){if(Mc===undefined){Mc="";}
if(Nc===undefined){Nc="";}
if(Oc===undefined){Oc=[];}
if(Pc===undefined){Pc="GET";}
var Qc=this.p_flexApp.createRequest(Lc,Mc,Nc,Oc,Pc);return Qc;};xmp.net.AdService.prototype.i_makeRequest=function(Rc){this.p_service.makeRequest(Rc);};xmp.createNamespace("xmp.net");xmp.net.AjaxRequestManager=function(){this._logger=new xmp.util.internals.CategoryLogger('AjaxRequestManager');this._loggerByTypeMap={};this._DEFAULT_TIMEOUT=30000;this._DEFAULT_TRANSPORT_TYPE=xmp.net.TransportTypes.stringify(xmp.net.TransportTypes.FLASH_XHR);this._DEFAULT_RETRIES=1;this._DEFAULT_WAIT_BETWEEN_RETRIES=0;this._DEFAULT_REQUEST_VERB='GET';this._requestIdCounter=0;this._requestMap={};};xmp.net.AjaxRequestManager.POST_FORM_TYPE='post_form';xmp.net.AjaxRequestManager._singeltonInstance=null;xmp.net.AjaxRequestManager.getInstance=function(){if(xmp.net.AjaxRequestManager._singeltonInstance===null){xmp.net.AjaxRequestManager._singeltonInstance=new xmp.net.AjaxRequestManager();}
return xmp.net.AjaxRequestManager._singeltonInstance;};xmp.net.AjaxRequestManager.prototype.init=function(Sc){xmp.net.FlashXhrTransportManager.getInstance().init(Sc);};xmp.net.AjaxRequestManager.handleLoaded=function(Tc,Uc){xmp.net.AjaxRequestManager.getInstance()._handleLoadedCore(Tc,Uc);};xmp.net.AjaxRequestManager.ping=function(Vc,Wc){var cb=new xmp.util.Callback('Ping',xmp.net.AjaxRequestManager._pingCallback,null);xmp.net.AjaxRequestManager.getInstance().request(Wc,cb,Vc,Wc,xmp.net.ContentTypes.PING,null);};xmp.net.AjaxRequestManager._pingCallback=function(Xc,Yc){};xmp.net.AjaxRequestManager.prototype.request=function(Zc,$c,ad,bd,cd,dd){var ok=xmp.isNonEmptyString(Zc)&&xmp.isNonEmptyString(ad)&&xmp.isNonEmptyString(bd);if(ok){ok=($c!==null)&&(typeof $c==='object');}
if(ok){cd=xmp.net.ContentTypes._calc(cd);ok=(cd!==xmp.net.ContentTypes.INVALID);}
if(ok){if(!dd){dd=null;}
ok=((dd===null)||(typeof dd==='object'));}
if(!ok){throw new xmp.util.internals.InvalidArgsError('Invalid arguments, please read documentation for xmp.net.AjaxRequestManager.prototype.request.');}
var ed=this._findConfiguration(ad);if(!ed){throw new Error('Could not find proper configuration for URL root type: '+ad);}
this._requestWithConfiguration(ed,Zc,$c,bd,cd,dd);};xmp.net.AjaxRequestManager.prototype._requestWithConfiguration=function(fd,gd,hd,jd,kd,ld){var md=this._createTransport(fd.transportType,gd,hd,fd,kd);this._requestMap[md.getRequestId()]=md;this._logRequestReport(md,jd,ld);md.request(jd,ld);};xmp.net.AjaxRequestManager.prototype._buildRequestReport=function(nd,od,pd){var qd='Making request = ';qd+=(nd.makeReport()+', ');qd+=('Relative URL: '+od+', ');qd+=('Request Headers: ');if(pd===null){qd+='NONE';}
else{for(var i=0;i<pd.length;i++){var rd=pd[i];qd+=(rd.name+' = '+rd.value);if(i!==(pd.length-1)){qd+=' & ';}}}
return qd;};xmp.net.AjaxRequestManager.prototype._createTransport=function(sd,td,ud,vd,wd){var xd=xmp.net.TransportTypes;var yd=xd._calc(sd);this._requestIdCounter++;var zd=this._requestIdCounter.toString();switch(yd){case xd.XHR:return new xmp.net.XhrTransport(zd,td,ud,vd,wd);case xd.IFRAME:return new xmp.net.IFrameTagTransport(zd,td,ud,vd,wd);case xd.SCRIPT:return new xmp.net.ScriptTagTransport(zd,td,ud,vd,wd);case xd.FLASH_XHR:return new xmp.net.FlashXhrTransport(zd,td,ud,vd,wd);case xd.MOCK:return new xmp.net.MockTransport(zd,td,ud,vd,wd);default:return null;}};xmp.net.AjaxRequestManager.prototype._parseJson=function(Ad){Ad=xmp.trimString(Ad);return this._parseJavaScript('('+Ad+')');};xmp.net.AjaxRequestManager.prototype._parseJavaScript=function(Bd){return eval(Bd);};xmp.net.AjaxRequestManager.prototype._handleCompleteRequest=function(Cd){var Dd=Cd.getRequestId();if(!this._requestMap[Dd]){this._logger.debug("Did not find transport: "+Dd);return;}
delete this._requestMap[Dd];try{if(Cd.getResponse().isError()){if(Cd.getResponse().isTimedOut()||(Cd.getResponse().isCriticalOrFatalError())){var Ed=xmp.CriticalException.createCriticalException(xmp.XmpErrorCodes.CRITICAL_UNSPECIFIED_AJAX_ERROR,'ARM',this._buildReponseReport(Cd));this._logger.debug('ARM transport timeout',Ed);}
else{this._logReponseReport(Cd);}}
else{this._logReponseReport(Cd);}
Cd.getCallback().call(Cd.getResponse());}
catch(e){this._logger.trace("Error while calling request callback.",e);}};xmp.net.AjaxRequestManager.prototype._getLoggerByType=function(Fd){var Gd=this._loggerByTypeMap[Fd];if(!Gd){Gd=new xmp.util.internals.CategoryLogger('AjaxRequestManager'+'_'+Fd);this._loggerByTypeMap[Fd]=Gd;}
return Gd;};xmp.net.AjaxRequestManager.prototype._logRequestReport=function(Hd,Id,Jd){var Kd=this._getLoggerByType(Hd.getConfiguration().rootUrlType);if(Kd.isDebugEnabled()){Kd.debug(this._buildRequestReport(Hd,Id,Jd));}};xmp.net.AjaxRequestManager.prototype._logReponseReport=function(Ld){var Md=this._getLoggerByType(Ld.getConfiguration().rootUrlType);if(Md.isDebugEnabled()){Md.debug(this._buildReponseReport(Ld));}};xmp.net.AjaxRequestManager.prototype._buildReponseReport=function(Nd){var Od='Request complete (Request ID: '+Nd.getRequestId()+'), response = '+Nd.getResponse().makeReport();return Od;};xmp.net.AjaxRequestManager.prototype._handleLoadedCore=function(Pd,Qd){try{for(var Rd=xmp.MapIterator.create(this._requestMap);Rd.hasNext();Rd.next()){var Sd=Rd.currentValue();if(Sd.getLoadId()===Pd){Sd.setLoadedData(Qd);return;}}
this._logger.info("Dropping loaded data, could not find transport for: "+Pd);}
catch(e){this._logger.warn("Error while calling _handleLoadedCore.",e);}};xmp.net.AjaxRequestManager.prototype._findConfiguration=function(Td){var Ud=xmp.util.RootUrlProvider.getInstance().getRootUrl(Td);if(Ud.length===0){return null;}
var Vd=xmp.util.RootUrlProvider.getInstance().getRootUrlNode(Td);var Wd=xmp.net.TransportTypes.fromString(Vd.getString('transportType',this._DEFAULT_TRANSPORT_TYPE));if(Wd===xmp.net.TransportTypes.INVALID){return null;}
var Xd={};Xd.rootUrl=Ud;Xd.rootUrlType=Td;Xd.transportType=Wd;Xd.timeout=Vd.getInt('timeout',this._DEFAULT_TIMEOUT);Xd.retries=Vd.getInt('retries',this._DEFAULT_RETRIES);Xd.waitBetweenRetries=Vd.getInt('waitBetweenRetries',this._DEFAULT_WAIT_BETWEEN_RETRIES);Xd.requestVerb=Vd.getString('requestVerb',this._DEFAULT_REQUEST_VERB);return Xd;};xmp.createNamespace("xmp.net");xmp.net.AjaxResponse=function(id){this._id=id;this._fullUrl="";this._errorObject=null;this._jsonObject=null;this._text='';this._timedOutError=false;this._isCriticalOrFatalError=false;};xmp.net.AjaxResponse.prototype.getId=function(){return this._id;};xmp.net.AjaxResponse.prototype.getFullUrl=function(){return this._fullUrl;};xmp.net.AjaxResponse.prototype.setFullUrl=function(Yd){this._fullUrl=Yd;};xmp.net.AjaxResponse.prototype.isError=function(){return(this._errorObject!==null);};xmp.net.AjaxResponse.prototype.isTimedOut=function(){return this._timedOutError;};xmp.net.AjaxResponse.prototype.isCriticalOrFatalError=function(){return this._isCriticalOrFatalError;};xmp.net.AjaxResponse.prototype.getErrorObject=function(){return this._errorObject;};xmp.net.AjaxResponse.prototype.getJsonObject=function(){this._accessGuard();return this._jsonObject;};xmp.net.AjaxResponse.prototype.getText=function(){this._accessGuard();return this._text;};xmp.net.AjaxResponse.prototype.getErrorMessage=function(){if(this.isError()){return xmp.extractErrorMessage(this.getErrorObject());}
else{return'No Error';}};xmp.net.AjaxResponse.prototype._accessGuard=function(){if(this.isError()){var ex=new xmp.net.AjaxResponseException('Tried to access AjaxResponse while in an error state, see nested exception.');ex.message+=('\nNESTED ERROR: '+xmp.extractErrorMessage(this._errorObject));throw ex;}};xmp.net.AjaxResponse.prototype._setError=function(Zd){this._setErrorCore(Zd);};xmp.net.AjaxResponse.prototype._setTimedOut=function(){this._timedOutError=true;this._setErrorCore(new Error("AjaxResponse: Request timed out."));};xmp.net.AjaxResponse.prototype._setJsonObject=function($d){this._jsonObject=$d;};xmp.net.AjaxResponse.prototype._setText=function(ae){this._text=ae;};xmp.net.AjaxResponse.prototype._setErrorCore=function(be){this._isCriticalOrFatalError=false;if(be instanceof Error){this._errorObject=new xmp.net.AjaxResponseException('AjaxResponse, see nested exception');this._errorObject.message+=('\nNESTED ERROR: '+xmp.extractErrorMessage(be));if((be instanceof xmp.FatalException)||(be instanceof xmp.CriticalException)){this._isCriticalOrFatalError=true;}}
else{this._errorObject=new xmp.net.AjaxResponseException("AjaxResponse: UNKNOWN ERROR");}};xmp.net.AjaxResponse.prototype.makeReport=function(){var ce='';ce+=('Response ID: '+this.getFullUrl()+'\n');if(this.isError()){ce+=('Response Text: '+this._text+'\n');ce+=('Response JSON: null\n');ce+=('ERROR Message: '+this.getErrorMessage());}
else{ce+=('Response Text: '+this.getText()+'\n');ce+=('Response JSON: '+((this.getJsonObject()===null)?'null':'not null')+'\n');ce+='SUCCESS';}
return ce;};xmp.net.AjaxResponseException=function(de){this.name="AjaxResponseException";this.message=de;};xmp.DERIVE_CLASS(Error,xmp.net.AjaxResponseException);xmp.createNamespace("xmp.net");xmp.net.ContentTypes=function(){};xmp.net.ContentTypes.INVALID=-1;xmp.net.ContentTypes.TEXT=0;xmp.net.ContentTypes.JSON=1;xmp.net.ContentTypes.PING=2;xmp.net.ContentTypes._BEGIN=-1;xmp.net.ContentTypes._END=2;xmp.net.ContentTypes._calc=function(ee){var fe=xmp.net.ContentTypes;if((typeof ee!=='number')||(ee<fe._BEGIN)||(ee>fe._END)){return fe._BEGIN;}
return ee;};xmp.net.ContentTypes.stringify=function(ge){var he=xmp.net.ContentTypes;var ie=he._calc(ge);switch(ie){case he.INVALID:return'invalid';case he.TEXT:return'text';case he.JSON:return'json';case he.PING:return'ping';default:return'invalid';}};xmp.net.ContentTypes.fromString=function(je){var ke=xmp.net.ContentTypes;switch(je){case'invalid':return ke.INVALID;case'text':return ke.TEXT;case'json':return ke.JSON;case'ping':return ke.PING;default:return ke.INVALID;}};xmp.createNamespace("xmp.net");xmp.net.FlashXhrTransport=function(le,me,ne,oe,pe){xmp.net.FlashXhrTransport.ctor.call(this,le,me,ne,oe,pe);this._FLASH_XML_REQUEST_MIME_TYPE="text/html";this._handle="";this._url="";this._flashXhrManager=xmp.net.FlashXhrTransportManager.getInstance();this._isIEWin=(xmp.isIEBrowser()&&(xmp.util.internals.BrowserDetect.OS===xmp.WINDOWS_PLATFORM));this._requestHeaderArray=null;};xmp.DERIVE_CLASS(xmp.net.AbstractTransport,xmp.net.FlashXhrTransport);xmp.net.FlashXhrTransport.prototype._getHandle=function(){return this._handle;};xmp.net.FlashXhrTransport.prototype._getUrl=function(){return this._url;};xmp.net.FlashXhrTransport.prototype._getRequestVerb=function(){return this.getConfiguration().requestVerb;};xmp.net.FlashXhrTransport.prototype._getRequestMimeType=function(){return this._FLASH_XML_REQUEST_MIME_TYPE;};xmp.net.FlashXhrTransport.prototype._getFlashXhrManager=function(){return this._flashXhrManager;};xmp.net.FlashXhrTransport.prototype._getRequestHeaders=function(){return this._requestHeaderArray;};xmp.net.FlashXhrTransport.prototype.request=function(qe,se){try{this._requestHeaderArray=se;this._url=this.getConfiguration().rootUrl+qe;this._handle=this._getFlashXhrManager().getXhrComponentName()+this.getRequestId();this._getFlashXhrManager().open(this);}
catch(e){this.handleError(e.name,e.message);}};xmp.net.FlashXhrTransport.prototype.doRequest=function(){this._checkAndCreateTimer();this._getFlashXhrManager().doRequest(this);this._startTimer();};xmp.net.FlashXhrTransport.prototype.handleData=function(te){this._stopTimer();this.getResponse()._setText(te);if(this.getContentType()===xmp.net.ContentTypes.JSON){var ue=this._getManager()._parseJson(te);this.getResponse()._setJsonObject(ue);}
this._getFlashXhrManager().close(this);this._getManager()._handleCompleteRequest(this);};xmp.net.FlashXhrTransport.prototype.handleError=function(ve,we){this._stopTimer();var xe="Type:  "+ve+"\nDescription:  "+we;this._getFlashXhrManager().close(this);var ye=this._extractErrorCode(we);var ze=null;if(this._isIEWin&&(ye===0)){ze=xmp.CriticalException.createCriticalException(xmp.XmpErrorCodes.CRITICAL_UNSPECIFIED_AJAX_ERROR,'FlashXhrTransport',we);}
else{ze=new Error(xe);}
this.getResponse()._setError(ze);this._getManager()._handleCompleteRequest(this);};xmp.net.FlashXhrTransport.prototype._extractErrorCode=function(Ae){var re=/XML\/HTTP Error:\s{2}(\d{1,6}) \w*/;var Be=Ae.match(re);if(Be!==null&&Be.length>1){return parseInt(Be[1],0);}
return-1;};xmp.net.FlashXhrTransport.prototype._handleTimeout=function(){this._getFlashXhrManager().close(this);this.getResponse()._setTimedOut();this._getManager()._handleCompleteRequest(this);};xmp.createNamespace("xmp.net");xmp.net.FlashXhrTransportManager=function(){this._logger=new xmp.util.internals.CategoryLogger('FlashXhrTransportManager');this._CREATION_TIMEOUT=5000;this._FLASH_DATA_CALLBACK="dataCallback";this._FLASH_XML_HTTP_REQUEST_COMPONENT="XMLHttpRequest";this._FLASH_XML_HTTP_REQUEST_COMPONENT_NAME="FlashXMLHttpRequest";this._FLASH_XML_HTTP_REQUEST_COMPONENT_CONTAINER_NAME="FlashXMLHttpRequestContainer";this._initializationState='None';this._FlashXmlHttpRequestRegistry={};this._create_cb=null;this._transitionInitializationState('Uninitialized');};xmp.net.FlashXhrTransportManager._singeltonInstance=null;xmp.net.FlashXhrTransportManager.getInstance=function(){if(xmp.net.FlashXhrTransportManager._singeltonInstance===null){xmp.net.FlashXhrTransportManager._singeltonInstance=new xmp.net.FlashXhrTransportManager();}
return xmp.net.FlashXhrTransportManager._singeltonInstance;};xmp.net.FlashXhrTransportManager.prototype.init=function(Ce){try{if(this._getInitializationState()!=='Uninitialized'){throw new Error('FlashXhrTransportManager - Already started initialization.');}
this._transitionInitializationState('Before creation');this.createFlashXMLHttpRequest();this._transitionInitializationState('After creation');this._create_cb=Ce;var De=new xmp.util.Callback('FlashXhrTransportManager_init',this._handleInitTimeout,this);De.callAsynchEx(this._CREATION_TIMEOUT,[]);}
catch(ex){Ce.call(new Error(xmp.extractErrorMessage(ex)));}};xmp.net.FlashXhrTransportManager.prototype._handleInitTimeout=function(){var Ee=this._create_cb;this._create_cb=null;if(Ee===null){return;}
var Fe=new xmp.baseplayer.ApplicationError(null,'badInitialFlashObject',null,[{label:"Url",text:this._makeSWFPath()}]);this._logger.warn(Fe.message,Fe);Ee.call(xmp.FatalException.createFatalException(xmp.XmpErrorCodes.FATAL_PLUGIN_INIT,'FlashXhrTransportManager','timed out intializing flash XHR SWF'));};xmp.net.FlashXhrTransportManager.prototype.getXhrComponentName=function(){return this._FLASH_XML_HTTP_REQUEST_COMPONENT_NAME;};xmp.net.FlashXhrTransportManager.prototype._getXhrComponent=function(){return document.getElementById(this.getXhrComponentName());};xmp.net.FlashXhrTransportManager.prototype.doRequest=function(Ge){this._enforceReadyState();var He=this._getXhrComponent();He.xhrOpen(Ge._getHandle(),Ge._getRequestVerb(),Ge._getRequestMimeType());if(Ge.getContentType()===xmp.net.ContentTypes.PING){He.xhrSetResultData(Ge._getHandle(),'ping');}
var Ie=Ge._getRequestHeaders();if(Ie){for(var i=0;i<Ie.length;i++){var Je=Ie[i];var Ke=Je.name;if(xmp.isNonEmptyString(Je.type)&&(Je.type===xmp.net.AjaxRequestManager.POST_FORM_TYPE)){Ke='_POST_FORM_VAR_:'+Ke;}
He.xhrAddRequestHeader(Ge._getHandle(),Ke,Je.value);}}
He.xhrSend(Ge._getHandle(),Ge._getUrl());};xmp.net.FlashXhrTransportManager.prototype._makeSWFPath=function(){return xmp.makeSWFPath(this._FLASH_XML_HTTP_REQUEST_COMPONENT,true);};xmp.net.FlashXhrTransportManager.prototype.createFlashXMLHttpRequest=function(){if(document.getElementById(this._FLASH_XML_HTTP_REQUEST_COMPONENT_CONTAINER_NAME)===null){var Le=document.createElement("div");Le.setAttribute(xmp.ID_ATTRIBUTE,this._FLASH_XML_HTTP_REQUEST_COMPONENT_CONTAINER_NAME);Le.setAttribute(xmp.NAME_ATTRIBUTE,this._FLASH_XML_HTTP_REQUEST_COMPONENT_CONTAINER_NAME);xmp.insertDomChildBefore(document.body,Le);var Me=new SWFObject(this._makeSWFPath(),this.getXhrComponentName(),1,1,8,"#FFFFFF");Me.addParam(xmp.ALLOW_SCRIPT_ACCESS,xmp.ALWAYS_ACCESS);Me.addVariable(xmp.CONTEXT,'create_handle');var Ne='xmp.net.FlashXhrTransportManager.getInstance().';Me.addVariable(xmp.FLASH_INITIALIZATION_CALLBACK,Ne+'onInit');Me.addVariable(this._FLASH_DATA_CALLBACK,Ne+'onData');Me.addVariable(xmp.FLASH_ERROR_CALLBACK,Ne+'onError');Me.write(this._FLASH_XML_HTTP_REQUEST_COMPONENT_CONTAINER_NAME);xmp.util.FlashUtility.buildFSCommandScript(Le,this.getXhrComponentName(),Ne+"_handleFSCommand(command, args);");}};xmp.net.FlashXhrTransportManager.prototype.handleInit=function(){this._logger.debug('In handleInit.');if(this._getInitializationState()!=='After creation'){if(this._getInitializationState()!=='Relaying handleInit'){var Oe=new xmp.util.Callback('FlashXhrTransportManager_relay_handleInit',this.handleInit,this);Oe.callAsynch([]);this._transitionInitializationState('Relaying handleInit');}
return;}
var Pe=this._create_cb;this._create_cb=null;if(Pe===null){this.logger.critical("Unexpected: creation callback is null.");return;}
this._transitionInitializationState('Ready');Pe.call('Ready');};xmp.net.FlashXhrTransportManager.prototype.close=function(Qe){this._getXhrComponent().xhrClose(Qe._getHandle());this._FlashXmlHttpRequestRegistry[Qe._getHandle()]=null;delete this._FlashXmlHttpRequestRegistry[Qe._getHandle()];};xmp.net.FlashXhrTransportManager.prototype.open=function(Re){this._enforceReadyState();this._FlashXmlHttpRequestRegistry[Re._getHandle()]=Re;Re.doRequest();};xmp.net.FlashXhrTransportManager.prototype._handleFSCommand=function(Se,Te){try{Se=xmp.util.FlashUtility.normalizeCommand(Se);var Ue='xmp.net.FlashXhrTransportManager.getInstance().';var Ve=xmp.util.FlashUtility;var We=null;switch(Se){case Ue+'onInit':We=Ve.splitFSCommandData(Te,2);this.onInit(We[0],We[1]);break;case Ue+'onData':We=Ve.splitFSCommandData(Te,2);this.onData(We[0],We[1]);break;case Ue+'onError':We=Ve.splitFSCommandData(Te,3);this.onError(We[0],We[1],We[2]);break;default:this._logger.warn('Unrecognized FSCommand: '+Se);break;}}
catch(e){this._logger.warn('Error executing FSCommand: '+Se,e);}};xmp.net.FlashXhrTransportManager.prototype.onInit=function(Xe,Ye){try{this.handleInit();}
catch(e){this._handleError(e,true);}};xmp.net.FlashXhrTransportManager.prototype.onData=function(Ze,$e){try{var af=this._getTransport(Ze);try{af.handleData(xmp.util.FlashUtility.externalInterfaceDecode($e));}
catch(e2){this._handleTransportError(af,e2,true);}}
catch(e){this._handleError(e,false);}};xmp.net.FlashXhrTransportManager.prototype.onError=function(bf,cf,df){try{var ef=this._getTransport(bf);try{ef.handleError(cf,df);}
catch(e2){this._handleTransportError(ef,e2,false);}}
catch(e){this._handleError(e,false);}};xmp.net.FlashXhrTransportManager.prototype._getTransport=function(ff){var gf=this._findTransport(ff);if(!gf){throw new Error("Could not get transport for handle: "+ff);}
return gf;};xmp.net.FlashXhrTransportManager.prototype._findTransport=function(hf){var jf=this._FlashXmlHttpRequestRegistry[hf];return(jf)?jf:null;};xmp.net.FlashXhrTransportManager.prototype._handleError=function(kf,lf){if(lf){this._logger.critical("Error in FlashXhrTransportManager",kf);}
else{this._logger.warn("Error in FlashXhrTransportManager",kf);}};xmp.net.FlashXhrTransportManager.prototype._handleTransportError=function(mf,nf,of){try{if(of){mf.handleError(nf.name,nf.message);}
else{this._handleError(nf,false);this.close(mf);}}
catch(e){var e2=new Error("Error calling _handleTransportError: "+xmp.extractErrorMessage(e)+"\nOriginal error: "+xmp.extractErrorMessage(nf));this._handleError(e2,true);}};xmp.net.FlashXhrTransportManager.prototype._transitionInitializationState=function(pf){this._logger.debug('Transition init state from "'+this._initializationState+'" to "'+pf+'".');this._initializationState=pf;};xmp.net.FlashXhrTransportManager.prototype._getInitializationState=function(){return this._initializationState;};xmp.net.FlashXhrTransportManager.prototype._isInReadyState=function(){return(this._getInitializationState()==='Ready');};xmp.net.FlashXhrTransportManager.prototype._enforceReadyState=function(){if(!this._isInReadyState()){throw new Error("FlashXhrTransportManager is not iniitialized!");}};xmp.createNamespace("xmp.net");xmp.net.IFrameTagTransport=function(qf,rf,sf,tf,uf){xmp.net.IFrameTagTransport.ctor.call(this,qf,rf,sf,tf,uf);this._logger=new xmp.util.internals.CategoryLogger('IFrameTagTransport');};xmp.DERIVE_CLASS(xmp.net.AbstractTagTransport,xmp.net.IFrameTagTransport);xmp.net.IFrameTagTransport.prototype._initTag=function(vf){var wf=document.createElement('iframe');wf.id=this._makeTagId();document.body.appendChild(wf);wf.src=vf;};xmp.net.IFrameTagTransport.prototype._finiTag=function(){try{var xf=document.getElementById(this._makeTagId());if(xf){document.body.removeChild(xf);}}
catch(e){this._logger.warn('Error removing tag with ID: '+this._makeTagId(),e);}};xmp.net.IFrameTagTransport.prototype._makeTagId=function(){return'IFrameTagTransport'+'_'+this.getRequestId();};xmp.net.IFrameTagTransport.prototype._getLogger=function(){return this._logger;};xmp.createNamespace("xmp.net");xmp.net.MockTransport=function(yf,zf,Af,Bf,Cf){xmp.net.MockTransport.ctor.call(this,yf,zf,Af,Bf,Cf);};xmp.DERIVE_CLASS(xmp.net.AbstractTransport,xmp.net.MockTransport);xmp.net.MockTransport.prototype.request=function(Df,Ef){this._url=Df;this.doRequest();};xmp.net.MockTransport.prototype.doRequest=function(){this._checkAndCreateTimer();this._startTimer();if(this._networkDelayTimer){this._networkDelayTimer.stop();}
this._dataItem=xmp.net.MockTransportData.getInstance().getItem(this._url);var Ff=this._dataItem?this._dataItem.delay:200;this._networkDelayTimer=new xmp.util.Timer(this.getRequestId(),Ff,1,new xmp.util.Callback(this.getRequestId(),this._handleRequest,this));this._networkDelayTimer.start();};xmp.net.MockTransport.prototype._handleRequest=function(Gf,Hf){Hf.stop();try{if(this._dataItem){this.handleData(this._dataItem.data);}
else{this.handleError("MockTransportError","No mock data found for "+this._url);}}
catch(e){this.handleError(e.nam,e.message);}};xmp.net.MockTransport.prototype.handleData=function(If){this._stopTimer();var Jf=null;var Kf=null;if(typeof If==='string'){Jf=If;}
else{Kf=If;Jf="";}
this.getResponse()._setText(Jf);if(this.getContentType()===xmp.net.ContentTypes.JSON){if(!Kf){Kf=this._getManager()._parseJson(Jf);}
this.getResponse()._setJsonObject(Kf);}
this._getManager()._handleCompleteRequest(this);};xmp.net.MockTransport.prototype.handleError=function(Lf,Mf){this._stopTimer();var Nf="Type:  "+Lf+"\nDescription:  "+Mf;this.getResponse()._setError(new Error(Nf));this._getManager()._handleCompleteRequest(this);};xmp.net.MockTransport.prototype._handleTimeout=function(){this.getResponse()._setTimedOut();this._getManager()._handleCompleteRequest(this);};xmp.createNamespace("xmp.net");xmp.net.MockTransportData=function(){this._logger=new xmp.util.internals.CategoryLogger('MockTransportData');this._dataMap={};};xmp.net.MockTransportData._singeltonInstance=null;xmp.net.MockTransportData.getInstance=function(){if(xmp.net.MockTransportData._singeltonInstance===null){xmp.net.MockTransportData._singeltonInstance=new xmp.net.MockTransportData();}
return xmp.net.MockTransportData._singeltonInstance;};xmp.net.MockTransportData.prototype.setDataMap=function(Of){this._dataMap=Of;};xmp.net.MockTransportData.prototype.getDataMap=function(){return this._dataMap;};xmp.net.MockTransportData.prototype.setItem=function(Pf,Qf){var Rf=this._transformUrl(Pf);this._dataMap[Rf]=Qf;};xmp.net.MockTransportData.prototype.getItem=function(Sf){this._logger.info("MockTransportData.getData for "+Sf);var Tf=this._transformUrl(Sf);return this._dataMap[Tf];};xmp.net.MockTransportData.prototype._transformUrl=function(Uf){var Vf=this._hasTileId(Uf)?this._removeTileId(Uf):Uf;return Vf;};xmp.net.MockTransportData.prototype._hasTileId=function(Wf){return Wf.match(/tile=\d+/);};xmp.net.MockTransportData.prototype._removeTileId=function(Xf){var Yf=Xf.replace(/tile=\d+&/,'');if(Yf===Xf){Yf=Xf.replace(/&tile=\d+/,'');}
return Yf;};xmp.createNamespace("xmp.net");xmp.net.ScriptTagTransport=function(Zf,$f,ag,bg,cg){xmp.net.ScriptTagTransport.ctor.call(this,Zf,$f,ag,bg,cg);this._logger=new xmp.util.internals.CategoryLogger('ScriptTagTransport');};xmp.DERIVE_CLASS(xmp.net.AbstractTagTransport,xmp.net.ScriptTagTransport);xmp.net.ScriptTagTransport.prototype._initTag=function(dg){var eg=document.createElement('script');eg.id=this._makeTagId();document.body.appendChild(eg);eg.src=dg;};xmp.net.ScriptTagTransport.prototype._finiTag=function(){try{var fg=document.getElementById(this._makeTagId());if(fg){document.body.removeChild(fg);}}
catch(e){this._logger.warn('Error removing tag with ID: '+this._makeTagId(),e);}};xmp.net.ScriptTagTransport.prototype._makeTagId=function(){return'ScriptTagTransport'+'_'+this.getRequestId();};xmp.net.ScriptTagTransport.prototype._getLogger=function(){return this._logger;};xmp.createNamespace("xmp.net");xmp.net.TransportTypes=function(){};xmp.net.TransportTypes.INVALID=-1;xmp.net.TransportTypes.XHR=0;xmp.net.TransportTypes.IFRAME=1;xmp.net.TransportTypes.SCRIPT=2;xmp.net.TransportTypes.FLASH_XHR=3;xmp.net.TransportTypes.MOCK=4;xmp.net.TransportTypes._BEGIN=-1;xmp.net.TransportTypes._END=4;xmp.net.TransportTypes._calc=function(gg){var hg=xmp.net.TransportTypes;if((typeof gg!=='number')||(gg<hg._BEGIN)||(gg>hg._END)){return hg._BEGIN;}
return gg;};xmp.net.TransportTypes.stringify=function(ig){var jg=xmp.net.TransportTypes;var kg=jg._calc(ig);switch(kg){case jg.INVALID:return'invalid';case jg.XHR:return'xhr';case jg.IFRAME:return'iframe';case jg.SCRIPT:return'script';case jg.FLASH_XHR:return'flash';case jg.MOCK:return'mock';default:return'invalid';}};xmp.net.TransportTypes.fromString=function(lg){var mg=xmp.net.TransportTypes;switch(lg){case'invalid':return mg.INVALID;case'xhr':return mg.XHR;case'iframe':return mg.IFRAME;case'script':return mg.SCRIPT;case'flash':return mg.FLASH_XHR;case'mock':return mg.MOCK;default:return mg.INVALID;}};xmp.createNamespace("xmp.net");xmp.net.XhrTransport=function(ng,og,pg,qg,rg){xmp.net.XhrTransport.ctor.call(this,ng,og,pg,qg,rg);this._requestObject=this._createRequestObject();var sg=this;this._requestObject.onreadystatechange=function(){sg._handleStateChange();};};xmp.DERIVE_CLASS(xmp.net.AbstractTransport,xmp.net.XhrTransport);xmp.net.XhrTransport.prototype.request=function(tg,ug){try{this._checkAndCreateTimer();var vg=this.getConfiguration().rootUrl+tg;this._requestObject.open('GET',vg);if(ug!==null){for(var i=0;i<ug.length;i++){var wg=ug[i];this._requestObject.setRequestHeader(wg.name,wg.value);}}
this._requestObject.send(null);this._startTimer();}
catch(e){this._stopTimer();this.getResponse()._setError(e);this._getManager()._handleCompleteRequest(this);}};xmp.net.XhrTransport.prototype._completeResponse=function(){try{this._stopTimer();if(this._requestObject.status!==200){throw new Error('Status: '+this._requestObject.status);}
var xg=this._requestObject.responseText;this.getResponse()._setText(xg);if(this.getContentType()===xmp.net.ContentTypes.JSON){var yg=this._getManager()._parseJson(xg);this.getResponse()._setJsonObject(yg);}}
catch(e){this.getResponse()._setError(e);}
this._getManager()._handleCompleteRequest(this);};xmp.net.XhrTransport.prototype._handleTimeout=function(){this._requestObject.abort();this.getResponse()._setTimedOut();this._getManager()._handleCompleteRequest(this);};xmp.net.XhrTransport.prototype._handleStateChange=function(){if(this._requestObject.readyState===4){this._completeResponse();}};xmp.net.XhrTransport._factories=[function(){return new XMLHttpRequest();},function(){return new ActiveXObject('Msxml2.XMLHTTP');},function(){return new ActiveXObject('Microsoft.XMLHTTP');}];xmp.net.XhrTransport._factory=null;xmp.net.XhrTransport.prototype._createRequestObject=function(){if(xmp.net.XhrTransport._factory!==null){return xmp.net.XhrTransport._factory();}
for(var i=0;i<xmp.net.XhrTransport._factories.length;i++){try{var zg=xmp.net.XhrTransport._factories[i];var Ag=zg();if(Ag!==null){xmp.net.XhrTransport._factory=zg;return Ag;}}
catch(e){continue;}}
xmp.net.XhrTransport._factory=function(){throw new Error('XMLHttpRequest not supported.');};xmp.net.XhrTransport._factory();return null;};

/*
Copyright 2006 Adobe Systems Incorporated

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.


THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

// This verion modified for XMP. Uses xmp namespace.
var xmp = xmp || {};

/*
 * The Bridge class, responsible for navigating AS instances
 */
xmp.FABridge = function(target,bridgeName)
{
    this.target = target;
    this.remoteTypeCache = {};
    this.remoteInstanceCache = {};
    this.remoteFunctionCache = {};
    this.localFunctionCache = {};
    this.bridgeID = xmp.FABridge.nextBridgeID++;
    this.name = bridgeName;
    this.nextLocalFuncID = 0;
    xmp.FABridge.instances[this.name] = this;
    xmp.FABridge.idMap[this.bridgeID] = this;

    return this;
}

// type codes for packed values
xmp.FABridge.TYPE_ASINSTANCE =  1;
xmp.FABridge.TYPE_ASFUNCTION =  2;

xmp.FABridge.TYPE_JSFUNCTION =  3;
xmp.FABridge.TYPE_ANONYMOUS =   4;

xmp.FABridge.initCallbacks = {};
xmp.FABridge.userTypes = {};

xmp.FABridge.addToUserTypes = function()
{
	for (var i = 0; i < arguments.length; i++)
	{
		xmp.FABridge.userTypes[arguments[i]] = {
			'typeName': arguments[i], 
			'enriched': false
		};
	}
}

xmp.FABridge.argsToArray = function(args)
{
    var result = [];
    for (var i = 0; i < args.length; i++)
    {
        result[i] = args[i];
    }
    return result;
}

xmp.FABridge.instanceFactory = function(objID)
{
    this.fb_instance_id = objID;
    return this;
}

xmp.FABridge__invokeJSFunction = function(args)
{  
    var funcID = args[0];
    var throughArgs = args.concat();//xmp.FABridge.argsToArray(arguments);
    throughArgs.shift();
   
    var bridge = xmp.FABridge.extractBridgeFromID(funcID);
    return bridge.invokeLocalFunction(funcID, throughArgs);
}

xmp.FABridge.addInitializationCallback = function(bridgeName, callback)
{
    var inst = xmp.FABridge.instances[bridgeName];
    if (inst != undefined)
    {
        callback.call(inst);
        return;
    }

    var callbackList = xmp.FABridge.initCallbacks[bridgeName];
    if(callbackList == null)
    {
        xmp.FABridge.initCallbacks[bridgeName] = callbackList = [];
    }

    callbackList.push(callback);
}

// updated for changes to SWFObject2
xmp.FABridge__bridgeInitialized = function(bridgeName) {
    var objects = document.getElementsByTagName("object");
    var ol = objects.length;
    var activeObjects = [];
    if (ol > 0) {
		for (var i = 0; i < ol; i++) {
			if (typeof objects[i].SetVariable != "undefined") {
				activeObjects[activeObjects.length] = objects[i];
			}
		}
	}
    var embeds = document.getElementsByTagName("embed");
    var el = embeds.length;
    var activeEmbeds = [];
    if (el > 0) {
		for (var j = 0; j < el; j++) {
			if (typeof embeds[j].SetVariable != "undefined") {
            	activeEmbeds[activeEmbeds.length] = embeds[j];
            }
        }
    }
    var aol = activeObjects.length;
    var ael = activeEmbeds.length;
    var searchStr = "bridgeName="+ bridgeName;
    if ((aol == 1 && !ael) || (aol == 1 && ael == 1)) {
    	xmp.FABridge.attachBridge(activeObjects[0], bridgeName);	 
    }
    else if (ael == 1 && !aol) {
    	xmp.FABridge.attachBridge(activeEmbeds[0], bridgeName);
        }
    else {
                var flash_found = false;
		if (aol > 1) {
			for (var k = 0; k < aol; k++) {
				 var params = activeObjects[k].childNodes;
				 for (var l = 0; l < params.length; l++) {
					var param = params[l];
					if (param.nodeType == 1 && param.tagName.toLowerCase() == "param" && param["name"].toLowerCase() == "flashvars" && param["value"].indexOf(searchStr) >= 0) {
						xmp.FABridge.attachBridge(activeObjects[k], bridgeName);
                            flash_found = true;
                            break;
                        }
                    }
                if (flash_found) {
                    break;
                }
            }
        }
		if (!flash_found && ael > 1) {
			for (var m = 0; m < ael; m++) {
                var flashVarsNode = activeEmbeds[m].attributes.getNamedItem("flashVars");
                if (flashVarsNode != null && flashVarsNode != undefined) {
                    var flashVars = flashVarsNode.nodeValue;
                    if (flashVars.indexOf(searchStr) >= 0) {
                        xmp.FABridge.attachBridge(activeEmbeds[m], bridgeName);
                        break;
                    }
                }
            }
        }
    }
    return true;
}

// used to track multiple bridge instances, since callbacks from AS are global across the page.

xmp.FABridge.nextBridgeID = 0;
xmp.FABridge.instances = {};
xmp.FABridge.idMap = {};
xmp.FABridge.refCount = 0;

xmp.FABridge.extractBridgeFromID = function(id)
{
    var bridgeID = (id >> 16);
    return xmp.FABridge.idMap[bridgeID];
}

xmp.FABridge.attachBridge = function(instance, bridgeName)
{
    var newBridgeInstance = new xmp.FABridge(instance, bridgeName);

    xmp.FABridge[bridgeName] = newBridgeInstance;

/*  xmp.FABridge[bridgeName] = function() {
        return newBridgeInstance.root();
    }
*/
    var callbacks = xmp.FABridge.initCallbacks[bridgeName];
    if (callbacks == null)
    {
        return;
    }
    for (var i = 0; i < callbacks.length; i++)
    {
        callbacks[i].call(newBridgeInstance);
    }
    delete xmp.FABridge.initCallbacks[bridgeName]
}

// some methods can't be proxied.  You can use the explicit get,set, and call methods if necessary.

xmp.FABridge.blockedMethods =
{
    toString: true,
    get: true,
    set: true,
    call: true
};

xmp.FABridge.prototype =
{


// bootstrapping

    root: function()
    {
        return this.deserialize(this.target.getRoot());
    },
//clears all of the AS objects in the cache maps
    releaseASObjects: function()
    {
        return this.target.releaseASObjects();
    },
//clears a specific object in AS from the type maps
    releaseNamedASObject: function(value)
    {
        if(typeof(value) != "object")
        {
            return false;
        }
        else
        {
            var ret =  this.target.releaseNamedASObject(value.fb_instance_id);
            return ret;
        }
    },
//create a new AS Object
    create: function(className)
    {
        return this.deserialize(this.target.create(className));
    },


    // utilities

    makeID: function(token)
    {
        return (this.bridgeID << 16) + token;
    },


    // low level access to the flash object

//get a named property from an AS object
    getPropertyFromAS: function(objRef, propName)
    {
        if (xmp.FABridge.refCount > 0)
        {
            throw new Error("You are trying to call recursively into the Flash Player which is not allowed. In most cases the JavaScript setTimeout function, can be used as a workaround.");
        }
        else
        {
            xmp.FABridge.refCount++;
            retVal = this.target.getPropFromAS(objRef, propName);
            retVal = this.handleError(retVal);
            xmp.FABridge.refCount--;
            return retVal;
        }
    },
//set a named property on an AS object
    setPropertyInAS: function(objRef,propName, value)
    {
        if (xmp.FABridge.refCount > 0)
        {
            throw new Error("You are trying to call recursively into the Flash Player which is not allowed. In most cases the JavaScript setTimeout function, can be used as a workaround.");
        }
        else
        {
            xmp.FABridge.refCount++;
            retVal = this.target.setPropInAS(objRef,propName, this.serialize(value));
            retVal = this.handleError(retVal);
            xmp.FABridge.refCount--;
            return retVal;
        }
    },

//call an AS function
    callASFunction: function(funcID, args)
    {
        if (xmp.FABridge.refCount > 0)
        {
            throw new Error("You are trying to call recursively into the Flash Player which is not allowed. In most cases the JavaScript setTimeout function, can be used as a workaround.");
        }
        else
        {
            xmp.FABridge.refCount++;
            retVal = this.target.invokeASFunction(funcID, this.serialize(args));
            retVal = this.handleError(retVal);
            xmp.FABridge.refCount--;
            return retVal;
        }
    },
//call a method on an AS object
    callASMethod: function(objID, funcName, args)
    {
        if (xmp.FABridge.refCount > 0)
        {
            throw new Error("You are trying to call recursively into the Flash Player which is not allowed. In most cases the JavaScript setTimeout function, can be used as a workaround.");
        }
        else
        {
            xmp.FABridge.refCount++;
            args = this.serialize(args);
            retVal = this.target.invokeASMethod(objID, funcName, args);
            retVal = this.handleError(retVal);
            xmp.FABridge.refCount--;
            return retVal;
        }
    },

    // responders to remote calls from flash

    //callback from flash that executes a local JS function
    //used mostly when setting js functions as callbacks on events
    invokeLocalFunction: function(funcID, args)
    {
        var result;
        var func = this.localFunctionCache[funcID];

        if(func != undefined)
        {
            result = this.serialize(func.apply(null, this.deserialize(args)));
        }

        return result;
    },

    // Object Types and Proxies
	
    // accepts an object reference, returns a type object matching the obj reference.
    getTypeFromName: function(objTypeName)
    {
        return this.remoteTypeCache[objTypeName];
    },
    //create an AS proxy for the given object ID and type
    createProxy: function(objID, typeName)
    {
        var objType = this.getTypeFromName(typeName);
	        xmp.FABridge.instanceFactory.prototype = objType;
	        var instance = new xmp.FABridge.instanceFactory(objID);
        this.remoteInstanceCache[objID] = instance;
        return instance;
    },
    //return the proxy associated with the given object ID
    getProxy: function(objID)
    {
        return this.remoteInstanceCache[objID];
    },

    // accepts a type structure, returns a constructed type
    addTypeDataToCache: function(typeData)
    {
        newType = new xmp.ASProxy(this, typeData.name);
        var accessors = typeData.accessors;
        for (var i = 0; i < accessors.length; i++)
        {
            this.addPropertyToType(newType, accessors[i]);
        }

        var methods = typeData.methods;
        for (var i = 0; i < methods.length; i++)
        {
            if (xmp.FABridge.blockedMethods[methods[i]] == undefined)
            {
                this.addMethodToType(newType, methods[i]);
            }
        }


        this.remoteTypeCache[newType.typeName] = newType;
        return newType;
    },

    //add a property to a typename; used to define the properties that can be called on an AS proxied object
    addPropertyToType: function(ty, propName)
    {
        var c = propName.charAt(0);
        var setterName;
        var getterName;
        if(c >= "a" && c <= "z")
        {
            getterName = "get" + c.toUpperCase() + propName.substr(1);
            setterName = "set" + c.toUpperCase() + propName.substr(1);
        }
        else
        {
            getterName = "get" + propName;
            setterName = "set" + propName;
        }
        ty[setterName] = function(val)
        {
            this.bridge.setPropertyInAS(this.fb_instance_id, propName, val);
        }
        ty[getterName] = function()
        {
            return this.bridge.deserialize(this.bridge.getPropertyFromAS(this.fb_instance_id, propName));
        }
    },

    //add a method to a typename; used to define the methods that can be callefd on an AS proxied object
    addMethodToType: function(ty, methodName)
    {
        ty[methodName] = function()
        {
            return this.bridge.deserialize(this.bridge.callASMethod(this.fb_instance_id, methodName, xmp.FABridge.argsToArray(arguments)));
        }
    },

    // Function Proxies

    //returns the AS proxy for the specified function ID
    getFunctionProxy: function(funcID)
    {
        var bridge = this;
        if (this.remoteFunctionCache[funcID] == null)
        {
            this.remoteFunctionCache[funcID] = function()
            {
                bridge.callASFunction(funcID, xmp.FABridge.argsToArray(arguments));
            }
        }
        return this.remoteFunctionCache[funcID];
    },
    
    //reutrns the ID of the given function; if it doesnt exist it is created and added to the local cache
    getFunctionID: function(func)
    {
        if (func.__bridge_id__ == undefined)
        {
            func.__bridge_id__ = this.makeID(this.nextLocalFuncID++);
            this.localFunctionCache[func.__bridge_id__] = func;
        }
        return func.__bridge_id__;
    },

    // serialization / deserialization

    serialize: function(value)
    {
        var result = {};

        var t = typeof(value);
        //primitives are kept as such
        if (t == "number" || t == "string" || t == "boolean" || t == null || t == undefined)
        {
            result = value;
        }
        else if (value instanceof Array)
        {
            //arrays are serializesd recursively
            result = [];
            for (var i = 0; i < value.length; i++)
            {
                result[i] = this.serialize(value[i]);
            }
        }
        else if (t == "function")
        {
            //js functions are assigned an ID and stored in the local cache 
            result.type = xmp.FABridge.TYPE_JSFUNCTION;
            result.value = this.getFunctionID(value);
        }
        else if (value instanceof xmp.ASProxy)
        {
            result.type = xmp.FABridge.TYPE_ASINSTANCE;
            result.value = value.fb_instance_id;
        }
        else
        {
            result.type = xmp.FABridge.TYPE_ANONYMOUS;
            result.value = value;
        }

        return result;
    },

    //on deserialization we always check the return for the specific error code that is used to marshall NPE's into JS errors
    // the unpacking is done by returning the value on each pachet for objects/arrays 
    deserialize: function(packedValue)
    {

        var result;

        var t = typeof(packedValue);
        if (t == "number" || t == "string" || t == "boolean" || packedValue == null || packedValue == undefined)
        {
            result = this.handleError(packedValue);
        }
        else if (packedValue instanceof Array)
        {
            result = [];
            for (var i = 0; i < packedValue.length; i++)
            {
                result[i] = this.deserialize(packedValue[i]);
            }
        }
        else if (t == "object")
        {
            for(var i = 0; i < packedValue.newTypes.length; i++)
            {
                this.addTypeDataToCache(packedValue.newTypes[i]);
            }
            for (var aRefID in packedValue.newRefs)
            {
                this.createProxy(aRefID, packedValue.newRefs[aRefID]);
            }
            if (packedValue.type == xmp.FABridge.TYPE_PRIMITIVE)
            {
                result = packedValue.value;
            }
            else if (packedValue.type == xmp.FABridge.TYPE_ASFUNCTION)
            {
                result = this.getFunctionProxy(packedValue.value);
            }
            else if (packedValue.type == xmp.FABridge.TYPE_ASINSTANCE)
            {
                result = this.getProxy(packedValue.value);
            }
            else if (packedValue.type == xmp.FABridge.TYPE_ANONYMOUS)
            {
                result = packedValue.value;
            }
        }
        return result;
    },
    //increases the reference count for the given object
    addRef: function(obj)
    {
        this.target.incRef(obj.fb_instance_id);
    },
    //decrease the reference count for the given object and release it if needed
    release:function(obj)
    {
        this.target.releaseRef(obj.fb_instance_id);
    },

    // check the given value for the components of the hard-coded error code : __FLASHERROR
    // used to marshall NPE's into flash
    
    handleError: function(value)
    {
        if (typeof(value)=="string" && value.indexOf("__FLASHERROR")==0)
        {
            var myErrorMessage = value.split("||");
            if(xmp.FABridge.refCount > 0 )
            {
                xmp.FABridge.refCount--;
            }
            throw new Error(myErrorMessage[1]);
            return value;
        }
        else
        {
            return value;
        }   
    }
};

// The root ASProxy class that facades a flash object

xmp.ASProxy = function(bridge, typeName)
{
    this.bridge = bridge;
    this.typeName = typeName;
    return this;
};
//methods available on each ASProxy object
xmp.ASProxy.prototype =
{
    get: function(propName)
    {
        return this.bridge.deserialize(this.bridge.getPropertyFromAS(this.fb_instance_id, propName));
    },

    set: function(propName, value)
    {
        this.bridge.setPropertyInAS(this.fb_instance_id, propName, value);
    },

    call: function(funcName, args)
    {
        this.bridge.callASMethod(this.fb_instance_id, funcName, args);
    }, 
    
    addRef: function() {
        this.bridge.addRef(this);
    }, 
    
    release: function() {
        this.bridge.release(this);
    }
};

