// Turner XMP, Release Build,  2007 Turner Broadcasting System, Inc. A Time Warner Company.  Version: 0.1.633.2120
// xmp_playlistapi, xmp_playlistapi_0_1_633_2120.js
xmp.createNamespace("xmp.playlistapi");xmp.playlistapi.PlayableNodeType=function(aa,id,ba){xmp.validateArguments(arguments,[xmp.i_OBJECT_TYPE,xmp.i_STRING_TYPE,xmp.i_STRING_TYPE],"PlayableNodeType.ctor");if(!xmp.isNonEmptyString(id)||!xmp.isNonEmptyString(ba)){throw new xmp.util.internals.InvalidArgsError("PlayableNodeType requires non-empty 'id' and 'typeName'.");}
this.p_typeName=ba;this.p_parent=null;this.p_id=id;this.p_directive=null;this.p_dataObject=aa;this.p_resourceDirective=null;};xmp.playlistapi.PlayableNodeType.getBaseNodeTypeName=function(ca){if(!xmp.playlistapi.PlayableNodeType._typeMapNode){var da=xmp.util.SettingsManager.getInstance().getGlobalContextNode();xmp.playlistapi.PlayableNodeType._typeMapNode=da.getNodeForPath('nodeTypeMap');}
var ea=xmp.playlistapi.PlayableNodeType._typeMapNode.getNodeForPath(ca);var fa=ea.getString('baseType','DEFAULT');return fa;};xmp.playlistapi.PlayableNodeType.prototype.getTypeName=function(){return this.p_typeName;};xmp.playlistapi.PlayableNodeType.prototype.getId=function(){return this.p_id;};xmp.playlistapi.PlayableNodeType.prototype.getDataObject=function(){return this.p_dataObject;};xmp.playlistapi.PlayableNodeType.prototype.getMetadata=function(ga,ha){return null;};xmp.playlistapi.PlayableNodeType.prototype._getChildCount=function(){return 0;};xmp.playlistapi.PlayableNodeType.prototype._getParent=function(){return this.p_parent;};xmp.playlistapi.PlayableNodeType.prototype._isCompositeType=function(){return false;};xmp.playlistapi.PlayableNodeType.prototype.i_isContentCompositeType=function(){return false;};xmp.playlistapi.PlayableNodeType.prototype.isContentType=function(){var ia=xmp.playlistapi.PlayableNodeType.getBaseNodeTypeName(this.getTypeName());return ia==='Content';};xmp.playlistapi.PlayableNodeType.prototype.isAdType=function(){var ja=xmp.playlistapi.PlayableNodeType.getBaseNodeTypeName(this.getTypeName());return ja==='Ad';};xmp.playlistapi.PlayableNodeType.prototype.isPromoType=function(){var ka=xmp.playlistapi.PlayableNodeType.getBaseNodeTypeName(this.getTypeName());return ka==='Promo';};xmp.playlistapi.PlayableNodeType.prototype.i_setParent=function(la){this.p_parent=la;};xmp.playlistapi.PlayableNodeType.prototype.i_handlePostBuild=function(){};xmp.playlistapi.PlayableNodeType.prototype.i_setDirective=function(ma){this.p_directive=ma;};xmp.playlistapi.PlayableNodeType.prototype.i_getDirective=function(){return this.p_directive;};xmp.playlistapi.PlayableNodeType.prototype.i_setResourceDirective=function(na){this.p_resourceDirective=na;};xmp.playlistapi.PlayableNodeType.prototype.i_getResourceDirective=function(){return this.p_resourceDirective;};xmp.createNamespace("xmp.playlistapi.internals");xmp.playlistapi.internals.PatternDirective=function(oa,pa,qa){xmp.validateArguments(arguments,[xmp.i_STRING_TYPE,xmp.i_OBJECT_TYPE,xmp.i_OBJECT_TYPE],"PatternDirective.ctor");if(!xmp.isNonEmptyString(oa)){throw new xmp.util.internals.InvalidArgsError("Argument 'type' must be a non-empty string.");}
this.p_type=oa;this.p_metadataMap=new xmp.util.internals.MetadataMap(true);this.p_metadataMap.i_reInitialize(pa);this.p_parameters=qa;};xmp.playlistapi.internals.PatternDirective.prototype.getType=function(){return this.p_type;};xmp.playlistapi.internals.PatternDirective.prototype.i_getParameterArray=function(){return this.p_parameters;};xmp.playlistapi.internals.PatternDirective.prototype.getMetadata=function(ra,sa){return this.p_metadataMap.i_get(ra,sa);};xmp.playlistapi.internals.PatternDirective.prototype.i_findNamedContentNode=function(ta,ua,va){var wa=this.p_findNamedContentNodeFromIterator(ta.i_getDataIterator(),ua,va);if(wa===null){xmp.util.internals.CategoryLogger.i_create('PatternDirective').info('Did not find named content node: '+va+', trying historical data.');wa=this.p_findNamedContentNodeFromIterator(ta.i_getHistoricalDataIterator(),ua,va);}
return wa;};xmp.playlistapi.internals.PatternDirective.prototype.p_findNamedContentNodeFromIterator=function(xa,ya,za){xa.first();var Aa=(za==='@Content');while(xa.hasNext()){var Ba=xa.next();if(!Ba.isValid()){continue;}
if(Ba.isContentType()&&Ba.getNodeType()._getParent().i_isContentCompositeType()){if(Aa){if(Ba.i_getPatternAddress().isSibling(ya.i_getPatternAddress(),true)){return Ba;}}
else{if(Ba.getNodeType()._getParent().getId()===za){var Ca=Ba.i_getPatternAddress().getParent();if(Ca.isSibling(ya.i_getPatternAddress(),true)){return Ba;}}}}}
return null;};xmp.createNamespace("xmp.playlistapi");xmp.playlistapi.AdPatternPlayList=function(Da,Ea,Fa,Ga){xmp.validateArguments(arguments,[xmp.i_OBJECT_TYPE,xmp.i_OBJECT_TYPE,xmp.i_OBJECT_TYPE,xmp.i_OBJECT_TYPE],"AdPatternPlayList.ctor");if(!Da||!Ea||!Fa){throw new xmp.util.internals.InvalidArgsError("One or more constructor arguments is null.");}
this.p_LOOK_AHEAD_AND_BEHIND_MIN=7;this.p_LOOK_AHEAD_AND_BEHIND_MAX=100;this.p_MAX_NODE_POOL_SIZE=50;this.p_logger=new xmp.util.internals.CategoryLogger('AdPatternPlayList');this.p_lockedForModification=false;this.p_metadataMap=new xmp.util.internals.MetadataMap(true);this.p_listener=Da;this.p_adPatternRootNodeType=null;this.p_invariantRuleContextArray=null;this.p_ruleIdToFactoryMap={};this.p_ruleIdToRuleMap={};this.p_ruleSetRunContext=new xmp.playlistapi.RuleSetRunContext();this.p_lookAheadAndBehindCount=this.p_calculateLookAheadAndBehind();this.p_internalPlayListArray=[];this.p_historicalPlayListArray=[];this.p_lastNode=null;this.p_outStandingPlayableNodeArray=[];this.p_poolPlayableNodeArray=[];this.p_iteratator=new xmp.playlistapi.PlayListIterator(this);this.p_parameterMap=null;xmp.util.PlayableNode.i_staticInit();this.p_parameterMap=xmp.playlistapi.internals.ParameterMap.calcInitial(Ea,Ga);var Ha=new xmp.playlistapi.internals.AdPatternBuilder(this.p_parameterMap);this.p_metadataMap.i_reInitialize(Ha.i_extractOptionalMetaData(Ea));this.p_adPatternRootNodeType=Ha._build(Ea);this.p_invariantRuleContextArray=Ha.i_buildRuleContextArray(Fa,null);this.p_logger.info('Constructed AdPatternPlayList');};xmp.playlistapi.AdPatternPlayList.prototype.getMetadata=function(Ia,Ja){return this.p_metadataMap.i_get(Ia,Ja);};xmp.playlistapi.AdPatternPlayList.prototype.setContentMetaResourceIds=function(Ka){try{for(var i=0;i<Ka.length;i++){if(typeof Ka[i]!=='string'){throw new xmp.util.internals.InvalidArgsError("Argument 'contentMetaResourceIdArray' must be an array of strings.");}}
this.i_checkLockedForModification();this.i_lockForModification();var La=new xmp.playlistapi.internals.PlayListBuilder(this,this.p_lastNode,this.p_adPatternRootNodeType,Ka,this.p_listener);this.p_internalPlayListArray=La.i_getOutput();}
finally{this.i_unlockForModification();}};xmp.playlistapi.AdPatternPlayList.prototype.i_getHistoricalDataIterator=function(){var Ma=[];Ma=Ma.concat(this.p_historicalPlayListArray);Ma=Ma.concat(this.p_internalPlayListArray);return(new xmp.playlistapi.internals.SimplePlayListIterator(Ma));};xmp.playlistapi.AdPatternPlayList.prototype.getIterator=function(){return this.p_iteratator;};xmp.playlistapi.AdPatternPlayList.prototype.getRuleIdArray=function(){var Na=[];var Oa={};for(var i=0;i<this.p_invariantRuleContextArray.length;i++){var Pa=this.p_invariantRuleContextArray[i].getId();if(!Oa[Pa]){Oa[Pa]=Pa;Na.push(Pa);}}
this.p_getPatternRuleIdsHelper(this.p_adPatternRootNodeType,Na,Oa);return Na;};xmp.playlistapi.AdPatternPlayList.prototype.loadRuleFactoryArray=function(Qa){xmp.validateArguments(arguments,[xmp.i_OBJECT_TYPE],"AdPatternPlayList.loadRuleFactoryArray");if(!Qa){throw new xmp.util.internals.InvalidArgsError("Argument 'ruleFactoryArray' cannot be null.");}
this.p_buildRuleIdToFactoryMap(Qa);if(this.p_logger.isDebugEnabled()){this.p_logger.debug('Loaded rule factories.');}};xmp.playlistapi.AdPatternPlayList.prototype.getLookAheadNodeArray=function(){return this.p_buildLookAheadArray();};xmp.playlistapi.AdPatternPlayList.prototype.getLookBehindNodeArray=function(){return this.p_buildLookBehindArray();};xmp.playlistapi.AdPatternPlayList.prototype.i_getParameterMapInternal=function(){return this.p_parameterMap;};xmp.playlistapi.AdPatternPlayList.prototype.p_findRule=function(Ra){var Sa=this.p_ruleIdToRuleMap[Ra];if(typeof Sa==="undefined"){var Ta=this.p_getFactory(Ra);try{Sa=Ta.createRule(Ra);}
catch(e){throw this.p_createExtensionGuardException(e,'RuleFactory.createRule');}
this.p_ruleIdToRuleMap[Ra]=Sa;}
return Sa;};xmp.playlistapi.AdPatternPlayList.prototype.p_buildRuleIdToFactoryMap=function(Ua){for(var i=0;i<Ua.length;i++){var Va=Ua[i];var Wa=null;try{Wa=Va.getCreatableRuleIds();}
catch(e){throw this.p_createExtensionGuardException(e,'RuleFactory.getCreatableRuleIds');}
for(var j=0;j<Wa.length;j++){var Xa=Wa[j];if(!Xa||Xa.length===0){throw new xmp.playlistapi.internals.PlayListError("RuleFactory retured a rule ID that is null, undefined, or empty.");}
if(typeof this.p_ruleIdToFactoryMap[Xa]!=="undefined"){throw new xmp.playlistapi.internals.PlayListError("Rule "+Xa+" found in more than one factory.");}
this.p_ruleIdToFactoryMap[Xa]=Va;}}
this.p_verifyRuleFactories();};xmp.playlistapi.AdPatternPlayList.prototype.addRuleFactory=function(Ya,Za){this.p_ruleIdToFactoryMap[Ya]=Za;};xmp.playlistapi.AdPatternPlayList.prototype.p_createExtensionGuardException=function(e,$a){var ab='Error occurred while invoking extension method: '+$a;this.p_logger.warn(ab,e);ab+=', Error data: ';ab+=xmp.extractErrorMessage(e);return new xmp.playlistapi.internals.PlayListError(ab);};xmp.playlistapi.AdPatternPlayList.prototype.p_calculateLookAheadAndBehind=function(){var bb=xmp.util.SettingsManager.getInstance().getContextNode();var cb=bb.getNodeForPath('BasePlayer');var db=cb.getInt('look ahead and behind count',this.p_LOOK_AHEAD_AND_BEHIND_MIN);if(db<this.p_LOOK_AHEAD_AND_BEHIND_MIN){db=this.p_LOOK_AHEAD_AND_BEHIND_MIN;}
else if(db>this.p_LOOK_AHEAD_AND_BEHIND_MAX){db=this.p_LOOK_AHEAD_AND_BEHIND_MAX;}
return db;};xmp.playlistapi.AdPatternPlayList.prototype.p_verifyRuleFactories=function(){this.p_verifyInvariantRuleFactories();this.p_verifyPlayableNodeTypeRuleFactoriesHelper(this.p_adPatternRootNodeType);};xmp.playlistapi.AdPatternPlayList.prototype.p_verifyInvariantRuleFactories=function(){for(var i=0;i<this.p_invariantRuleContextArray.length;i++){var eb=this.p_invariantRuleContextArray[i].getId();this.p_getFactory(eb);}};xmp.playlistapi.AdPatternPlayList.prototype.p_verifyPlayableNodeTypeRuleFactoriesHelper=function(fb){if(fb._isCompositeType()){var gb=fb._getChildCount();for(var i=0;i<gb;i++){this.p_verifyPlayableNodeTypeRuleFactoriesHelper(fb._getChild(i));}}
else{var hb=fb._getRuleContextArray();for(var j=0;j<hb.length;j++){var ib=hb[j].getId();this.p_getFactory(ib);}}};xmp.playlistapi.AdPatternPlayList.prototype.p_getFactory=function(jb){var kb=this.p_ruleIdToFactoryMap[jb];if(!kb){throw new xmp.playlistapi.internals.PlayListError("No factory defined for rule: "+jb);}
return kb;};xmp.playlistapi.AdPatternPlayList.prototype.i_getNextRuleFilteredPlayableNode=function(){var lb=null;while(this.p_internalPlayListArray.length>0){var mb=this.p_internalPlayListArray.shift();this.p_historicalPlayListArray.push(mb);if(this.p_safeRunRulesForNode(mb)){this.p_addToOutstandingArray(mb);lb=mb;break;}
else{this.p_returnNodeToPool(mb);}}
if(lb!==null){this.p_lastNode=lb;}
return lb;};xmp.playlistapi.AdPatternPlayList.prototype.p_safeRunRulesForNode=function(nb){try{return this.p_runRulesForNode(nb);}
catch(e){var ob='Error occured running rules for node: '+xmp.util.PlayableNode.safeGetBestId(nb);ob+='\nNode will be treated AS IF A RULE FAILED, skipped.';this.p_logger.warn(ob,e);return false;}};xmp.playlistapi.AdPatternPlayList.prototype.p_runRulesForNode=function(pb){if(pb.i_isEmptySlot()){if(this.p_logger.isDebugEnabled()){this.p_logger.debug('Node: '+pb.getBestId()+' IS AN EMPTY SLOT, FAILURE.');}
return false;}
var qb=this.p_buildRuleContextsForNode(pb);if(qb.length===0){if(this.p_logger.isDebugEnabled()){this.p_logger.debug('Node: '+pb.getBestId()+' HAS NO RULES, SUCCESS.');}
return true;}
this.p_ruleSetRunContext.i_initialize(pb);for(var i=0;i<qb.length;i++){var rb=qb[i];this.p_ruleSetRunContext.i_setCurrentRuleContext(rb);var sb=this.p_findRule(rb.getId());var tb=false;try{tb=sb.isPlayable(this.p_ruleSetRunContext);}
catch(e){throw this.p_createExtensionGuardException(e,'Rule.isPlayable for rule: '+this.p_ruleSetRunContext.getCurrentRuleContext().getId());}
if(!tb){if(this.p_logger.isDebugEnabled()){this.p_logger.debug('Node: '+pb.getBestId()+', Rule ID: '+rb.getId()+' FAILED.');}
return false;}
else{if(this.p_logger.isDebugEnabled()){this.p_logger.debug('Node: '+pb.getBestId()+', Rule ID: '+rb.getId()+' SUCCEEDED.');}}}
if(this.p_logger.isDebugEnabled()){this.p_logger.debug('Node: '+pb.getBestId()+' ALL RULES SUCCEEDED.');}
return true;};xmp.playlistapi.AdPatternPlayList.prototype.p_buildLookAheadArray=function(){var ub=[];for(var i=0;i<this.p_lookAheadAndBehindCount;i++){if(i>=(this.p_internalPlayListArray.length)){break;}
ub.push(this.p_internalPlayListArray[i]);}
return ub;};xmp.playlistapi.AdPatternPlayList.prototype.p_buildLookBehindArray=function(){var vb=[];vb=vb.concat(this.p_outStandingPlayableNodeArray).reverse();return vb;};xmp.playlistapi.AdPatternPlayList.prototype.p_buildRuleContextsForNode=function(wb){var xb=this.p_getApplicableInvariantRuleContexts(wb.getNodeTypeName());xb=xb.concat(wb.i_getRuleArrayReference());return xb;};xmp.playlistapi.AdPatternPlayList.prototype.p_getApplicableInvariantRuleContexts=function(yb){var zb=[];for(var i=0;i<this.p_invariantRuleContextArray.length;i++){var Ab=this.p_invariantRuleContextArray[i];if(Ab.i_isApplicable(yb)){zb.push(Ab);}}
return zb;};xmp.playlistapi.AdPatternPlayList.prototype.p_addToOutstandingArray=function(Bb){this.p_outStandingPlayableNodeArray.push(Bb);while(this.p_outStandingPlayableNodeArray.length>this.p_lookAheadAndBehindCount){this.p_returnNodeToPool(this.p_outStandingPlayableNodeArray.shift());}};xmp.playlistapi.AdPatternPlayList.prototype.p_getNodeFromPool=function(){var Cb=new xmp.util.PlayableNode();Cb._init();return Cb;};xmp.playlistapi.AdPatternPlayList.prototype.p_returnNodeToPool=function(Db){this.p_poolPlayableNodeArray.push(Db);while(this.p_poolPlayableNodeArray.length>this.p_MAX_NODE_POOL_SIZE){var Eb=this.p_poolPlayableNodeArray.shift();if(Eb){Eb._clear();}}};xmp.playlistapi.AdPatternPlayList.prototype.i_createNode=function(){return this.p_getNodeFromPool();};xmp.playlistapi.AdPatternPlayList.prototype.i_initializeNode=function(Fb){try{this.p_listener.handleInitializePlayableNode(Fb);}
catch(e){throw this.p_createExtensionGuardException(e,'PlayListListener.handleInitializePlayableNode');}};xmp.playlistapi.AdPatternPlayList.prototype.i_lockForModification=function(){this.p_lockedForModification=true;};xmp.playlistapi.AdPatternPlayList.prototype.i_unlockForModification=function(){this.p_lockedForModification=false;};xmp.playlistapi.AdPatternPlayList.prototype.i_checkLockedForModification=function(){if(this.p_lockedForModification){throw new xmp.playlistapi.internals.PlayListError("Cannot modify playlist while it is locked.");}};xmp.playlistapi.AdPatternPlayList.prototype.p_getPatternRuleIdsHelper=function(Gb,Hb,Ib){if(Gb._isCompositeType()){var Jb=Gb._getChildCount();for(var i=0;i<Jb;i++){var Kb=Gb._getChild(i);this.p_getPatternRuleIdsHelper(Kb,Hb,Ib);}}
else{var Lb=Gb._getRuleContextArray();for(var j=0;j<Lb.length;j++){var Mb=Lb[j].getId();if(!Ib[Mb]){Ib[Mb]=Mb;Hb.push(Mb);}}}};xmp.createNamespace("xmp.playlistapi");xmp.playlistapi.AdResourceOverrideContext=function(Nb,Ob){this.p_node=Nb;this.p_parameterMap=Ob;};xmp.playlistapi.AdResourceOverrideContext.prototype.getNode=function(){return this.p_node;};xmp.playlistapi.AdResourceOverrideContext.prototype.addResource=function(Pb){this.p_node.i_setMetaResource(Pb);};xmp.playlistapi.AdResourceOverrideContext.prototype.getResource=function(Qb){return this.p_node.getMetaResource(Qb);};xmp.playlistapi.AdResourceOverrideContext.prototype.copyMetaResourceBundleRefFrom=function(Rb){this.p_node.i_reSetMetaResourceBundle(Rb.i_getMetaResourceBundle());};xmp.playlistapi.AdResourceOverrideContext.prototype.copyMetaResourceBundleRefTo=function(Sb,Tb){Sb.i_reSetMetaResourceBundle(this.p_node.i_getMetaResourceBundle());if(Tb){Sb.i_setAssociatedResourceBundleTypes(Tb);}};xmp.playlistapi.AdResourceOverrideContext.prototype.expandString=function(Ub){return this.p_parameterMap.expandString(Ub);};xmp.playlistapi.AdResourceOverrideContext.prototype.setNodeAssociatedResourceBundleTypes=function(Vb){this.p_node.i_setAssociatedResourceBundleTypes(Vb);};xmp.createNamespace("xmp.playlistapi.internals");xmp.playlistapi.internals.AdPatternBuilder=function(Wb){xmp.validateArguments(arguments,[xmp.i_OBJECT_TYPE],"AdPatternBuilder.ctor");this.p_logger=new xmp.util.internals.CategoryLogger('AdPatternBuilder');this.p_COMPOSITE_TYPE_ARRAY=['Composite','ContentComposite'];this.p_patternMap=null;this.p_parameterMap=Wb;};xmp.playlistapi.internals.AdPatternBuilder.prototype._build=function(Xb){try{this.p_patternMap=Xb.patternMap;if(!this.p_isComposite(Xb.root)){throw new xmp.playlistapi.internals.PlayListError("Root of ad pattern must have type of one of the following: "+this.p_COMPOSITE_TYPE_ARRAY.join(', '));}
var Yb=this.p_buildHelper(Xb.root,true);Xb=null;return Yb;}
catch(e){e.stack=null;var Zb=new xmp.baseplayer.ApplicationError(e,'badAdPattern','AdPatternPlayList',[{label:'details',text:xmp.extractErrorMessage(e)}]);this.p_logger.warn(Zb.message,Zb);var $b="Error building Ad Pattern with memento data";throw new xmp.playlistapi.internals.PlayListError($b);}};xmp.playlistapi.internals.AdPatternBuilder.prototype.p_isComposite=function(ac){for(var i=0;i<this.p_COMPOSITE_TYPE_ARRAY.length;i++){if(ac.type===this.p_COMPOSITE_TYPE_ARRAY[i]){return true;}}
return false;};xmp.playlistapi.internals.AdPatternBuilder.prototype.p_buildHelper=function(bc,cc){var dc=null;if(this.p_isComposite(bc)){var ec=(typeof bc.repeat==="number")?bc.repeat:1;dc=new xmp.playlistapi.internals[bc.type+'PlayableNodeType'](bc,(cc?'/':this.p_calcId(bc)),bc.type,bc.pattern,ec);if(dc._isDeferred()){dc.i_setReadyToValidate(false);}
else{var fc=this.p_patternMap[dc._getPatternName()];this.p_buildChildren(dc,fc);}}
else{dc=new xmp.playlistapi.internals.RuleSetPlayableNodeType(bc,this.p_calcId(bc),bc.type,this.i_buildRuleContextArray(bc.rules,bc.type),this.i_extractOptionalMetaData(bc));this.p_extractOptionalResources(bc,dc);this.p_extractOptionalDirective(bc,dc);this.p_extractOptionalResourceDirective(bc,dc);}
dc.i_handlePostBuild();return dc;};xmp.playlistapi.internals.AdPatternBuilder.prototype.p_calcId=function(gc){return(typeof(gc.id)==='string')?gc.id:gc.type;};xmp.playlistapi.internals.AdPatternBuilder.prototype.p_extractOptionalDirective=function(hc,ic){var jc=xmp.playlistapi.internals.PatternDirectiveFactory.i_create(hc);ic.i_setDirective(jc);};xmp.playlistapi.internals.AdPatternBuilder.prototype.p_extractOptionalResourceDirective=function(kc,lc){var mc=xmp.playlistapi.internals.ResourceDirectiveFactory.i_create(kc);lc.i_setResourceDirective(mc);};xmp.playlistapi.internals.AdPatternBuilder.prototype.p_extractOptionalResources=function(nc,oc){if(typeof nc.resources==='object'){for(var i=0;i<nc.resources.length;i++){var pc=nc.resources[i];oc.i_setMetaResource(this.i_buildMetaResource(pc));}}};xmp.playlistapi.internals.AdPatternBuilder.prototype.p_buildChildren=function(qc,rc){for(var i=0;i<rc.length;i++){var sc=this.p_buildHelper(rc[i],false);qc._addChild(sc);}};xmp.playlistapi.internals.AdPatternBuilder.prototype.i_buildDeferredContentComposite=function(tc,uc){this.p_buildChildren(tc,uc);tc.i_setReadyToValidate(true);tc.i_handlePostBuild();};xmp.playlistapi.internals.AdPatternBuilder.prototype.i_buildRuleContextArray=function(vc,wc){var xc=[];if(typeof vc==="object"){for(var i=0;i<vc.length;i++){xc.push(this.p_buildRuleContext(vc[i],wc));}}
return xc;};xmp.playlistapi.internals.AdPatternBuilder.prototype.i_buildMetaResource=function(yc){return new xmp.playlistapi.Resource(this.p_parameterMap.expandStringAndFixSlashes(yc.id),yc.type,this.i_extractOptionalMetaData(yc),'default');};xmp.playlistapi.internals.AdPatternBuilder.prototype.p_buildRuleContext=function(zc,Ac){var Bc=[];if(Ac!==null){Bc.push(Ac);}
else{if(typeof zc.nodeTypes==="object"){Bc=Bc.concat(zc.nodeTypes);}}
return new xmp.playlistapi.RuleContext(this.p_parameterMap.expandString(zc.id),this.i_extractOptionalMetaData(zc),Bc,true);};xmp.playlistapi.internals.AdPatternBuilder.prototype.i_extractOptionalMetaData=function(Cc){var Dc={};if(typeof Cc.meta==="object"){for(var Ec=xmp.MapIterator.create(Cc.meta);Ec.hasNext();Ec.next()){var Fc=Ec.currentKey();var Gc=this.p_parameterMap.expandString(Ec.currentValue());Dc[Fc]=Gc;}}
return Dc;};xmp.createNamespace("xmp.playlistapi.internals");xmp.playlistapi.internals.CompositePlayableNodeType=function(Hc,id,Ic,Jc,Kc){xmp.validateArguments(arguments,[xmp.i_OBJECT_TYPE,xmp.i_STRING_TYPE,xmp.i_STRING_TYPE,xmp.i_STRING_TYPE,xmp.i_NUMBER_TYPE],"CompositePlayableNodeType.ctor");if(Jc===null||Jc.length===0){throw new xmp.util.internals.InvalidArgsError("CompositePlayableNodeType requires non-empty patternName.");}
if(Kc<1){throw new xmp.util.internals.InvalidArgsError("CompositePlayableNodeType must have a repeat count of 1 or greater.");}
this._patternName=Jc;this._repeatCount=Kc;this._children=[];xmp.playlistapi.internals.CompositePlayableNodeType.ctor.call(this,Hc,id,Ic);};xmp.DERIVE_CLASS(xmp.playlistapi.PlayableNodeType,xmp.playlistapi.internals.CompositePlayableNodeType);xmp.playlistapi.internals.CompositePlayableNodeType.prototype._getRepeatCount=function(){return this._repeatCount;};xmp.playlistapi.internals.CompositePlayableNodeType.prototype._isDeferred=function(){return(this._patternName.toLowerCase()==='deferred');};xmp.playlistapi.internals.CompositePlayableNodeType.prototype._getPatternName=function(){return this._patternName;};xmp.playlistapi.internals.CompositePlayableNodeType.prototype._getChildCount=function(){return this._children.length;};xmp.playlistapi.internals.CompositePlayableNodeType.prototype._getChild=function(Lc){xmp.validateArguments(arguments,[xmp.i_NUMBER_TYPE],"CompositePlayableNodeType._getChild");return this._children[Lc];};xmp.playlistapi.internals.CompositePlayableNodeType.prototype._addChild=function(Mc){var Nc=this._children.push(Mc);Mc.i_setParent(this);return Nc;};xmp.playlistapi.internals.CompositePlayableNodeType.prototype._isCompositeType=function(){return true;};xmp.playlistapi.internals.CompositePlayableNodeType.prototype._removeAllChildren=function(){this._children=[];};xmp.createNamespace("xmp.playlistapi.internals");xmp.playlistapi.internals.ContentCompositePlayableNodeType=function(Oc,id,Pc,Qc,Rc){xmp.playlistapi.internals.ContentCompositePlayableNodeType.ctor.call(this,Oc,id,Pc,Qc,Rc);this._readyToValidate=true;};xmp.DERIVE_CLASS(xmp.playlistapi.internals.CompositePlayableNodeType,xmp.playlistapi.internals.ContentCompositePlayableNodeType);xmp.playlistapi.internals.ContentCompositePlayableNodeType.prototype.i_setReadyToValidate=function(Sc){this._readyToValidate=Sc;};xmp.playlistapi.internals.ContentCompositePlayableNodeType.prototype.i_handlePostBuild=function(){if(!this._readyToValidate){return;}
function throwContentChildException(){throw new xmp.playlistapi.internals.PlayListError("ContentCompositePlayableNodeType must have one and only one node of type 'Content' (can have other leaf node types as well); cannot contain composite node types.");}
var Tc=-1;var Uc=this._getChildCount();for(var i=0;i<Uc;i++){var Vc=this._getChild(i);if(Vc._isCompositeType()){throwContentChildException();}
if(Vc.isContentType()){if(Tc===-1){Tc=i;}
else{throwContentChildException();}}}
if(Tc===-1){throwContentChildException();}};xmp.playlistapi.internals.ContentCompositePlayableNodeType.prototype.i_isContentCompositeType=function(){return true;};xmp.createNamespace("xmp.playlistapi.internals");xmp.playlistapi.internals.DefaultAdDataPatternDirective=function(Wc,Xc,Yc){xmp.playlistapi.internals.DefaultAdDataPatternDirective.ctor.call(this,Wc,Xc,Yc);};xmp.DERIVE_CLASS(xmp.playlistapi.internals.PatternDirective,xmp.playlistapi.internals.DefaultAdDataPatternDirective);xmp.playlistapi.internals.DefaultAdDataPatternDirective.prototype.doDirective=function(Zc,$c){var ad=this.getMetadata('refId','');var bd=this.getMetadata('defaultDataId','');if(ad.length===0||bd.length===0){throw new xmp.playlistapi.internals.PlayListError("Directive '"+this.getType()+"' requires metadata 'refId' and 'defaultDataId'.");}
var cd=this.i_findNamedContentNode(Zc,$c,ad);var dd=cd.getPlayableData().getDataObject().adDataMap;if(typeof dd!=='object'){throw new xmp.playlistapi.internals.PlayListError("Did not find 'adDataMap' for content node: "+cd.getBestId());}
var ed=dd[bd];if(typeof ed!=='object'){throw new xmp.playlistapi.internals.PlayListError("Did not find '"+bd+"' in 'adDataMap' for content node: "+cd.getBestId());}
var fd=Zc.i_getParameterMapInternal().clone();fd.setOverrides(this.i_getParameterArray());fd.addContextObject('video',cd.getPlayableData().getDataObject());fd.addContextObject('node',$c.getNodeType().getDataObject());var gd=new xmp.playlistapi.internals.AdPatternBuilder(fd);if(typeof ed.resources==='object'){for(var i=0;i<ed.resources.length;i++){var hd=ed.resources[i];$c.i_setMetaResource(gd.i_buildMetaResource(hd));}}
var jd=gd.i_extractOptionalMetaData(ed);for(var kd=xmp.MapIterator.create(jd);kd.hasNext();kd.next()){var ld=kd.currentKey();var md=kd.currentValue();$c.setMetadata(ld,md);}
$c.setMetadata('__DIRECTIVE_PARAMETER_MAP__',fd);};xmp.createNamespace("xmp.playlistapi.internals");xmp.playlistapi.internals.NullPatternDirective=function(){};xmp.playlistapi.internals.NullPatternDirective.p_flyWeight=new xmp.playlistapi.internals.NullPatternDirective();xmp.playlistapi.internals.NullPatternDirective.getNull=function(){return xmp.playlistapi.internals.NullPatternDirective.p_flyWeight;};xmp.playlistapi.internals.NullPatternDirective.prototype.getType=function(){return'Null';};xmp.playlistapi.internals.NullPatternDirective.prototype.doDirective=function(nd,od){};xmp.createNamespace("xmp.playlistapi.internals");xmp.playlistapi.internals.NullResourceDirective=function(){};xmp.playlistapi.internals.NullResourceDirective.p_flyWeight=new xmp.playlistapi.internals.NullResourceDirective();xmp.playlistapi.internals.NullResourceDirective.i_getNull=function(){return xmp.playlistapi.internals.NullResourceDirective.p_flyWeight;};xmp.playlistapi.internals.NullResourceDirective.prototype.i_getType=function(){return'Null';};xmp.playlistapi.internals.NullResourceDirective.prototype.i_doDirective=function(pd,qd){};xmp.createNamespace("xmp.playlistapi.internals");xmp.playlistapi.internals.ParameterMap=function(){this._logger=new xmp.util.internals.CategoryLogger('ParameterMap');this._map={};this._contextObjectMap={};};xmp.playlistapi.internals.ParameterMap.calcInitial=function(rd,sd){xmp.validateArguments(arguments,[xmp.i_OBJECT_TYPE,xmp.i_OBJECT_TYPE],"ParameterMap.calcInitial");var td=new xmp.playlistapi.internals.ParameterMap();td.init(rd);td.setOverrides(sd);return td;};xmp.playlistapi.internals.ParameterMap.prototype.clone=function(){var ud=new xmp.playlistapi.internals.ParameterMap();ud._cloneInternal(this._map);return ud;};xmp.playlistapi.internals.ParameterMap.prototype.init=function(vd){this._map=this._mapParameters((typeof vd.parameters==='object')?vd.parameters:[]);};xmp.playlistapi.internals.ParameterMap.prototype.setOverrides=function(wd){this._validateParameters(wd);for(var i=0;i<wd.length;i++){var p=wd[i];if(typeof this._map[p.name]==='undefined'){this._logger.warn('Pattern input parameter dropped, no default value in pattern: '+p.name);continue;}
this._map[p.name]=p.value;}};xmp.playlistapi.internals.ParameterMap.prototype.expandStringAndFixSlashes=function(xd){var yd='://';var zd=this.expandString(xd);var Ad='';var Bd=zd;if(zd.indexOf(yd)>-1){var Cd=zd.split(yd);Ad=Cd[0]+yd;Bd=Cd[1];}
while(Bd.indexOf('//')>-1){Bd=Bd.replace(/\/\//g,'/');}
return Ad+Bd;};xmp.playlistapi.internals.ParameterMap.prototype.expandString=function(Dd){if(typeof Dd!=='string'){return Dd;}
if(Dd.indexOf('${')!==-1){var Ed=false;if(Dd.indexOf('$${')!==-1){Dd=Dd.replace(/\$\$\{/g,'__PROTECT_DOLLAR_ESCAPE__');Ed=true;}
Dd=Dd.replace(/\$\{player./g,'${');for(var Fd=xmp.MapIterator.create(this._map);Fd.hasNext();Fd.next()){var Gd=Fd.currentKey();var Hd=Fd.currentValue();var Id='${'+Gd+'}';if(Dd.indexOf(Id)!==-1){var Jd=Dd.split(Id);Dd=Jd.join(Hd);}}
Dd=this._makeContextObjectSubs(Dd);if(Ed){Dd=Dd.replace(/__PROTECT_DOLLAR_ESCAPE__/g,'${');}}
return Dd;};xmp.playlistapi.internals.ParameterMap.prototype._makeContextObjectSubs=function(Kd){var Ld=0;var Md=true;while(Md){var Nd=Kd.indexOf('${',Ld);if(Nd===-1){Md=false;break;}
var Od=Kd.indexOf('}',Nd+1);if(Od===-1){Md=false;break;}
Ld=Od+1;var Pd=Kd.substr(0,Nd);var Qd=Kd.substr(Od+1);var Rd=Kd.substr(Nd+2,Od-Nd-2);var Sd=Rd.indexOf('.');if(Sd===-1){continue;}
var Td=Rd.substr(0,Sd);var Ud=Rd.substr(Sd+1);var Vd=this._contextObjectMap[Td];if(!Vd){continue;}
var Wd=null;try{Wd=xmp.util.JsonPath.evaluate(Vd,Ud);}
catch(e){Wd=null;this._logger.warn('Error evaluating JSON Path: '+Ud,e);}
if(Wd!==null){var Xd=Kd.length;Kd=Pd+Wd+Qd;Ld+=(Kd.length-Xd);}}
return Kd;};xmp.playlistapi.internals.ParameterMap.prototype.addContextObject=function(Yd,Zd){this._contextObjectMap[Yd]=Zd;};xmp.playlistapi.internals.ParameterMap.prototype._validateParameters=function($d){for(var i=0;i<$d.length;i++){var p=$d[i];if(!((typeof p.name==='string')&&(p.name.length>0)&&(typeof p.value==='string'))){throw new xmp.playlistapi.internals.PlayListError("Parameters must have string 'name and 'value' properties.");}}};xmp.playlistapi.internals.ParameterMap.prototype._mapParameters=function(ae){this._validateParameters(ae);var be={};for(var i=0;i<ae.length;i++){var p=ae[i];be[p.name]=p.value;}
return be;};xmp.playlistapi.internals.ParameterMap.prototype._cloneInternal=function(ce){for(var de=xmp.MapIterator.create(ce);de.hasNext();de.next()){var ee=de.currentKey();var fe=de.currentValue();this._map[ee]=fe;}};xmp.createNamespace("xmp.playlistapi.internals");xmp.playlistapi.internals.PatternDirectiveFactory=function(){};xmp.playlistapi.internals.PatternDirectiveFactory.p_ctors=null;xmp.playlistapi.internals.PatternDirectiveFactory.i_create=function(ge){if(xmp.playlistapi.internals.PatternDirectiveFactory.p_ctors===null){xmp.playlistapi.internals.PatternDirectiveFactory.p_ctors={};var he=xmp.playlistapi.internals.PatternDirectiveFactory.p_ctors;he.defaultAdData=xmp.playlistapi.internals.DefaultAdDataPatternDirective;}
if(typeof ge.patternDirective==='object'){var ie=xmp.playlistapi.internals.PatternDirectiveFactory.p_ctors[ge.patternDirective.type];if(ie){var je=ge.patternDirective.parameters;je=(!je)?[]:je;var ke=ge.patternDirective.meta;ke=(!ke)?{}:ke;return new ie(ge.patternDirective.type,ke,je);}
else{throw new xmp.util.internals.InvalidArgsError('Unknown directive type: '+ge.patternDirective.type);}}
else{return xmp.playlistapi.internals.NullPatternDirective.getNull();}};xmp.createNamespace("xmp.playlistapi.internals");xmp.playlistapi.internals.PlayListAddress=function(){this._array=[];};xmp.playlistapi.internals.PlayListAddress.prototype.getLength=function(){return this._array.length;};xmp.playlistapi.internals.PlayListAddress.prototype.clone=function(){var le=new xmp.playlistapi.internals.PlayListAddress();le._cloneInternal(this._array);return le;};xmp.playlistapi.internals.PlayListAddress.prototype._cloneInternal=function(me){this._array=this._array.concat(me);};xmp.playlistapi.internals.PlayListAddress.prototype.getAtIndex=function(ne){return this._array[ne];};xmp.playlistapi.internals.PlayListAddress.prototype.shift=function(){return this._array.shift();};xmp.playlistapi.internals.PlayListAddress.prototype.push=function(oe){return this._array.push(oe);};xmp.playlistapi.internals.PlayListAddress.prototype.pop=function(){return this._array.pop();};xmp.playlistapi.internals.PlayListAddress.prototype.getParent=function(){var pe=this.clone();pe.pop();return pe;};xmp.playlistapi.internals.PlayListAddress.prototype.isSibling=function(qe,re){var se=this.getLength();if(se!==qe.getLength()){return false;}
for(var i=0;i<se;i++){var te=this.getAtIndex(i);var ue=qe.getAtIndex(i);if(i<(se-1)){if(!te.isEqual(ue)){return false;}}
else{if(re){if(te.i_getRepeatIndex()!==ue.i_getRepeatIndex()){return false;}}}}
return true;};xmp.playlistapi.internals.PlayListAddress.prototype.i_asString=function(){var s='';var ve=this.getLength();for(var i=0;i<ve;i++){var we=this.getAtIndex(i);s+=we.i_asString();if(i!==(ve-1)){s+=',';}}
return s;};xmp.createNamespace("xmp.playlistapi.internals");xmp.playlistapi.internals.PlayListAddressPart=function(xe,ye){this.p_repeatIndex=xe;this.p_childIndex=ye;};xmp.playlistapi.internals.PlayListAddressPart.prototype.i_getRepeatIndex=function(){return this.p_repeatIndex;};xmp.playlistapi.internals.PlayListAddressPart.prototype.i_getChildIndex=function(){return this.p_childIndex;};xmp.playlistapi.internals.PlayListAddressPart.prototype.isEqual=function(ze){return(ze.i_getRepeatIndex()===this.i_getRepeatIndex()&&ze.i_getChildIndex()===this.i_getChildIndex());};xmp.playlistapi.internals.PlayListAddressPart.prototype.i_asString=function(){return('['+this.p_repeatIndex+','+this.p_childIndex+']');};xmp.createNamespace("xmp.playlistapi.internals");xmp.playlistapi.internals.PlayListBuilder=function(Ae,Be,Ce,De,Ee){try{this.p_STATE_TRAVERSE_TO_ADDRESS=0;this.p_STATE_TRAVERSE_TO_NEXT=1;this.p_STATE_BUILD=2;this.p_logger=new xmp.util.internals.CategoryLogger('PlayListBuilder');this.p_playList=Ae;this.p_playableDataProvider=Ee;this.p_contentMetaResourceIdArray=[];this.p_playListDataArray=[];this.p_traverseToPatternAddress=new xmp.playlistapi.internals.PlayListAddress();this.p_build_state=this.p_STATE_TRAVERSE_TO_ADDRESS;this.p_assignPatternAddress=new xmp.playlistapi.internals.PlayListAddress();this.p_contentCompositeIdToContentNodeMap={};this.p_parentIdCounter=0;this.p_contentMetaResourceIdArray=this.p_contentMetaResourceIdArray.concat(De);if(Be!==null){this.p_traverseToPatternAddress=Be.i_getPatternAddress().clone();}
if(this.p_traverseToPatternAddress.getLength()===0){this.p_build_state=this.p_STATE_BUILD;}
this.p_buildHelper(Ce,0);this.p_initializeNodes();}
catch(e){var Fe="Error building playlist with meta resource IDs";this.p_logger.warn(Fe,e);Fe+=", error = ";Fe+=xmp.extractErrorMessage(e);throw new xmp.playlistapi.internals.PlayListError(Fe);}};xmp.playlistapi.internals.PlayListBuilder.prototype.i_getOutput=function(){var Ge=[];for(var i=0;i<this.p_playListDataArray.length;i++){var He=this.p_playListDataArray[i];var Ie=He[0];Ge.push(Ie);}
if(this.p_logger.isDebugEnabled()){var Je='Node output: ';for(var j=0;j<Ge.length;j++){Je+=('('+j.toString()+') ');Je+=Ge[j].getBestId();Je+=('('+Ge[j].i_getPatternAddress().i_asString()+')');if(j!==(Ge.length-1)){Je+=', ';}}
this.p_logger.debug(Je);}
return Ge;};xmp.playlistapi.internals.PlayListBuilder.prototype.p_buildHelper=function(Ke,Le){if(Ke._isCompositeType()){var Me=0;var Ne=0;if(this.p_build_state===this.p_STATE_TRAVERSE_TO_ADDRESS){var Oe=this.p_traverseToPatternAddress.shift();Me=Oe.i_getRepeatIndex();Ne=Oe.i_getChildIndex();if(this.p_traverseToPatternAddress.getLength()===0){this.p_build_state=this.p_STATE_TRAVERSE_TO_NEXT;}}
if(this.p_build_state!==this.p_STATE_TRAVERSE_TO_ADDRESS&&Ke._isDeferred()){Ke=this.p_buildDeferredContentComposite(Ke);}
var Pe=Ke._getRepeatCount();var Qe=Ke._getChildCount();for(var Re=Me;Re<Pe;Re++){if(this.p_contentMetaResourceIdArray.length===0){break;}
this.p_parentIdCounter++;if(this.p_build_state===this.p_STATE_BUILD){Ne=0;}
for(var Se=Ne;Se<Qe;Se++){var Te=Ke._getChild(Se);this.p_assignPatternAddress.push(new xmp.playlistapi.internals.PlayListAddressPart(Re,Se));this.p_buildHelper(Te,this.p_parentIdCounter);this.p_assignPatternAddress.pop();}}}
else{if(this.p_build_state===this.p_STATE_BUILD){this.p_buildLeaf(Ke,Le);}
else if(this.p_build_state===this.p_STATE_TRAVERSE_TO_NEXT){this.p_build_state=this.p_STATE_BUILD;}}};xmp.playlistapi.internals.PlayListBuilder.prototype.p_buildLeaf=function(Ue,Ve){var We=this.p_playList.i_createNode();if(Ue.isContentType()){if(this.p_contentMetaResourceIdArray.length===0){We.i_mutateEmptySlot(true);We.i_setData(new xmp.util.PlayableData('EMPTY_SLOT'));}
else{var Xe=this.p_contentMetaResourceIdArray.shift();We.i_linkData(this.p_playableDataProvider,Xe);}}
We.i_setNodeType(Ue);We.i_setPatternAddress(this.p_assignPatternAddress.clone());if(We.isContentType()&&We.getNodeType()._getParent().i_isContentCompositeType()){We.getPlayableData().i_setCompositeMetaResourceId(We.getPlayableData().getMetaResourceId());this.p_contentCompositeIdToContentNodeMap[Ve.toString()]=We;}
this.p_playListDataArray.push([We,Ve]);};xmp.playlistapi.internals.PlayListBuilder.prototype.p_initializeNodes=function(){this.p_doNodePatternDirectives();this.p_doNodeResourceDirectives();this.p_doNodeFixupsAndInitialization();};xmp.playlistapi.internals.PlayListBuilder.prototype.p_doNodePatternDirectives=function(){for(var i=0;i<this.p_playListDataArray.length;i++){var Ye=this.p_playListDataArray[i];var Ze=Ye[0];try{Ze.getNodeType().i_getDirective().doDirective(this,Ze);}
catch(e){var $e=new xmp.baseplayer.ApplicationError(e,'badAdPattern',null,[{label:'cause',text:e.message}]);this.p_logger.warn($e.message,$e);}}};xmp.playlistapi.internals.PlayListBuilder.prototype.p_doNodeResourceDirectives=function(){for(var i=0;i<this.p_playListDataArray.length;i++){var af=this.p_playListDataArray[i];var bf=af[0];try{bf.getNodeType().i_getResourceDirective().i_doDirective(this,bf);}
catch(e){var cf=new xmp.baseplayer.ApplicationError(e,'badAdPattern',null,[{label:'cause',text:e.message}]);this.p_logger.warn(cf.message,cf);}}};xmp.playlistapi.internals.PlayListBuilder.prototype.p_doNodeFixupsAndInitialization=function(){for(var i=0;i<this.p_playListDataArray.length;i++){var df=this.p_playListDataArray[i];var ef=df[0];var ff=df[1];if(ef.getPlayableData()===null){var gf=ef.i_getPrimaryMetaResource(false);ef.i_setData(new xmp.util.PlayableData((gf)?gf.getId():''));}
if(!ef.isContentType()&&ef.getNodeType()._getParent().i_isContentCompositeType()){this.p_fixContentCompositeSibling(ef,ff);}
if(!ef.i_isEmptySlot()&&!ef.getPlayableData().isError()){this.p_playList.i_initializeNode(ef);}}};xmp.playlistapi.internals.PlayListBuilder.prototype.p_fixContentCompositeSibling=function(hf,jf){var kf=this.p_contentCompositeIdToContentNodeMap[jf.toString()];if(kf.i_isEmptySlot()){hf.i_mutateEmptySlot(true);}
hf.getPlayableData().i_setCompositeMetaResourceId(kf.getPlayableData().getCompositeMetaResourceId());};xmp.playlistapi.internals.PlayListBuilder.prototype.p_buildDeferredContentComposite=function(lf){lf._removeAllChildren();if(this.p_contentMetaResourceIdArray.length>0){var mf=this.p_contentMetaResourceIdArray[0];var nf=this.p_playableDataProvider.getPlayableData(mf);var of=null;if(nf.isError()){of=[{type:'Content'}];}
else{of=nf.getDataObject().pattern;}
var pf=new xmp.playlistapi.internals.AdPatternBuilder(this.p_playList.i_getParameterMapInternal());pf.i_buildDeferredContentComposite(lf,of);}
return lf;};xmp.playlistapi.internals.PlayListBuilder.prototype.i_getParameterMapInternal=function(){return this.p_playList.i_getParameterMapInternal();};xmp.playlistapi.internals.PlayListBuilder.prototype.i_getPlayListDataArrayLength=function(){return this.p_playListDataArray.length;};xmp.playlistapi.internals.PlayListBuilder.prototype.i_getPlayListDataArrayItemAtIndex=function(qf){var rf=this.p_playListDataArray[qf];return rf[0];};xmp.playlistapi.internals.PlayListBuilder.prototype.i_getDataIterator=function(){return(new xmp.playlistapi.internals.PlayListBuilder.Iterator(this));};xmp.playlistapi.internals.PlayListBuilder.prototype.i_getHistoricalDataIterator=function(){return this.p_playList.i_getHistoricalDataIterator();};xmp.playlistapi.internals.PlayListBuilder.Iterator=function(sf){this.p_playListBuilder=sf;this.p_curIndex=0;};xmp.playlistapi.internals.PlayListBuilder.Iterator.prototype.getLength=function(){return this.p_playListBuilder.i_getPlayListDataArrayLength();};xmp.playlistapi.internals.PlayListBuilder.Iterator.prototype.first=function(){this.p_curIndex=0;};xmp.playlistapi.internals.PlayListBuilder.Iterator.prototype.next=function(){var tf=this.p_playListBuilder.i_getPlayListDataArrayItemAtIndex(this.p_curIndex);this.p_curIndex++;return tf;};xmp.playlistapi.internals.PlayListBuilder.Iterator.prototype.hasNext=function(){return(this.p_curIndex<this.getLength());};xmp.createNamespace("xmp.playlistapi.internals");xmp.playlistapi.internals.PlayListError=function(uf){this.name="xmp.playlistapi.internals.PlayListError";this.message=uf;};xmp.DERIVE_CLASS(Error,xmp.playlistapi.internals.PlayListError);xmp.createNamespace("xmp.playlistapi.internals");xmp.playlistapi.internals.ResourceDirectiveFactory=function(){};xmp.playlistapi.internals.ResourceDirectiveFactory.p_ctors=null;xmp.playlistapi.internals.ResourceDirectiveFactory.i_create=function(vf){if(xmp.playlistapi.internals.ResourceDirectiveFactory.p_ctors===null){xmp.playlistapi.internals.ResourceDirectiveFactory.p_ctors={};var wf=xmp.playlistapi.internals.ResourceDirectiveFactory.p_ctors;wf.shareResources=xmp.playlistapi.internals.ShareResourcesResourceDirective;}
if(typeof vf.resourceDirective==='object'){var xf=xmp.playlistapi.internals.ResourceDirectiveFactory.p_ctors[vf.resourceDirective.type];if(xf){var yf=vf.resourceDirective.meta;yf=(!yf)?{}:yf;return new xf(vf.resourceDirective.type,yf);}
else{throw new xmp.util.internals.InvalidArgsError('Unknown resource directive type: '+vf.resourceDirective.type);}}
else{return xmp.playlistapi.internals.NullResourceDirective.i_getNull();}};xmp.createNamespace("xmp.playlistapi.internals");xmp.playlistapi.internals.RuleSetPlayableNodeType=function(zf,id,Af,Bf,Cf){xmp.validateArguments(arguments,[xmp.i_OBJECT_TYPE,xmp.i_STRING_TYPE,xmp.i_STRING_TYPE,xmp.i_OBJECT_TYPE,xmp.i_OBJECT_TYPE],"RuleSetPlayableNodeType.ctor");this._metadataMap=new xmp.util.internals.MetadataMap(true);this._metadataMap.i_reInitialize(Cf);this._ruleContextArray=Bf;this._metaResourceBundle=new xmp.playlistapi.ResouceBundle();xmp.playlistapi.internals.RuleSetPlayableNodeType.ctor.call(this,zf,id,Af);};xmp.DERIVE_CLASS(xmp.playlistapi.PlayableNodeType,xmp.playlistapi.internals.RuleSetPlayableNodeType);xmp.playlistapi.internals.RuleSetPlayableNodeType.prototype.i_setMetaResource=function(Df){this._metaResourceBundle.i_setMetaResource(Df);};xmp.playlistapi.internals.RuleSetPlayableNodeType.prototype.i_getMetaResource=function(Ef){return this._metaResourceBundle.i_getMetaResource(Ef);};xmp.playlistapi.internals.RuleSetPlayableNodeType.prototype.i_getMetaResourceBundle=function(){return this._metaResourceBundle;};xmp.playlistapi.internals.RuleSetPlayableNodeType.prototype.getMetadata=function(Ff,Gf){return this._metadataMap.i_get(Ff,Gf);};xmp.playlistapi.internals.RuleSetPlayableNodeType.prototype._getRuleContextArray=function(){return this._ruleContextArray;};xmp.playlistapi.internals.RuleSetPlayableNodeType.prototype._getMetadataMapRef=function(){return this._metadataMap;};xmp.createNamespace("xmp.playlistapi.internals");xmp.playlistapi.internals.ShareResourcesResourceDirective=function(Hf,If){xmp.validateArguments(arguments,[xmp.i_STRING_TYPE,xmp.i_OBJECT_TYPE],"ShareResourcesResourceDirective.ctor");if(!xmp.isNonEmptyString(Hf)){throw new xmp.util.internals.InvalidArgsError("Argument 'type' must be a non-empty string.");}
this.p_type=Hf;this.p_metadataMap=new xmp.util.internals.MetadataMap(true);this.p_metadataMap.i_reInitialize(If);};xmp.playlistapi.internals.ShareResourcesResourceDirective.prototype.i_getType=function(){return this.p_type;};xmp.playlistapi.internals.ShareResourcesResourceDirective.prototype.p_getMetadata=function(Jf,Kf){return this.p_metadataMap.i_get(Jf,Kf);};xmp.playlistapi.internals.ShareResourcesResourceDirective.prototype.i_doDirective=function(Lf,Mf){if(this.p_isNodeMarked(Mf)){return;}
var Nf=this.p_findSharedNodes(Lf,Mf);if(Nf.length===0){return;}
this.p_shareResources(Nf);var Of=this.p_getAssociationMap(Nf);this.p_setAssociatedResourceBundleTypes(Nf,Of);this.p_markNodes(Nf);};xmp.playlistapi.internals.ShareResourcesResourceDirective.prototype.p_shareResources=function(Pf){var Qf=Pf[0];var Rf=Qf.i_getMetaResourceBundle();for(var i=1;i<Pf.length;i++){var Sf=Pf[i];var Tf=Sf.i_getMetaResourceBundle().clone();Sf.i_reSetMetaResourceBundle(Rf);this.p_mergeResBundles(Rf,Tf);}};xmp.playlistapi.internals.ShareResourcesResourceDirective.prototype.p_mergeResBundles=function(Uf,Vf){var Wf=Vf.i_getResourceTypes();for(var i=0;i<Wf.length;i++){Uf.i_setMetaResource(Vf.i_getMetaResource(Wf[i]));}};xmp.playlistapi.internals.ShareResourcesResourceDirective.prototype.p_getAssociationMap=function(Xf){var Yf=[];for(var i=0;i<Xf.length;i++){var Zf=Xf[i];var $f=Zf.getNodeType().i_getResourceDirective().p_getAssociatedResourceTypeMap();if($f!==null){Yf.push($f);}}
return this.p_getMergedAssociationMap(Yf);};xmp.playlistapi.internals.ShareResourcesResourceDirective.prototype.p_getMergedAssociationMap=function(ag){if(ag.length===0){return{};}
var bg=ag[0];for(var i=1;i<ag.length;i++){var cg=ag[i];for(var dg=xmp.MapIterator.create(cg);dg.hasNext();dg.next()){var eg=dg.currentKey();var fg=dg.currentValue();bg[eg]=fg;}}
return bg;};xmp.playlistapi.internals.ShareResourcesResourceDirective.prototype.p_setAssociatedResourceBundleTypes=function(gg,hg){var ig="Resource Directive '"+this.i_getType()+"' requires that if metadata 'nodeTypeToResTypesMap' is specified, it ia map of strings (node types) to arrays of strings (resource types).";for(var i=0;i<gg.length;i++){var jg=gg[i];var kg=hg[jg.getNodeTypeName()];if(kg){if(!(kg instanceof Array)){throw new xmp.playlistapi.internals.PlayListError(ig);}
for(var j=0;j<kg.length;j++){if(!xmp.isNonEmptyString(kg[j])){throw new xmp.playlistapi.internals.PlayListError(ig);}}
jg.i_setAssociatedResourceBundleTypes(kg);}}};xmp.playlistapi.internals.ShareResourcesResourceDirective.prototype.p_markNodes=function(lg){for(var i=0;i<lg.length;i++){this.p_markNode(lg[i]);}};xmp.playlistapi.internals.ShareResourcesResourceDirective.prototype.p_markNode=function(mg){mg.setMetadata('__RESOURCE_DIRECTIVE_COMPLETE__','true');};xmp.playlistapi.internals.ShareResourcesResourceDirective.prototype.p_isNodeMarked=function(ng){return(ng.getMetadata('__RESOURCE_DIRECTIVE_COMPLETE__','false')==='true');};xmp.playlistapi.internals.ShareResourcesResourceDirective.prototype.p_findSharedNodes=function(og,pg){var qg=this.p_findSharedNodesFromIterator(og.i_getHistoricalDataIterator(),pg);var rg=this.p_findSharedNodesFromIterator(og.i_getDataIterator(),pg);var sg=qg.concat(rg);var tg=[];var ug={};for(var i=0;i<sg.length;i++){var vg=sg[i];if(typeof(ug[vg.getUniqueId()])==='undefined'){tg.push(vg);ug[vg.getUniqueId()]=vg;}}
return tg;};xmp.playlistapi.internals.ShareResourcesResourceDirective.prototype.p_findSharedNodesFromIterator=function(wg,xg){var yg=[];wg.first();while(wg.hasNext()){var zg=wg.next();if(!zg.isValid()){continue;}
var Ag=zg.getNodeType().i_getResourceDirective();if(Ag.i_getType()!==this.i_getType()){continue;}
if(!zg.i_getPatternAddress().isSibling(xg.i_getPatternAddress(),true)){continue;}
if(this.p_getSharedId()===Ag.p_getSharedId()){yg.push(zg);}}
return yg;};xmp.playlistapi.internals.ShareResourcesResourceDirective.prototype.p_getSharedId=function(){var Bg=this.p_getMetadata('shareId','');if(Bg.length===0){throw new xmp.playlistapi.internals.PlayListError("Resource Directive '"+this.i_getType()+"' requires metadata 'shareId'.");}
return Bg;};xmp.playlistapi.internals.ShareResourcesResourceDirective.prototype.p_getAssociatedResourceTypeMap=function(){var Cg=this.p_getMetadata('nodeTypeToResTypesMap',this);if(Cg===this){return null;}
return Cg;};xmp.createNamespace("xmp.playlistapi.internals");xmp.playlistapi.internals.SimplePlayListIterator=function(Dg){this._playListArray=Dg;this._curIndex=-1;};xmp.playlistapi.internals.SimplePlayListIterator.prototype.getLength=function(){return this._playListArray.length;};xmp.playlistapi.internals.SimplePlayListIterator.prototype.first=function(){this._curIndex=0;};xmp.playlistapi.internals.SimplePlayListIterator.prototype.next=function(){var Eg=this._playListArray[this._curIndex];this._curIndex++;return Eg;};xmp.playlistapi.internals.SimplePlayListIterator.prototype.hasNext=function(){return(this._curIndex<this.getLength());};xmp.createNamespace("xmp.playlistapi");xmp.playlistapi.PlayListIterator=function(Fg){this.p_playList=Fg;this.p_currentNode=null;this.p_initialized=false;this.p_canAdvance=true;};xmp.playlistapi.PlayListIterator.prototype.first=function(){this.p_initialized=true;this.p_canAdvance=true;};xmp.playlistapi.PlayListIterator.prototype.next=function(){if(!this.hasNext()){throw new xmp.playlistapi.internals.PlayListError("Cannot call next if there are no more items to be returned, call 'hasNext' method to check.");}
this.p_canAdvance=true;return this.p_currentNode;};xmp.playlistapi.PlayListIterator.prototype.hasNext=function(){this.p_checkInitialized();if(this.p_canAdvance){this.p_currentNode=this.p_getNextCore();this.p_canAdvance=false;}
return(this.p_currentNode!==null);};xmp.playlistapi.PlayListIterator.prototype.p_getNextCore=function(){try{this.p_playList.i_checkLockedForModification();this.p_playList.i_lockForModification();return this.p_playList.i_getNextRuleFilteredPlayableNode();}
finally{this.p_playList.i_unlockForModification();}};xmp.playlistapi.PlayListIterator.prototype.p_checkInitialized=function(){if(!this.p_initialized){throw new xmp.playlistapi.internals.PlayListError("Iterator not initialized, call 'first' method.");}};xmp.createNamespace("xmp.playlistapi");xmp.playlistapi.ResouceBundle=function(){xmp.playlistapi.ResouceBundle.ctor.call(this);this.p_map={};this.p_array=[];};xmp.DERIVE_CLASS(xmp.util.Loadable,xmp.playlistapi.ResouceBundle);xmp.playlistapi.ResouceBundle.prototype.i_setMetaResource=function(Gg){if(this.i_getMetaResource(Gg.getType())!==null){throw new xmp.util.internals.InvalidArgsError('Node type already has a resource of type: '+Gg.getType());}
this.p_map[Gg.getType()]=Gg;this.p_array.push(Gg);};xmp.playlistapi.ResouceBundle.prototype.i_getMetaResource=function(Hg){var Ig=this.p_map[Hg];return(Ig)?Ig:null;};xmp.playlistapi.ResouceBundle.prototype.i_getResourceTypes=function(){return xmp.MapIterator.extractKeys(this.p_map);};xmp.playlistapi.ResouceBundle.prototype.i_getCount=function(){return(this.i_getResourceTypes().length);};xmp.playlistapi.ResouceBundle.prototype.clone=function(){var Jg=new xmp.playlistapi.ResouceBundle();for(var Kg=xmp.MapIterator.create(this.p_map);Kg.hasNext();Kg.next()){var Lg=Kg.currentKey();var Mg=this.i_getMetaResource(Lg);Jg.i_setMetaResource(Mg.i_clone());}
return Jg;};xmp.playlistapi.ResouceBundle.prototype.getLoadableId=function(){return'ResouceBundle';};xmp.playlistapi.ResouceBundle.prototype.i_getErrorCount=function(){var Ng=this.i_getResourceTypes();var Og=0;for(var i=0;i<Ng.length;i++){var Pg=Ng[i];var Qg=this.i_getMetaResource(Pg);if(Qg.isError()){Og++;}}
return Og;};xmp.playlistapi.ResouceBundle.i_getDataType=function(Rg){var Sg=xmp.util.SettingsManager.getInstance().getContextNode().getNodeForPath('ad resource metadata/'+Rg);return Sg.getString('data type','default');};xmp.playlistapi.ResouceBundle.i_getRenderer=function(Tg){var Ug=xmp.util.SettingsManager.getInstance().getContextNode().getNodeForPath('ad resource metadata/'+Tg);return Ug.getString('renderer','dummy');};xmp.playlistapi.ResouceBundle.i_filterByRenderer=function(Vg,Wg){var Xg=[];for(var i=0;i<Vg.length;i++){var Yg=Vg[i];if(Wg===xmp.playlistapi.ResouceBundle.i_getRenderer(Yg)){Xg.push(Yg);}}
return Xg;};xmp.playlistapi.ResouceBundle.prototype.i_getAssociatedResourceBundleTypes=function(Zg){var $g=[];for(var i=0;i<this.p_array.length;i++){var ah=this.p_array[i];if(Zg===ah.i_getAssociationId()){$g.push(ah.getType());}}
return $g;};xmp.playlistapi.ResouceBundle.prototype.i_setAssociatedResourceBundleTypes=function(bh,ch){if(!(ch instanceof Array)){throw new xmp.util.internals.InvalidArgsError("Invalid associated resource bundle types - must be an array of non-empty strings.");}
for(var i=0;i<ch.length;i++){var dh=this.i_getMetaResource(ch[i]);if(dh!==null){dh.i_setAssociationId(bh);}}};xmp.createNamespace("xmp.playlistapi");xmp.playlistapi.Resource=function(id,eh,fh,gh){xmp.playlistapi.Resource.ctor.call(this);if(!fh){fh={};}
if(!gh){gh='default';}
xmp.validateArguments([id,eh,fh,gh],[xmp.i_STRING_TYPE,xmp.i_STRING_TYPE,xmp.i_OBJECT_TYPE,xmp.i_STRING_TYPE],"Resource.ctor");if(!(xmp.isNonEmptyString(id)&&xmp.isNonEmptyString(eh)&&xmp.isNonEmptyString(gh))){throw new xmp.util.internals.InvalidArgsError("Parameters 'id' and 'type' and 'dataType' must be non-empty strings.");}
this.p_id=id;this.p_type=eh;this.p_dataType=gh;this.p_metadataMap=new xmp.util.internals.MetadataMap(false);this.p_metadataMap.i_reInitialize(fh);this.p_companionAdId=-1;this.p_associationId=-1;};xmp.DERIVE_CLASS(xmp.util.Loadable,xmp.playlistapi.Resource);xmp.playlistapi.Resource.prototype.getId=function(){return this.p_id;};xmp.playlistapi.Resource.prototype.setId=function(id){this.p_id=id;};xmp.playlistapi.Resource.prototype.getType=function(){return this.p_type;};xmp.playlistapi.Resource.prototype.getDataType=function(){return this.p_dataType;};xmp.playlistapi.Resource.prototype.i_setDataType=function(hh){this.p_dataType=hh;};xmp.playlistapi.Resource.prototype.getMetadata=function(ih,jh){return this.p_metadataMap.i_get(ih,jh);};xmp.playlistapi.Resource.prototype.setMetadata=function(kh,lh){this.p_metadataMap.i_set(kh,lh);};xmp.playlistapi.Resource.prototype.removeMetadata=function(mh){this.p_metadataMap.i_remove(mh);};xmp.playlistapi.Resource.prototype.i_clone=function(){return new xmp.playlistapi.Resource(this.p_id,this.p_type,this.p_metadataMap.i_getClonedWrappedMetadata(),this.p_dataType);};xmp.playlistapi.Resource.prototype.getLoadableId=function(){return this.getId();};xmp.playlistapi.Resource.prototype.getCompanionAdId=function(){return this.p_companionAdId;};xmp.playlistapi.Resource.prototype.i_setCompanionAdId=function(nh){this.p_companionAdId=nh;};xmp.playlistapi.Resource.prototype.i_getAssociationId=function(){return this.p_associationId;};xmp.playlistapi.Resource.prototype.i_setAssociationId=function(oh){this.p_associationId=oh;};xmp.createNamespace("xmp.playlistapi");xmp.playlistapi.RuleContext=function(id,ph,qh,rh){xmp.validateArguments(arguments,[xmp.i_STRING_TYPE,xmp.i_OBJECT_TYPE,xmp.i_OBJECT_TYPE,xmp.i_BOOLEAN_TYPE],"RuleContext.ctor");if(id===null||id.length===0){throw new xmp.util.internals.InvalidArgsError("RuleContext requires non-empty ID.");}
if(qh.length<1){throw new xmp.util.internals.InvalidArgsError("RuleContext at least one applicable type.");}
this.p_id=id;this.p_metadataMap=new xmp.util.internals.MetadataMap(rh);this.p_metadataMap.i_reInitialize(ph);this.p_applicableTypeArray=qh;};xmp.playlistapi.RuleContext.createDynamic=function(id,sh){return new xmp.playlistapi.RuleContext(id,sh,['dynamic'],true);};xmp.playlistapi.RuleContext.prototype.getId=function(){return this.p_id;};xmp.playlistapi.RuleContext.prototype.getMetadata=function(th,uh){return this.p_metadataMap.i_get(th,uh);};xmp.playlistapi.RuleContext.prototype.i_isApplicable=function(vh){if(vh.toLowerCase()==='all'){return true;}
for(var i=0;i<this.p_applicableTypeArray.length;i++){if(this.p_applicableTypeArray[i]===vh){return true;}}
return false;};xmp.createNamespace("xmp.playlistapi");xmp.playlistapi.RuleSetRunContext=function(){this.p_playableNode=null;this.p_currentRuleContext=null;};xmp.playlistapi.RuleSetRunContext.prototype.getPlayableNode=function(){return this.p_playableNode;};xmp.playlistapi.RuleSetRunContext.prototype.getCurrentRuleContext=function(){return this.p_currentRuleContext;};xmp.playlistapi.RuleSetRunContext.prototype.i_initialize=function(wh){this.p_playableNode=wh;this.p_currentRuleContext=null;};xmp.playlistapi.RuleSetRunContext.prototype.i_setCurrentRuleContext=function(xh){this.p_currentRuleContext=xh;};
