// Turner XMP, Release Build,  2007 Turner Broadcasting System, Inc. A Time Warner Company.  Version: 0.1.633.2120
// xmp_services, xmp_services_0_1_633_2120.js
xmp.i_CONTROL_STREAM_NODE_PATH="/PlayerContexts/Global/ControlStream";xmp.CONTROL_STREAM_SERVICE="ControlStream";xmp.i_CONTROL_STREAM_MEDIA_TYPE="Media Type";xmp.i_CONTROL_STREAM_ENVIRONMENT_LABEL="Environment Label";xmp.i_CONTROL_STREAM_URL="Url";xmp.i_CONTROL_STREAM_RECONNECT_RETRIES="Reconnect Retries";xmp.i_CONTROL_STREAM_RECONNECT_RETRY_INTERVAL="Reconnect Retry Interval";xmp.i_CONTROL_STREAM_REFRESH_INTERVAL="RefreshInterval";xmp.i_CONTROL_STREAM_START_DELAY="Start Delay";xmp.i_CONTROL_STREAM_RESOURCE_TRANSPORT="controlStreamResource";xmp.i_ENVIRONMENT_LABEL="{{environment_label}}";xmp.i_RESOURCE_NAME="name";xmp.i_RESOURCE_LABEL="label";xmp.i_RESOURCE_WEB_URL="webUrl";xmp.i_RESOURCE="resource";xmp.i_WEB_RESOURCE_CACHING_CONTEXT="retrieved from the web";xmp.i_TRIGGER_RESOURCE_CACHING_CONTEXT="received from trigger";xmp.i_START_DELAY_TIMER="StartDelay";xmp.i_REFRESH_RESOURCE_TIMER="RefreshResources";xmp.i_RECONNECT_TIMER="Reconnect";xmp.ControlStream=function(){this.p_listener=null;};xmp.ControlStream.prototype.i_init=function(aa){try{this.p_logger=new xmp.util.internals.CategoryLogger(xmp.CONTROL_STREAM_SERVICE);this.p_validateListener(aa);this.p_listener=aa;this.p_resetReconnect();var ba=xmp.util.SettingsManager.getInstance().getGlobalContextNode().getNodeForPath(xmp.i_CONTROL_STREAM_NODE_PATH);this.p_initProperties(ba);this.p_reader=xmp.ControlStreamReaderFactory.i_createReader(xmp.util.internals.BrowserDetect.OS,this,this.p_mimeType);this.p_initResources(ba);this.p_start();}
catch(e){this.p_handleError("Initializing.",e);}};xmp.ControlStream.prototype.i_fini=function(){if(this.p_reader){this.p_reader.i_close();}
if(this.p_startDelayTimer){this.p_startDelayTimer.stop();this.p_startDelayTimer=null;}
if(this.p_refreshResourcesTimer){this.p_refreshResourcesTimer.stop();this.p_refreshResourcesTimer=null;}
this.p_resetReconnect();};xmp.ControlStream.prototype.p_start=function(){if(0===this.p_startDelay){this.p_handleStart();}
else{this.p_startDelayTimer=this.p_createTimer({id:xmp.i_START_DELAY_TIMER,interval:this.p_startDelay,handler:this.p_onDelayedStart});this.p_startDelayTimer.start();}};xmp.ControlStream.prototype.p_validateListener=function(ca){if(!ca){throw new xmp.ControlStreamError("Validating listener.","Missing control stream listener.");}
if(false===xmp.isDefined(ca.i_onControlStreamError)){throw new xmp.ControlStreamError("Validating listener.","Invalid control stream listener.  Missing \"i_onControlStreamError\" handler.");}
if(false===xmp.isDefined(ca.i_onControlStreamTrigger)){throw new xmp.ControlStreamError("Validating listener.","Invalid control stream listener.  Missing \"i_onControlStreamTrigger\" handler.");}
if(false===xmp.isDefined(ca.i_onControlStreamTriggerInit)){throw new xmp.ControlStreamError("Validating listener.","Invalid control stream listener.  Missing \"i_onControlStreamTriggerInit\" handler.");}};xmp.ControlStream.prototype.p_validateResource=function(da){if(da.name.length===0){throw new xmp.ControlStreamError("Validating resource.","Missing control stream resource name.");}
if(da.label.length===0){throw new xmp.ControlStreamError("Validating resource.","Missing control stream resource label.");}
if(da.webUrl.length===0){throw new xmp.ControlStreamError("Validating resource.","Missing control stream \""+da.name+"\" web url.");}};xmp.ControlStream.prototype.p_initProperties=function(ea){var fa=ea.getString(xmp.i_CONTROL_STREAM_MEDIA_TYPE,xmp.NO_DEFAULT_VALUE);if(fa.length===0){throw new xmp.ControlStreamError("Initializing properties.","Missing control stream media type.");}
var ga=xmp.PlayerPolicy.i_getMediaType(fa);if(false===xmp.isDefined(ga)){throw new xmp.ControlStreamError("Initializing properties.","Invalid control stream media type \""+fa+"\".");}
this.p_mimeType=ga.mimeType;this.p_url=ea.getString(xmp.i_CONTROL_STREAM_URL,xmp.NO_DEFAULT_VALUE);if(this.p_url.length===0){throw new xmp.ControlStreamError("Initializing properties.","Missing control stream url.");}
this.p_reconnectRetryInterval=ea.getInt(xmp.i_CONTROL_STREAM_RECONNECT_RETRY_INTERVAL,0);if(this.p_reconnectRetryInterval===0){throw new xmp.ControlStreamError("Initializing properties.","Missing control stream reconnect retry interval.");}
this.p_maxReconnectRetryCount=ea.getInt(xmp.i_CONTROL_STREAM_RECONNECT_RETRIES,0);this.p_startDelay=ea.getInt(xmp.i_CONTROL_STREAM_START_DELAY,0);var ha=ea.getNodeForPath(xmp.i_CONTROL_STREAM_REFRESH_INTERVAL);this.p_refreshInterval=ha.getInt(xmp.util.internals.BrowserDetect.OS,0);if(this.p_refreshInterval===0){throw new xmp.ControlStreamError("Initializing properties.","Missing control stream refresh interval for the \""+xmp.util.internals.BrowserDetect.OS+"\" platform.");}};xmp.ControlStream.prototype.p_initResources=function(ia){this.p_resources={};var ja=ia.getString(xmp.i_CONTROL_STREAM_ENVIRONMENT_LABEL,xmp.NO_DEFAULT_VALUE);if(ja.Length===0){throw new xmp.ControlStreamError("Initializing resources.","Missing control stream environment label.");}
var ka=ia.retrieveChildren();var la=ka.length;for(var i=0;i<la;i++){var ma=ka[i];if(ma.getName()===xmp.i_CONTROL_STREAM_REFRESH_INTERVAL){continue;}
var na=ma.getString(xmp.i_RESOURCE_LABEL,xmp.NO_DEFAULT_VALUE);na=na.replace(xmp.i_ENVIRONMENT_LABEL,ja);var oa={initialized:false,name:ma.getString(xmp.i_RESOURCE_NAME,xmp.NO_DEFAULT_VALUE),label:na,webUrl:ma.getString(xmp.i_RESOURCE_WEB_URL,xmp.NO_DEFAULT_VALUE),data:null};this.p_validateResource(oa);this.p_resources[oa.name]=oa;}};xmp.ControlStream.prototype.p_refreshResources=function(pa){for(var qa=xmp.MapIterator.create(this.p_resources);qa.hasNext();qa.next()){this.p_getResourceFromWeb(qa.currentValue(),pa);}};xmp.ControlStream.prototype.p_getResourceFromWeb=function(ra,sa){var ta=((true===sa)?this.p_onInitResource:this.p_onResourceLoadedFromWeb);var ua=new xmp.util.Callback(xmp.CONTROL_STREAM_SERVICE,ta,this);ua.setMetadata(xmp.i_RESOURCE,ra);var va=xmp.net.AjaxRequestManager.getInstance();va.request(xmp.CONTROL_STREAM_SERVICE,ua,xmp.i_CONTROL_STREAM_RESOURCE_TRANSPORT,ra.webUrl,xmp.net.ContentTypes.JSON,null);};xmp.ControlStream.prototype.p_onResourceLoadedFromWeb=function(wa,xa){this.p_setWebResource(wa,xa,this.p_listener.i_onControlStreamTrigger,true);};xmp.ControlStream.prototype.p_onInitResource=function(ya,za){var Aa=null;try{Aa=ya.getMetadata(xmp.i_RESOURCE,{});this.p_setWebResource(ya,za,this.p_listener.i_onControlStreamTriggerInit,false);Aa.initialized=true;}
catch(e){if(Aa){if(false===Aa.initialized){try{this.p_listener.i_onControlStreamTriggerInit(Aa.name,null);}
catch(e2){}
Aa.initialized=true;}}}};xmp.ControlStream.prototype.p_setResource=function(Ba,Ca,Da,Ea,Fa){this.p_validateResourceData(Ca,Da);if(true===Ea&&false===this.p_checkResourceVersion(Ca,Da)){this.p_logger.info((new Date()).toString()+" - Ignoring resource \""+Ca.name+"\" "+Ba+".  Already up to date ("+Da.modifiedDate+").");return;}
Ca.data=Da;this.p_logger.info((new Date()).toString()+" - Resource \""+Ca.name+"\" "+Ba+".");Fa.call(this.p_listener,Ca.name,Da);};xmp.ControlStream.prototype.p_checkResourceVersion=function(Ga,Ha){if(!Ga.data){return true;}
return(Ha.modifiedDate>Ga.data.modifiedDate);};xmp.ControlStream.prototype.p_validateResourceData=function(Ia,Ja){if(!Ja){throw new xmp.ControlStreamError("Validating resource data.","NULL resource data.");}
if(!Ja.id||Ja.id.length===0){throw new xmp.ControlStreamError("Validating resource data.","Invalid control stream resource \""+Ia.name+"\" data.  Missing resource id.");}
if(Ia.label!==Ja.id){throw new xmp.ControlStreamError("Validating resource data.","Invalid control stream resource \""+Ia.name+"\" data id \""+Ja.id+"\".  Expected \""+Ia.label+"\".");}};xmp.ControlStream.prototype.p_createTimer=function(Ka){var La=new xmp.util.Callback(Ka.id,Ka.handler,this);return new xmp.util.Timer(Ka.id,Ka.interval,-1,La);};xmp.ControlStream.prototype.p_handleStart=function(){this.p_connect();this.p_refreshResources(true);this.p_refreshResourcesTimer=this.p_createTimer({id:xmp.i_REFRESH_RESOURCE_TIMER,interval:this.p_refreshInterval,handler:this.p_onRefreshResources});this.p_refreshResourcesTimer.start();};xmp.ControlStream.prototype.p_onDelayedStart=function(Ma,Na){try{this.p_startDelayTimer.stop();this.p_startDelayTimer=null;this.p_handleStart();}
catch(e){this.p_handleError("Starting after delay.",e);}};xmp.ControlStream.prototype.p_onRefreshResources=function(Oa,Pa){try{this.p_refreshResources(false);}
catch(e){this.p_handleError("Refreshing all resources.",e);}};xmp.ControlStream.prototype.p_handleError=function(Qa,e){var Ra=e;if(false===(Ra instanceof xmp.ControlStreamError)){Ra=new xmp.ControlStreamError(((e.context)?e.context:Qa),((e.rawMessage)?e.rawMessage:e.message));Ra.setInnerError(e);}
this.p_logError(Ra);if(!this.p_listener){xmp.handleFatalError(Ra);}
else if(true===xmp.isDefined(this.p_listener.i_onControlStreamError)){this.p_reader.i_close();this.p_listener.i_onControlStreamError(Ra);}};xmp.ControlStream.prototype.i_onReaderError=function(e){this.p_logError(e);this.p_reconnect();};xmp.ControlStream.prototype.i_onReaderTrigger=function(Sa,Ta){var Ua=null;try{Ua=this.p_getResourceFromLabel(Sa);this.p_validateTrigger(Sa,Ua);var Va=xmp.Base64.i_decode(Ta);var Wa=this.p_parseJson(Va);this.p_setResource(xmp.i_TRIGGER_RESOURCE_CACHING_CONTEXT,Ua,Wa,false,this.p_listener.i_onControlStreamTrigger);this.p_logger.info(Va);}
catch(e){var Xa="TRIGGER PROCESSING ERROR.";if(Ua){Xa="TRIGGER \""+Ua.name+"\" PROCESSING ERROR.";}
this.p_logError(e);this.p_getResourceFromWeb(this.p_getResourceFromLabel(Sa));}};xmp.ControlStream.prototype.i_onReaderConnected=function(){this.p_logger.info("Connected.");this.p_resetReconnect();};xmp.ControlStream.prototype.i_onReaderPlugInError=function(e){this.p_listener.onPlugInError(e);};xmp.ControlStream.prototype.i_onReaderUnsupportedPlatformError=function(e){this.p_listener.onUnsupportedPlatformError(e);};xmp.ControlStream.prototype.p_reconnect=function(){if(!this.p_reconnectTimer){this.p_reconnectRetryCount=0;this.p_reconnectTimer=this.p_createTimer({id:xmp.i_RECONNECT_TIMER,interval:this.p_reconnectRetryInterval,handler:this.p_onReconnect});this.p_reconnectTimer.start();}};xmp.ControlStream.prototype.p_onReconnect=function(Ya,Za){try{if(true===this.p_reader.i_isConnected()||(this.p_maxReconnectRetryCount>0&&this.p_reconnectRetryCount===this.p_maxReconnectRetryCount)){if(this.p_reconnectRetryCount===this.p_maxReconnectRetryCount&&false===this.p_reader.i_isConnected()){this.p_logger.warn("Control stream reconnect retry maximum "+this.p_maxReconnectRetryCount+" limit reached...");}
this.p_resetReconnect();return;}
this.p_reconnectRetryCount++;this.p_logger.warn("Control stream reconnect retry "+this.p_reconnectRetryCount+"...");this.p_connect();this.p_refreshResources(false);}
catch(e){this.p_logError(e);}};xmp.ControlStream.prototype.p_getResourceFromLabel=function($a){for(var ab=xmp.MapIterator.create(this.p_resources);ab.hasNext();ab.next()){var bb=ab.currentValue();if(bb.label===$a){return bb;}}
return null;};xmp.ControlStream.prototype.p_logError=function(e){this.p_logger.warn(e.message);};xmp.ControlStream.prototype.p_connect=function(){var cb=this.p_reader.i_open(this.p_url);if(cb){this.p_logger.info("Connecting to \""+cb+"\".");}};xmp.ControlStream.prototype.p_resetReconnect=function(){if(this.p_reconnectTimer){this.p_reconnectTimer.stop();this.p_reconnectTimer=null;}
this.p_reconnectRetryCount=0;};xmp.ControlStream.prototype.p_validateTrigger=function(db,eb){if(!eb){throw new xmp.ControlStreamError("Validating trigger.","Missing control stream resource configuration for \""+db+"\" trigger.");}};xmp.ControlStream.prototype.p_parseJson=function(fb){var gb=xmp.trimString(fb);return this.p_parseJavaScript('('+gb+')');};xmp.ControlStream.prototype.p_parseJavaScript=function(hb){return eval(hb);};xmp.ControlStream.prototype.p_setWebResource=function(ib,jb,kb,lb){try{var mb=ib.getMetadata(xmp.i_RESOURCE,{});if(true===jb.isError()){throw new xmp.ControlStreamError("Initializing resources.","Unable to retrieve control stream resource \""+mb.name+"\" from url \""+mb.webUrl+"\". \n\n"+jb.i_makeReport());}
this.p_setResource(xmp.i_WEB_RESOURCE_CACHING_CONTEXT,mb,jb.getJsonObject(),true,kb);}
catch(e){var nb="";if(e instanceof xmp.ControlStreamError){nb=e.message;}
else{nb="Unable to retrieve control stream resource \""+mb.name+"\" from url \""+mb.webUrl+"\". \n\n"+e.message;}
this.p_logger.warn(nb);if(false===lb){throw e;}}};xmp.CONTROL_STREAM_READER="ControlStreamReader";xmp.ControlStreamReader=function(ob,pb){this.p_listener=ob;this.p_mimeType=pb;this.p_connected=false;this.p_registry=new xmp.PlayerModeRegistry();this.p_state=this.p_registry.i_findMode(xmp.i_FINI);xmp.NativePlayerRegistry.i_createGroup(this.i_getName(),this);this.p_player=xmp.NativePlayerRegistry.i_findPlayerByMimeType(this.i_getName(),xmp.i_NULL_MIME_TYPE);this.p_viewManager=new xmp.ViewManager(this.i_getName());this.p_viewManager.i_setViewportConfig(xmp.i_NULL_MIME_TYPE,xmp.DHTML_VIEWPORT);this.p_viewManager.i_setViewportConfig(this.p_mimeType,xmp.DHTML_VIEWPORT);};xmp.ControlStreamReader.prototype.i_open=function(qb){var rb=this.p_createPlayableNode(qb);if(false===this.p_initNativePlayer(rb)){this.p_state.i_open(this,rb);}
return rb.getURI();};xmp.ControlStreamReader.prototype.i_close=function(){this.p_state.i_close(this);this.p_connected=false;};xmp.ControlStreamReader.prototype.p_createPlayableNode=function(sb){var tb=new xmp.util.PlayableNode();tb.setMimeTypes([this.p_mimeType]);tb.setURI(sb);tb.setStreamingMode(xmp.CONTROL_STREAMING_MODE);xmp.PlayerPolicy.i_apply(this,tb);return tb;};xmp.ControlStreamReader.prototype.i_onNativePlayerStateChange=function(ub,vb){try{if(ub===xmp.OPEN){this.p_state.i_play(this);this.p_connected=true;this.p_listener.i_onReaderConnected();}
else if(ub===xmp.ENDED){throw new xmp.ControlStreamReaderError("Handling native player state change.","Control stream ended.");}}
catch(e){this.p_handleError("Handling native player state change.",e);}};xmp.ControlStreamReader.prototype.i_onNativePlayerTrigger=function(wb,xb){try{this.p_listener.i_onReaderTrigger(wb,xb);}
catch(e){this.p_handleError("Forwarding trigger to listener.",e);}};xmp.ControlStreamReader.prototype.i_onNativePlayerError=function(e){this.p_handleError("Forwarding native player error to listener.",e);};xmp.ControlStreamReader.prototype.i_onNativePlayerTimelineChange=function(yb,zb){};xmp.ControlStreamReader.prototype.i_onNativePlayerCreated=function(Ab,Bb){if(this.p_state.i_getType()===xmp.ERRORS){return;}
this.p_state.i_open(this,Bb.node);};xmp.ControlStreamReader.prototype.i_onNativePlayerInvoke=function(Cb,Db){};xmp.ControlStreamReader.prototype.i_onViewportOpened=function(Eb,Fb){Fb.data.viewport=Eb;Fb.player.i_create(Fb.data);this.p_player=Fb.player;};xmp.ControlStreamReader.prototype.i_onCreateViewport=function(Gb,Hb,Ib,Jb){var Kb=document.createElement("div");Kb.setAttribute(xmp.ID_ATTRIBUTE,Hb);Kb.setAttribute(xmp.NAME_ATTRIBUTE,Hb);Kb.style.width="1px";Kb.style.height="1px";xmp.insertDomChildBefore(document.body,Kb,document.body.firstChild);return Kb;};xmp.ControlStreamReader.prototype.i_onDestroyViewport=function(Lb,Mb){var Nb=xmp.findDomElement(Mb);if(Nb){var Ob=xmp.getDomParent(Nb);Ob.removeChild(Nb);}};xmp.ControlStreamReader.prototype.i_onViewportCreated=function(Pb,Qb){if(this.p_state.i_getType()===xmp.ERRORS){return;}
if(Qb===null){return;}
this.p_viewManager.i_openViewport(this,this.i_getName(),Pb.i_getMimeType(),Qb);};xmp.ControlStreamReader.prototype.i_onViewportError=function(e){this.p_handleError("Forwarding viewport error to listener.",e);};xmp.ControlStreamReader.prototype.onError=function(Rb,e){this.p_listener.i_onReaderError(e);};xmp.ControlStreamReader.prototype.onPlugInError=function(e){this.p_listener.i_onReaderPlugInError(e);};xmp.ControlStreamReader.prototype.onUnsupportedPlatformError=function(e){this.p_listener.i_onReaderUnsupportedPlatformError(e);};xmp.ControlStreamReader.prototype.p_handleError=function(Sb,e){this.p_connected=false;this.p_state.i_error(this);this.p_setNullPlayer();var Tb=e;if(false===(Tb instanceof xmp.ControlStreamReaderError)){Tb=new xmp.ControlStreamReaderError(((e.context)?e.context:Sb),((e.rawMessage)?e.rawMessage:e.message));Tb.setInnerError(e);}
this.p_listener.i_onReaderError(Tb);};xmp.ControlStreamReader.prototype.p_initNativePlayer=function(Ub){try{this.p_state.i_close(this);var Vb=Ub.getMimeType();var Wb=xmp.NativePlayerRegistry.i_findPlayerByMimeType(this.i_getName(),Vb);if(!Wb){throw new xmp.InvalidMimeTypeError("Initializing native player..","Unable to find native player for MIME type \""+Vb+"\".");}
var Xb={player:Wb,data:{group:this.i_getName(),viewport:null,volume:0,mute:true,node:Ub,fullscreenEnabled:false,stretchToFit:false}};if(false===this.p_viewManager.i_openViewport(this,this.i_getName(),Ub.getMimeType(),Xb)){if(Wb.i_getType()!==this.p_player.i_getType()){Wb.i_create({group:this.i_getName(),viewport:this.p_viewManager.i_getActiveViewport(),volume:0,mute:true,node:Ub,fullscreenEnabled:false,stretchToFit:false});this.p_player=Wb;return true;}
return false;}
return true;}
catch(e){this.p_setNullPlayer();throw e;}
return false;};xmp.ControlStreamReader.prototype.p_setNullPlayer=function(){var Yb=xmp.NativePlayerRegistry.i_findPlayerByMimeType(this.i_getName(),xmp.i_NULL_MIME_TYPE);if(this.p_viewManager.i_getActiveViewport()===null){this.p_viewManager.i_createViewport(this,this.i_getName(),xmp.i_NULL_MIME_TYPE,null);}
Yb.i_create({group:this.i_getName(),viewport:this.p_viewManager.i_getActiveViewport(),volume:0,mute:true,node:null,fullscreenEnabled:false,stretchToFit:false});this.p_player=Yb;};xmp.ControlStreamReader.prototype.i_getName=function(){return xmp.CONTROL_STREAM_READER;};xmp.ControlStreamReader.prototype.i_getPlayer=function(){return this.p_player;};xmp.ControlStreamReader.prototype.i_changeState=function(Zb,$b){var ac=this.p_registry.i_findMode(Zb);ac.i_transition(this,$b,this.p_state);this.p_state=ac;};xmp.ControlStreamReader.prototype.i_isConnected=function(){return this.p_connected;};xmp.ControlStreamReaderFactory=function(){return{i_createReader:function(bc,cc,dc){if(bc===xmp.WINDOWS_PLATFORM){return new xmp.ControlStreamReader(cc,dc);}
else{return new xmp.NullStreamReader(cc,dc);}}};}();xmp.NullStreamReader=function(ec,fc){};xmp.NullStreamReader.prototype.i_open=function(gc){return null;};xmp.NullStreamReader.prototype.i_close=function(){};xmp.NullStreamReader.prototype.i_isConnected=function(){return false;};xmp.ControlStreamError=function(hc,ic){xmp.ControlStreamError.ctor.call(this,"ControlStreamError",hc,ic);};xmp.DERIVE_CLASS(xmp.util.internals.XMPError,xmp.ControlStreamError);xmp.ControlStreamReaderError=function(jc,kc){xmp.ControlStreamReaderError.ctor.call(this,"ControlStreamReaderError",jc,kc);};xmp.DERIVE_CLASS(xmp.util.internals.XMPError,xmp.ControlStreamReaderError);xmp.ImageRetrieverError=function(lc,mc){xmp.ImageRetrieverError.ctor.call(this,"ImageRetrieverError",lc,mc);};xmp.DERIVE_CLASS(xmp.util.internals.XMPError,xmp.ImageRetrieverError);xmp.i_IMAGE_RETRIEVER_NODE_PATH="/PlayerContexts/Global/ImageRetriever";xmp.IMAGE_RETRIEVER_SERVICE="ImageRetriever";xmp.i_IMAGE_RETRIEVER_REFRESH_INTERVAL="Refresh Interval";xmp.i_IMAGE_RETRIEVER_START_DELAY="Start Delay";xmp.i_RESOURCE_URL="url";xmp.ImageRetriever=function(){this.p_listener=null;};xmp.ImageRetriever.prototype.i_init=function(nc){try{this.p_logger=new xmp.util.internals.CategoryLogger(xmp.IMAGE_RETRIEVER_SERVICE);this.p_p_validateListener(nc);this.p_listener=nc;this.p_cacheID=(Math.round(Math.random()*(10000000-1))+1);var oc=xmp.util.SettingsManager.getInstance().getGlobalContextNode().getNodeForPath(xmp.i_IMAGE_RETRIEVER_NODE_PATH);this.p_initProperties(oc);this.p_initResources(oc);this.p_start();}
catch(e){this.p_handleError("Initializing.",e);}};xmp.ImageRetriever.prototype.i_fini=function(){if(this.p_startDelayTimer){this.p_startDelayTimer.stop();this.p_startDelayTimer=null;}
if(this.p_refreshResourcesTimer){this.p_refreshResourcesTimer.stop();this.p_refreshResourcesTimer=null;}};xmp.ImageRetriever.prototype.p_start=function(){if(0===this.p_startDelay){this.p_handleStart();}
else{this.p_startDelayTimer=this.p_createTimer({id:xmp.i_START_DELAY_TIMER,interval:this.p_startDelay,handler:this.p_onDelayedStart});this.p_startDelayTimer.start();}};xmp.ImageRetriever.prototype.p_handleStart=function(){this.p_refreshResourcesTimer=this.p_createTimer({id:xmp.i_REFRESH_RESOURCE_TIMER,interval:this.p_refreshInterval,handler:this.p_onRefreshResources});this.p_refreshResourcesTimer.start();this.p_refreshResources();};xmp.ImageRetriever.prototype.p_p_validateListener=function(pc){if(!pc){throw new xmp.ImageRetrieverError("Validating listener.","Missing image retriever listener.");}
if(false===xmp.isDefined(pc.i_onRetrieveImage)){throw new xmp.ImageRetrieverError("Validating listener.","Invalid image retriever listener.  Missing \"i_onRetrieveImage\" handler.");}
if(false===xmp.isDefined(pc.i_onImageRetrieverError)){throw new xmp.ImageRetrieverError("Validating listener.","Invalid image retriever listener.  Missing \"i_onImageRetrieverError\" handler.");}};xmp.ImageRetriever.prototype.p_validateResource=function(qc){if(qc.name.length===0){throw new xmp.ImageRetrieverError("Validating resource.","Missing image retriever resource name.");}
if(qc.url.length===0){throw new xmp.ImageRetrieverError("Validating resource.","Missing image retriever \""+qc.name+"\" url.");}};xmp.ImageRetriever.prototype.p_initProperties=function(rc){this.p_refreshInterval=rc.getInt(xmp.i_IMAGE_RETRIEVER_REFRESH_INTERVAL,0);if(this.p_refreshInterval===0){throw new xmp.ImageRetrieverError("Initializing properties.","Missing image retriever refresh interval.");}
this.p_startDelay=rc.getInt(xmp.i_IMAGE_RETRIEVER_START_DELAY,0);};xmp.ImageRetriever.prototype.p_initResources=function(sc){this.p_resources={};var tc=sc.retrieveChildren();var uc=tc.length;for(var i=0;i<uc;i++){var vc=tc[i];var wc={name:vc.getString(xmp.i_RESOURCE_NAME,xmp.NO_DEFAULT_VALUE),url:vc.getString(xmp.i_RESOURCE_URL,xmp.NO_DEFAULT_VALUE)};this.p_validateResource(wc);this.p_resources[wc.name]=wc;}};xmp.ImageRetriever.prototype.p_refreshResources=function(){try{var xc=xmp.getImageRoot();var yc=this.p_newCacheId();for(var zc=xmp.MapIterator.create(this.p_resources);zc.hasNext();zc.next()){try{var Ac=zc.currentValue();var Bc=xc+Ac.url+"?"+yc;this.p_listener.i_onRetrieveImage(Ac.name,Bc);this.p_logger.info((new Date()).toString()+" - Image resource \""+Ac.name+"\" retrieval refresh ("+yc+").");}
catch(e){var Cc="";if(e instanceof xmp.ImageRetrieverError){Cc=e.message;}
else{Cc="Error retrieving image resource \""+Ac.name+"\" from url \""+Bc+"\". \n\n"+e.message;}
this.p_logger.warn(Cc);}}}
catch(e2){this.p_handleError("Refreshing all resources.",e2);}};xmp.ImageRetriever.prototype.p_createTimer=function(Dc){var Ec=new xmp.util.Callback(Dc.id,Dc.handler,this);return new xmp.util.Timer(Dc.id,Dc.interval,-1,Ec);};xmp.ImageRetriever.prototype.p_onRefreshResources=function(Fc,Gc){this.p_refreshResources();};xmp.ImageRetriever.prototype.p_handleError=function(Hc,e){var Ic=e;if(false===(Ic instanceof xmp.ImageRetrieverError)){Ic=new xmp.ImageRetrieverError(((e.context)?e.context:Hc),((e.rawMessage)?e.rawMessage:e.message));Ic.setInnerError(e);}
this.p_logError(Ic);if(!this.p_listener){xmp.handleFatalError(Ic);}
else if(true===xmp.isDefined(this.p_listener.i_onImageRetrieverError)){this.p_listener.i_onImageRetrieverError(Ic);}};xmp.ImageRetriever.prototype.p_logError=function(e){this.p_logger.warn(e.message);};xmp.ImageRetriever.prototype.p_onDelayedStart=function(Jc,Kc){var Lc="";try{this.p_startDelayTimer.stop();this.p_startDelayTimer=null;this.p_handleStart();}
catch(e){this.p_handleError("Starting after delay.",e);}};xmp.ImageRetriever.prototype.p_newCacheId=function(){return"cacheID="+this.p_cacheID++;};xmp.ServiceRegistry=function(){var Mc={};return{p_getService:function(Nc){if(!Nc){throw new xmp.util.internals.InvalidArgsError("Missing service name.");}
if(!this.p_services){this.p_services={};}
var Oc=this.p_services[Nc];if(Oc){return Oc;}
if(Nc===xmp.CONTROL_STREAM_SERVICE){Oc=new xmp.ControlStream();this.p_services[Nc]=Oc;return Oc;}
else if(Nc===xmp.IMAGE_RETRIEVER_SERVICE){Oc=new xmp.ImageRetriever();this.p_services[Nc]=Oc;return Oc;}
throw new xmp.ServiceError("Retrieving service.","Unable to create service \""+Nc+"\".");},i_init:function(Pc,Mc){var Qc=Mc.length;for(var i=0;i<Qc;i++){this.p_getService(Mc[i]).i_init(Pc);}},i_fini:function(){for(var Rc=xmp.MapIterator.create(this.p_services);Rc.hasNext();Rc.next()){var Sc=Rc.currentValue();Sc.i_fini();}}};}();
