/* 
Version: 20071010

isisLive is now isLive.  Make update to EP for live stream
*/
/******************** DayPortVideo Class ********************/
function DayPortVideo(containerHndl, domain, imageDomain, format, videoID, width, height, adPackageArray, disableAutoFormatChange)
{
  //document.getElementById("debugTA").value += "\nDayPortVideo class constructor called.";

  // Initialize properties
  // Store reference to DayPortVideo object in global array.
  this.objectArrayIndex = DayPortVideo.objectArray.length;
  DayPortVideo.objectArray[this.objectArrayIndex] = this;

  if (typeof format == "string")
    format = format.toUpperCase();

  switch (format)
  {
    case 2:
    case "WMV":
      this.video = new DayPortWMVVideo(this.objectArrayIndex, containerHndl, domain, imageDomain, videoID, width, height, adPackageArray, disableAutoFormatChange);
      break;

    case 4:
    case "FLV":
      this.video = new DayPortFLVVideo(this.objectArrayIndex, containerHndl, domain, imageDomain, videoID, width, height, adPackageArray, disableAutoFormatChange);
      break;

    default:
      this.video = null;
      // Remove reference to DayPortVideo object in global array.
      this.objectArrayIndex = null;
      DayPortVideo.objectArray.length--;
  }
}

DayPortVideo.adArray = new Array();

// Generates a random string that can be appended onto URL's to help prevent cached content from being returned.
// The returned string is in the format of [|?|&]vCURRENTTIMEINMS_RANDOMNUMBERSTRING=1 (e.g., ?v1158852898276_0p3070916614117652=1)
DayPortVideo.appendRandom = function(baseString)
{
  //document.getElementById("debugTA").value += "\nDayPortVideo.appendRandom() called.";
  //document.getElementById("debugTA").value += "\n baseString="+baseString;

  var appendString = "";

  if (baseString != "")
  {
    // Generate random value that could be appended to baseString to help prevent caching
    var lastChar = baseString.toString().charAt(baseString.toString().length - 1);
    if ((lastChar == "?") || (lastChar == "&"))
    {
      appendString = "v" + DayPortVideo.genRandom(true) + "=1";
    }
    else if (baseString.toString().indexOf("?") == -1)
    {
      appendString = "?v" + DayPortVideo.genRandom(true) + "=1";
    }
    else
    {
      appendString = "&v" + DayPortVideo.genRandom(true) + "=1";
    }
  }

  //document.getElementById("debugTA").value += "\n appendString="+appendString;
  return appendString;
};

// Confirm that certain object methods are already defined, or define them if they are not.
DayPortVideo.confirmObjectMethods = function()
{
  //document.getElementById("debugTA").value += "\nDayPortVideo.confirmObjectMethods() called.";

  // Array.push() - Adds new elements to the end of an array and returns the new length.
  if (typeof Array.prototype.push == "undefined")
  {
    Array.prototype.push = function()
    {
      var currentLength = this.length;
      for (var i = 0; i < arguments.length; i++)
      {
        this[currentLength + i] = arguments[i];
      }
      return this.length;
    };
  }

  // Array.shift() - Removes the first element from an array and returns it.
  if (typeof Array.prototype.shift == "undefined")
  {
    Array.prototype.shift = function()
    {
      var firstElement = this[0];
      for (var i = 0; i < (this.length - 1); i++)
      {
        this[i] = this[i + 1];
      }
      this.length--;
      return firstElement;
    };
  }

  // Array.unshift() - Adds an element to the beginning of an array and returns the new length.
  if (typeof Array.prototype.unshift == "undefined")
  {
    Array.prototype.unshift = function(firstElement)
    {
      for (var i = (this.length - 1); i >= 0; i--)
      {
        this[i + 1] = this[i];
      }
      this[0] = firstElement;
      return this.length;
    };
  }
};
DayPortVideo.confirmObjectMethods();

DayPortVideo.changeClass = function(objHndl, newClass)
{
  //document.getElementById("debugTA").value += "\nDayPortVideo.changeClass() called.";

  objHndl.className = newClass;
};

// Generates a random string that can be added to URL's to help prevent cached content from being returned.
// The returned string is in the format of CURRENTTIMEINMS_RANDOMNUMBER
DayPortVideo.genRandom = function(replacePeriod)
{
  //document.getElementById("debugTA").value += "\nDayPortVideo.genRandom() called.";
  //document.getElementById("debugTA").value += "\n replacePeriod="+replacePeriod;

  var CurrTime = new Date();
  var rtnVal = CurrTime.getTime() + "_" + Math.random();
  if (replacePeriod)
  {
    rtnVal = rtnVal.replace(".", "p");
  }

  return rtnVal;
};

// Returns the number of pixels an element is away from the left side of the document (i.e., left/X position).
DayPortVideo.getLeftPos = function(elemObj)
{
  //document.getElementById("debugTA").value += "\nDayPortVideo.getLeftPos() called.";
  //document.getElementById("debugTA").value += "\n elemObj="+elemObj;

  var leftPos = 0;

  // See if an ID was passed in instead of an object
  if ((typeof(elemObj) == "string") || (typeof(elemObj) == "number"))
  {
    elemObj = document.getElementById(elemObj);

    if (!elemObj)
    {
      // Invalid element object
      //document.getElementById("debugTA").value += "\n Invalid element object. (elemObj="+elemObj+")";
      return null;
    }
  }

  if (elemObj.offsetParent)
  {
    while (elemObj.offsetParent != null)
    {
      leftPos += elemObj.offsetLeft;
      elemObj = elemObj.offsetParent;
    }

    if ((DayPortVideo.system.osPlatform == "Mac") && (typeof document.body.leftMargin != "undefined"))
    {
      leftPos += document.body.leftMargin;
    }
  }
  else if (elemObj.x)
  {
    leftPos += elemObj.x;
  }

  return leftPos;
};

// Returns the number of pixels an element is away from the top side of the document (i.e., top/Y position).
DayPortVideo.getTopPos = function(elemObj)
{
  //document.getElementById("debugTA").value += "\nDayPortVideo.getTopPos() called.";

  var topPos = 0;

  // See if an ID was passed in instead of an object
  if ((typeof(elemObj) == "string") || (typeof(elemObj) == "number"))
  {
    elemObj = document.getElementById(elemObj);

    if (!elemObj)
    {
      // Invalid element object
      //document.getElementById("debugTA").value += "\n Invalid element object. (elemObj="+elemObj+")";
      return null;
    }
  }

  if (elemObj.offsetParent)
  {
    while (elemObj.offsetParent != null)
    {
      //document.getElementById("debugTA").value += "\n tagName="+elemObj.tagName+", offsetTop="+elemObj.offsetTop+", offsetParent="+elemObj.offsetParent;
      // Check if element is a Flash object
      if (((typeof elemObj.codeBase != "undefined") && (elemObj.codeBase.toLowerCase().indexOf("flash") != -1)) || ((typeof elemObj.type != "undefined") && (elemObj.type.toLowerCase().indexOf("flash") != -1)))
      {
        // Check OS
        switch (DayPortVideo.system.osPlatform)
        {
          case "Windows":
            // Check browser
            switch (DayPortVideo.system.browser)
            {
              case "Internet Explorer":
              case "Opera":
                topPos += elemObj.offsetTop;
                break;

              case "Firefox":
              case "Netscape":
              default:
                //document.getElementById("debugTA").value += "\n Not including offsetTop for Flash object.";
            }
            break;

          case "Mac":
            // Check browser
            switch (DayPortVideo.system.browser)
            {
              case "Internet Explorer":
                topPos += elemObj.offsetTop;
                break;

              case "Firefox":
              case "Netscape":
              case "Safari":
              default:
                //document.getElementById("debugTA").value += "\n Not including offsetTop for Flash object.";
            }
            break;

          default:
            //document.getElementById("debugTA").value += "\n Not including offsetTop for Flash object.";
        }
      }
      else
      {
        topPos += elemObj.offsetTop;
      }
      elemObj = elemObj.offsetParent;
    }

    if ((DayPortVideo.system.osPlatform == "Mac") && (typeof document.body.topMargin != "undefined"))
    {
      topPos += document.body.topMargin;
    }
  }
  else if (elemObj.y)
  {
    topPos += elemObj.y;
  }

  return topPos;
};

DayPortVideo.metadataArray = new Array();

DayPortVideo.objectArray = new Array();

DayPortVideo.OnPageLoaded = function()
{
  //document.getElementById("debugTA").value += "\nDayPortVideo.OnPageLoaded() called.";

  DayPortVideo.pageLoaded = true;

  var numObjects = DayPortVideo.objectArray.length;
  for (var i=0; i < numObjects; i++)
  {
    // Dispatch OnPageLoaded event to all DayPortVideo objects in global array
    DayPortVideo.objectArray[i].video.OnPageLoaded();
  }
};

DayPortVideo.pageLoaded = false;

 DayPortVideo.prototype.changeFormat = function(format, disableAutoFormatChange)
{
  //document.getElementById("debugTA").value += "\nDayPortVideo.changeFormat() called.";

  if (typeof format == "string")
  {
    format = format.toUpperCase();
    if (format == this.video.format)
    {
      // This format is already set, so just return.
      return true;
    }
  }
  else if (format == this.video.formatID)
  {
    // This format is already set, so just return.
    return true;
  }

  // Make copy of automatic ad-insertion settings
  var tmpAdState = this.video.adState;
  var tmpAdInsertionChangeInterval = this.video.adInsertionChangeInterval;
  var tmpAdInsertionThreshold = this.video.adInsertionThreshold;
  var tmpAdInsertionThresholdChange = this.video.adInsertionThresholdChange;
  var tmpAdInsertionThresholdMax = this.video.adInsertionThresholdMax;
  var tmpAdInsertionFrequency = this.video.adInsertionFrequency;
  var tmpAdInsertionFrequencyChange = this.video.adInsertionFrequencyChange;
  var tmpAdInsertionFrequencyMax = this.video.adInsertionFrequencyMax;
  var tmpAdInsertionCount = this.video.adInsertionCount;
  var tmpPlaybackCount = this.video.playbackCount;
  var tmpIsLive = this.video.isLive;
  
  //Make copy of Article ID
  var tmpArticleID = this.video.articleID;
  var tmpcontentDomain = this.video.contentDomain;

  // Make copy of any registered event listeners
  var tmpEvents = new Array();
  for (var objEvent in this.video.events)
  {
    tmpEvents[objEvent] = new Array();
    for (var listenerFunc in this.video.events[objEvent])
    {
      tmpEvents[objEvent][listenerFunc] = this.video.events[objEvent][listenerFunc];
    }
  }

  // Make copy of any registered elements
  var tmpElements = new Array();
  for (var objElement in this.video.elements)
  {
    tmpElements[objElement] = new Object();
    for (var prop in this.video.elements[objElement])
    {
      tmpElements[objElement][prop] = this.video.elements[objElement][prop];
    }
  }

  // Make copy of any registered ad packages
  var tmpAdPackageArray = new Array();
  var numPackages = this.video.adPackageArray.length;
  for (var i=0; i < numPackages; i++)
  {
    tmpAdPackageArray[i] = new Object();
    tmpAdPackageArray[i].conDefID = this.video.adPackageArray[i].conDefID;
    tmpAdPackageArray[i].objects = new Array();
    var numObjects = this.video.adPackageArray[i].objects.length;
    for (var oi=0; oi < numObjects; oi++)
    {
      tmpAdPackageArray[i].objects[oi] = new Object();
      tmpAdPackageArray[i].objects[oi].objectID = this.video.adPackageArray[i].objects[oi].objectID;
      tmpAdPackageArray[i].objects[oi].adType = this.video.adPackageArray[i].objects[oi].adType;
      tmpAdPackageArray[i].objects[oi].track = this.video.adPackageArray[i].objects[oi].track;
      tmpAdPackageArray[i].objects[oi].elementRef = null;
    }
  }

  switch (format)
  {
    case 2:
    case "WMV":
      this.video = new DayPortWMVVideo(this.objectArrayIndex, this.video.containerObject, this.video.domain, this.video.imageDomain, this.video.videoID, this.video.width, this.video.height, tmpAdPackageArray, disableAutoFormatChange);
      //document.getElementById("debugTA").value += "\nthis.objectArrayIndex=" + this.objectArrayIndex + ", this.video.containerObject=" + this.video.containerObject + ", this.video.domain=" + this.video.domain + "\nthis.video.videoID=" + this.video.videoID + ", this.video.width=" + this.video.width + ", this.video.height=" + this.video.height;

      // Set automatic ad-insertion settings with previous values
      if (tmpAdState == "queued")
      {
        // Queue an advertisement for insertion
        this.video.adState = "queued";
      }
      this.video.setAdInsertionThreshold(tmpAdInsertionThreshold);
      this.video.setAdInsertionThresholdChange(tmpAdInsertionThresholdChange);
      this.video.setAdInsertionThresholdMax(tmpAdInsertionThresholdMax);
      this.video.setAdInsertionFrequency(tmpAdInsertionFrequency);
      this.video.setAdInsertionFrequencyChange(tmpAdInsertionFrequencyChange);
      this.video.setAdInsertionFrequencyMax(tmpAdInsertionFrequencyMax);
      this.video.setAdInsertionChangeInterval(tmpAdInsertionChangeInterval);

      // Register any previously registered event listeners
      for (var objEventR in tmpEvents)
      {
        for (var listenerFuncR in tmpEvents[objEventR])
        {
          this.video.registerEventListener(objEventR, tmpEvents[objEventR][listenerFuncR]);
        }
      }

      // Register any previously registered elements
      for (var objElementR in tmpElements)
      {
        if (tmpElements[objElementR] != null)
        {
          var tmpParameters = new Object();
          for (var param in tmpElements[objElementR])
          {
            if ((param != "idStr") && (param != "impressionTrackImageObject"))
            {
              tmpParameters[param] = tmpElements[objElementR][param];
            }
          }

          this.video.registerElement(tmpElements[objElementR].idStr, tmpParameters);
        }
      }
      
      this.video.adInsertionCount = tmpAdInsertionCount;
      this.video.contentDomain = tmpcontentDomain;
      this.video.playbackCount = tmpPlaybackCount;
      this.video.isLive = tmpIsLive;
      //document.getElementById("debugTA").value += "\ntmpIsLive=" + tmpIsLive;
     	//document.getElementById("debugTA").value += "\n tmpcontentDomain="+tmpcontentDomain;
      if(tmpArticleID != null)
      {
			if(this.video.contentDomain != this.video.domain && typeof this.video.contentDomain != "undefined") tmpArticleID += "@"+this.video.contentDomain;
			this.video.setSource("article", tmpArticleID);      	
      }
     
      break;

    case 4:
    case "FLV":
      this.video = new DayPortFLVVideo(this.objectArrayIndex, this.video.containerObject, this.video.domain, this.video.imageDomain, this.video.videoID, this.video.width, this.video.height, tmpAdPackageArray, disableAutoFormatChange);
      //document.getElementById("debugTA").value += "\nthis.objectArrayIndex=" + this.objectArrayIndex + ", this.video.containerObject=" + this.video.containerObject + ", this.video.domain=" + this.video.domain + "\nthis.video.videoID=" + this.video.videoID + ", this.video.width=" + this.video.width + ", this.video.height=" + this.video.height;

      // Set automatic ad-insertion settings with previous values
      if ((tmpAdState == "queued") && ((DayPortVideo.system.osPlatform != "Windows") || (DayPortVideo.system.browser != "Opera")))
      {
        // Queue an advertisement for insertion
        this.video.adState = "queued";
      }
      this.video.setAdInsertionThreshold(tmpAdInsertionThreshold);
      this.video.setAdInsertionThresholdChange(tmpAdInsertionThresholdChange);
      this.video.setAdInsertionThresholdMax(tmpAdInsertionThresholdMax);
      this.video.setAdInsertionFrequency(tmpAdInsertionFrequency);
      this.video.setAdInsertionFrequencyChange(tmpAdInsertionFrequencyChange);
      this.video.setAdInsertionFrequencyMax(tmpAdInsertionFrequencyMax);
      this.video.setAdInsertionChangeInterval(tmpAdInsertionChangeInterval);

      // Register any previously registered event listeners
      for (var objEventR in tmpEvents)
      {
        for (var listenerFuncR in tmpEvents[objEventR])
        {
          this.video.registerEventListener(objEventR, tmpEvents[objEventR][listenerFuncR]);
        }
      }

      // Register any previously registered elements
      for (var objElementR in tmpElements)
      {
        if (tmpElements[objElementR] != null)
        {
          var tmpParameters = new Object();
          for (var param in tmpElements[objElementR])
          {
            if ((param != "idStr") && (param != "impressionTrackImageObject"))
            {
              tmpParameters[param] = tmpElements[objElementR][param];
            }
          }

          this.video.registerElement(tmpElements[objElementR].idStr, tmpParameters);
        }
      }
      
      this.video.adInsertionCount = tmpAdInsertionCount;
      this.video.contentDomain = tmpcontentDomain;
      this.video.playbackCount = tmpPlaybackCount;
     	//document.getElementById("debugTA").value += "\n tmpcontentDomain="+tmpcontentDomain;
      if(tmpArticleID != null)
      {
			if(this.video.contentDomain != this.video.domain && typeof this.video.contentDomain != "undefined") tmpArticleID += "@"+this.video.contentDomain;
			
			this.video.setSource("article", tmpArticleID);      	
      }
      
      break;

    default:
      return false;
  }

  return true;
};

DayPortVideo.registerEventListener = function(targetObj, objEvent, listenerFunc)
{
  //document.getElementById("debugTA").value += "\nDayPortVideo.registerEventListener() called.";

  if (targetObj.attachEvent)
  {
    targetObj.attachEvent("on"+objEvent, listenerFunc);
  }
  else if (targetObj.addEventListener)
  {
    targetObj.addEventListener(objEvent, listenerFunc, false);
  }
  else
  {
    if (typeof targetObj["on"+objEvent] == "function")
    {
      var prevFunction = targetObj["on"+objEvent];

      targetObj["on"+objEvent] = function()
      {
        // Run previous contents
        prevFunction();

        // Call listener function for DayPortVideo class
        listenerFunc();
      };
    }
    else
    {
      targetObj["on"+objEvent] = function()
      {
        // Call listener function for DayPortVideo class
        listenerFunc();
      };
    }
  }
};

// Register for page events to utilize
DayPortVideo.registerForEvents = function()
{
  //document.getElementById("debugTA").value += "\nDayPortVideo.registerForEvents() called.";

  // Register for window.onload event
  DayPortVideo.registerEventListener(window, "load", DayPortVideo.OnPageLoaded);
};
DayPortVideo.registerForEvents();

DayPortVideo.requestAdCB = function(domain, conDefID)
{
  //document.getElementById("debugTA").value += "\nDayPortVideo.requestAdCB() called.";
  //document.getElementById("debugTA").value += "\n domain="+domain+", conDefID="+conDefID;

  var numObjects = DayPortVideo.objectArray.length;
  for (var i=0; i < numObjects; i++)
  {
    if ((DayPortVideo.objectArray[i].video.domain == domain) && (typeof DayPortVideo.objectArray[i].video.adArray["ConDef_"+conDefID] != "undefined") && (DayPortVideo.objectArray[i].video.adArray["ConDef_"+conDefID].adRequestState == "loading"))
    {
      // Dispatch callback for requestAd method to appropriate DayPortVideo object(s) in global array
      DayPortVideo.objectArray[i].video.requestAdCB(DayPortVideo.adArray[domain+"_"+conDefID]);
    }
  }
};

DayPortVideo.requestThirdPartyAdCB = function(adObject)
{
  //document.getElementById("debugTA").value += "\nDayPortVideo.requestThirdPartyAdCB() called.";
  //document.getElementById("debugTA").value += "\n adObject="+adObject;

  var numObjects = DayPortVideo.objectArray.length;
  for (var i=0; i < numObjects; i++)
  {
    if ((DayPortVideo.objectArray[i].video.thirdPartyAdParameters != null) && (DayPortVideo.objectArray[i].video.thirdPartyAdParameters.adRequestState == "loading"))
    {
      // Dispatch callback for requestThirdPartyAd method to appropriate DayPortVideo object(s) in global array
      DayPortVideo.objectArray[i].video.requestThirdPartyAdCB(adObject);
    }
  }
};

DayPortVideo.retrieveMetadataCB = function(domain, artID)
{
  //document.getElementById("debugTA").value += "\nDayPortVideo.retrieveMetadataCB() called.";
  //document.getElementById("debugTA").value += "\n domain="+domain+", artID="+artID;

  var numObjects = DayPortVideo.objectArray.length;
  for (var i=0; i < numObjects; i++)
  {
    if ((DayPortVideo.objectArray[i].video.domain == domain) && (DayPortVideo.objectArray[i].video.articleID == artID) && (DayPortVideo.objectArray[i].video.metadataState == "loading"))
    {
      // Dispatch callback for retrieveMetadata method to appropriate DayPortVideo object(s) in global array
      DayPortVideo.objectArray[i].video.retrieveMetadataCB(DayPortVideo.metadataArray[domain+"_"+artID]);
    }else if ((DayPortVideo.objectArray[i].video.contentDomain == domain) && (DayPortVideo.objectArray[i].video.articleID == artID) && (DayPortVideo.objectArray[i].video.metadataState == "loading")){
    	DayPortVideo.objectArray[i].video.retrieveMetadataCB(DayPortVideo.metadataArray[DayPortVideo.objectArray[i].video.contentDomain+"_"+artID]);
    }
  }
};

DayPortVideo.system = new Object();
DayPortVideo.system.osPlatform = null;
DayPortVideo.system.osVersion = null;
DayPortVideo.system.browser = null;
DayPortVideo.system.browserVersion = null;

DayPortVideo.systemCheck = function()
{
  //document.getElementById("debugTA").value += "\nDayPortVideo.systemCheck() called.";

  var osPlatform = "unknown";
  var osVersion = "unknown";
  var browser = "unknown";
  var browserVersion;

  // convert all characters to lowercase to simplify testing
  var agt=navigator.userAgent.toLowerCase();
  var appVer = navigator.appVersion.toLowerCase();

  // *** BROWSER VERSION ***

  var is_minor = parseFloat(appVer);
  var is_major = parseInt(is_minor);

  var is_opera = (agt.indexOf("opera") != -1);
  var is_opera2 = (agt.indexOf("opera 2") != -1 || agt.indexOf("opera/2") != -1);
  var is_opera3 = (agt.indexOf("opera 3") != -1 || agt.indexOf("opera/3") != -1);
  var is_opera4 = (agt.indexOf("opera 4") != -1 || agt.indexOf("opera/4") != -1);
  var is_opera5 = (agt.indexOf("opera 5") != -1 || agt.indexOf("opera/5") != -1);
  var is_opera6 = (agt.indexOf("opera 6") != -1 || agt.indexOf("opera/6") != -1); // new 020128- abk
  var is_opera7 = (agt.indexOf("opera 7") != -1 || agt.indexOf("opera/7") != -1); // new 021205- dmr
  var is_opera5up = (is_opera && !is_opera2 && !is_opera3 && !is_opera4);
  var is_opera6up = (is_opera && !is_opera2 && !is_opera3 && !is_opera4 && !is_opera5); // new020128
  var is_opera7up = (is_opera && !is_opera2 && !is_opera3 && !is_opera4 && !is_opera5 && !is_opera6); // new021205 -- dmr

  // Note: On IE, start of appVersion return 3 or 4
  // which supposedly is the version of Netscape it is compatible with.
  // So we look for the real version further on in the string
  // And on Mac IE5+, we look for is_minor in the ua; since
  // it appears to be more accurate than appVersion - 06/17/2004

  var is_mac = (agt.indexOf("mac")!=-1);
  var iePos  = appVer.indexOf('msie');
  if (iePos !=-1) {
     if(is_mac) {
         var iePos = agt.indexOf('msie');
         is_minor = parseFloat(agt.substring(iePos+5,agt.indexOf(';',iePos)));
     }
     else is_minor = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)));
     is_major = parseInt(is_minor);
  }

  // ditto Konqueror

  var is_konq = false;
  var kqPos   = agt.indexOf('konqueror');
  if (kqPos !=-1) {
     is_konq  = true;
     is_minor = parseFloat(agt.substring(kqPos+10,agt.indexOf(';',kqPos)));
     is_major = parseInt(is_minor);
  }

  var is_safari = ((agt.indexOf('safari')!=-1)&&(agt.indexOf('mac')!=-1))?true:false;
  var is_khtml  = (is_safari || is_konq);

  var is_gecko = ((!is_khtml)&&(navigator.product)&&(navigator.product.toLowerCase()=="gecko"))?true:false;
  var is_gver  = 0;
  if (is_gecko) is_gver=navigator.productSub;

  var is_moz   = ((agt.indexOf('mozilla/5')!=-1) && (agt.indexOf('spoofer')==-1) &&
                  (agt.indexOf('compatible')==-1) && (agt.indexOf('opera')==-1)  &&
                  (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)     &&
                  (is_gecko) &&
                  ((navigator.vendor=="")||(navigator.vendor=="Mozilla")||(navigator.vendor=="Debian")));
  var is_fb = ((agt.indexOf('mozilla/5')!=-1) && (agt.indexOf('spoofer')==-1) &&
               (agt.indexOf('compatible')==-1) && (agt.indexOf('opera')==-1)  &&
               (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)     &&
               (is_gecko) && (navigator.vendor=="Firebird"));
  var is_fx = ((agt.indexOf('mozilla/5')!=-1) && (agt.indexOf('spoofer')==-1) &&
               (agt.indexOf('compatible')==-1) && (agt.indexOf('opera')==-1)  &&
               (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)     &&
               (is_gecko) && (navigator.vendor=="Firefox"));
  if ((is_moz)||(is_fb)||(is_fx)) {  // 032504 - dmr
     var is_moz_ver = (navigator.vendorSub)?navigator.vendorSub:0;
     if(!(is_moz_ver)) {
         is_moz_ver = agt.indexOf('rv:');
         is_moz_ver = agt.substring(is_moz_ver+3);
         is_paren   = is_moz_ver.indexOf(')');
         is_moz_ver = is_moz_ver.substring(0,is_paren);
     }
     is_minor = is_moz_ver;
     is_major = parseInt(is_moz_ver);
  }
  var is_fb_ver = is_moz_ver;
  var is_fx_ver = is_moz_ver;

  var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
              && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
              && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)
              && (!is_khtml) && (!(is_moz)) && (!is_fb) && (!is_fx));

  // Netscape6 is mozilla/5 + Netscape6/6.0!!!
  // Mozilla/5.0 (Windows; U; Win98; en-US; m18) Gecko/20001108 Netscape6/6.0
  // Changed this to use navigator.vendor/vendorSub - dmr 060502
  // var nav6Pos = agt.indexOf('netscape6');
  // if (nav6Pos !=-1) {
  if ((navigator.vendor)&&
      ((navigator.vendor=="Netscape6")||(navigator.vendor=="Netscape"))&&
      (is_nav)) {
     is_major = parseInt(navigator.vendorSub);
     // here we need is_minor as a valid float for testing. We'll
     // revert to the actual content before printing the result.
     is_minor = parseFloat(navigator.vendorSub);
  }

  var is_nav2 = (is_nav && (is_major == 2));
  var is_nav3 = (is_nav && (is_major == 3));
  var is_nav4 = (is_nav && (is_major == 4));
  var is_nav4up = (is_nav && is_minor >= 4);  // changed to is_minor for
                                              // consistency - dmr, 011001
  var is_navonly      = (is_nav && ((agt.indexOf(";nav") != -1) ||
                        (agt.indexOf("; nav") != -1)) );

  var is_nav6   = (is_nav && is_major==6);    // new 010118 mhp
  var is_nav6up = (is_nav && is_minor >= 6); // new 010118 mhp

  var is_nav5   = (is_nav && is_major == 5 && !is_nav6); // checked for ns6
  var is_nav5up = (is_nav && is_minor >= 5);

  var is_nav7   = (is_nav && is_major == 7);
  var is_nav7up = (is_nav && is_minor >= 7);

  var is_ie   = ((iePos!=-1) && (!is_opera) && (!is_khtml));
  var is_ie3  = (is_ie && (is_major < 4));

  var is_ie4   = (is_ie && is_major == 4);
  var is_ie4up = (is_ie && is_minor >= 4);
  var is_ie5   = (is_ie && is_major == 5);
  var is_ie5up = (is_ie && is_minor >= 5);

  var is_ie5_5  = (is_ie && (agt.indexOf("msie 5.5") !=-1)); // 020128 new - abk
  var is_ie5_5up =(is_ie && is_minor >= 5.5);                // 020128 new - abk

  var is_ie6   = (is_ie && is_major == 6);
  var is_ie6up = (is_ie && is_minor >= 6);

  // KNOWN BUG: On AOL4, returns false if IE3 is embedded browser
  // or if this is the first browser window opened.  Thus the
  // variables is_aol, is_aol3, and is_aol4 aren't 100% reliable.

  var is_aol   = (agt.indexOf("aol") != -1);
  var is_aol3  = (is_aol && is_ie3);
  var is_aol4  = (is_aol && is_ie4);
  var is_aol5  = (agt.indexOf("aol 5") != -1);
  var is_aol6  = (agt.indexOf("aol 6") != -1);
  var is_aol7  = ((agt.indexOf("aol 7")!=-1) || (agt.indexOf("aol7")!=-1));
  var is_aol8  = ((agt.indexOf("aol 8")!=-1) || (agt.indexOf("aol8")!=-1));

  var is_webtv = (agt.indexOf("webtv") != -1);

  // new 020128 - abk

  var is_TVNavigator = ((agt.indexOf("navio") != -1) || (agt.indexOf("navio_aoltv") != -1));
  var is_AOLTV = is_TVNavigator;

  var is_hotjava = (agt.indexOf("hotjava") != -1);
  var is_hotjava3 = (is_hotjava && (is_major == 3));
  var is_hotjava3up = (is_hotjava && (is_major >= 3));

  // end new

  // Done with is_minor testing; revert to real for N6/7
  if (is_nav6up) {
     is_minor = navigator.vendorSub;
  }

  // *** PLATFORM ***
  var is_win   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
  // NOTE: On Opera 3.0, the userAgent string includes "Windows 95/NT4" on all
  //        Win32, so you can't distinguish between Win95 and WinNT.
  var is_win95 = ((agt.indexOf("win95")!=-1) || (agt.indexOf("windows 95")!=-1));

  // is this a 16 bit compiled version?
  var is_win16 = ((agt.indexOf("win16")!=-1) ||
             (agt.indexOf("16bit")!=-1) || (agt.indexOf("windows 3.1")!=-1) ||
             (agt.indexOf("windows 16-bit")!=-1) );

  var is_win31 = ((agt.indexOf("windows 3.1")!=-1) || (agt.indexOf("win16")!=-1) ||
                  (agt.indexOf("windows 16-bit")!=-1));

  var is_winme = ((agt.indexOf("win 9x 4.90")!=-1));    // new 020128 - abk
  var is_win2k = ((agt.indexOf("windows nt 5.0")!=-1) || (agt.indexOf("windows 2000")!=-1)); // 020214 - dmr
  var is_winxp = ((agt.indexOf("windows nt 5.1")!=-1) || (agt.indexOf("windows xp")!=-1)); // 020214 - dmr

  // NOTE: Reliable detection of Win98 may not be possible. It appears that:
  //       - On Nav 4.x and before you'll get plain "Windows" in userAgent.
  //       - On Mercury client, the 32-bit version will return "Win98", but
  //         the 16-bit version running on Win98 will still return "Win95".
  var is_win98 = ((agt.indexOf("win98")!=-1) || (agt.indexOf("windows 98")!=-1));
  var is_winnt = ((agt.indexOf("winnt")!=-1) || (agt.indexOf("windows nt")!=-1));
  var is_win32 = (is_win95 || is_winnt || is_win98 ||
                  ((is_major >= 4) && (navigator.platform == "Win32")) ||
                  (agt.indexOf("win32")!=-1) || (agt.indexOf("32bit")!=-1));

  var is_os2   = ((agt.indexOf("os/2")!=-1) ||
                  (navigator.appVersion.indexOf("OS/2")!=-1) ||
                  (agt.indexOf("ibm-webexplorer")!=-1));

  var is_mac    = (agt.indexOf("mac")!=-1);
  if (is_mac) { is_win = !is_mac; } // dmr - 06/20/2002
  var is_mac68k = (is_mac && ((agt.indexOf("68k")!=-1) ||
                             (agt.indexOf("68000")!=-1)));
  var is_macppc = (is_mac && ((agt.indexOf("ppc")!=-1) ||
                              (agt.indexOf("powerpc")!=-1)));

  var is_sun   = (agt.indexOf("sunos")!=-1);
  var is_sun4  = (agt.indexOf("sunos 4")!=-1);
  var is_sun5  = (agt.indexOf("sunos 5")!=-1);
  var is_suni86= (is_sun && (agt.indexOf("i86")!=-1));
  var is_irix  = (agt.indexOf("irix") !=-1);    // SGI
  var is_irix5 = (agt.indexOf("irix 5") !=-1);
  var is_irix6 = ((agt.indexOf("irix 6") !=-1) || (agt.indexOf("irix6") !=-1));
  var is_hpux  = (agt.indexOf("hp-ux")!=-1);
  var is_hpux9 = (is_hpux && (agt.indexOf("09.")!=-1));
  var is_hpux10= (is_hpux && (agt.indexOf("10.")!=-1));
  var is_aix   = (agt.indexOf("aix") !=-1);      // IBM
  var is_aix1  = (agt.indexOf("aix 1") !=-1);
  var is_aix2  = (agt.indexOf("aix 2") !=-1);
  var is_aix3  = (agt.indexOf("aix 3") !=-1);
  var is_aix4  = (agt.indexOf("aix 4") !=-1);
  var is_linux = (agt.indexOf("inux")!=-1);
  var is_sco   = (agt.indexOf("sco")!=-1) || (agt.indexOf("unix_sv")!=-1);
  var is_unixware = (agt.indexOf("unix_system_v")!=-1);
  var is_mpras    = (agt.indexOf("ncr")!=-1);
  var is_reliant  = (agt.indexOf("reliantunix")!=-1);
  var is_dec   = ((agt.indexOf("dec")!=-1) || (agt.indexOf("osf1")!=-1) ||
         (agt.indexOf("dec_alpha")!=-1) || (agt.indexOf("alphaserver")!=-1) ||
         (agt.indexOf("ultrix")!=-1) || (agt.indexOf("alphastation")!=-1));
  var is_sinix = (agt.indexOf("sinix")!=-1);
  var is_freebsd = (agt.indexOf("freebsd")!=-1);
  var is_bsd = (agt.indexOf("bsd")!=-1);
  var is_unix  = ((agt.indexOf("x11")!=-1) || is_sun || is_irix || is_hpux ||
               is_sco ||is_unixware || is_mpras || is_reliant ||
               is_dec || is_sinix || is_aix || is_linux || is_bsd || is_freebsd);

  var is_vms   = ((agt.indexOf("vax")!=-1) || (agt.indexOf("openvms")!=-1));


  // Define browser and version
  if (is_ie)
    browser = "Internet Explorer";
  else if (is_nav)
    browser = "Netscape";
  else if (is_fx)
    browser = "Firefox";
  else if (is_moz)
    browser = "Mozilla";
  else if (is_opera)
    browser = "Opera";
  else if (is_konq)
    browser = "Konqueror";
  else if (is_safari)
    browser = "Safari";
  else if (is_aol)
    browser = "AOL";

  browserVersion = is_minor;

  // Define OS and version
  if (is_win)
  {
    osPlatform = "Windows";
    if (is_winxp)
      osVersion = "Windows XP";
    else if (is_win2k)
      osVersion = "Windows 2000";
    else if (is_winnt)
      osVersion = "Windows NT";
    else if (is_winme)
      osVersion = "Windows ME";
    else if (is_win98)
      osVersion = "Windows 98";
    else if (is_win95)
      osVersion = "Windows 95";
    else if (is_win31)
      osVersion = "Windows 3.1";
  }
  else if (is_mac)
    osPlatform = "Mac";
  else if (is_linux)
    osPlatform = "Linux";
  else if (is_unix)
    osPlatform = "Unix";

  DayPortVideo.system.osPlatform = osPlatform;
  DayPortVideo.system.osVersion = osVersion;
  DayPortVideo.system.browser = browser;
  DayPortVideo.system.browserVersion = browserVersion;
};
DayPortVideo.systemCheck();

DayPortVideo.prototype.toString = function()
{
  //document.getElementById("debugTA").value += "\nDayPortVideo.toString() called.";

  return "[object DayPortVideo]";
};

DayPortVideo.unregisterEventListener = function(targetObj, objEvent, listenerFunc)
{
  //document.getElementById("debugTA").value += "\nDayPortVideo.unregisterEventListener() called.";

  if (targetObj.detachEvent)
  {
    targetObj.detachEvent("on"+objEvent, listenerFunc);
  }
  else if (targetObj.removeEventListener)
  {
    targetObj.removeEventListener(objEvent, listenerFunc, false);
  }
  else
  {
    if (typeof targetObj["on"+objEvent] == "function")
    {
      targetObj["on"+objEvent] = null;
    }
  }
};
/******************** End of DayPortVideo Class ********************/

/******************** DayPortFLVVideo Class ********************/
function DayPortFLVVideo(objectArrayIndex, containerHndl, domain, imageDomain, videoID, width, height, adPackageArray, disableAutoFormatChange)
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo class constructor called.";

  // Initialize properties
  // Store reference to DayPortVideo object in global array.
  this.objectArrayIndex = objectArrayIndex;
  this.format = "FLV";
  this.formatID = 4;
  this.containerObject = containerHndl;
  this.domain = domain;
  this.imageDomain = imageDomain;
  this.isLive = false;  //whether or not content video is a live broadcast
  this.videoID = videoID;
  this.videoAdName = "";
  this.width = width;
  this.height = height;
  this.adPackageArray = new Array();
  if ((adPackageArray != "") && (adPackageArray != null) && (typeof adPackageArray != "undefined"))
  {
    var numPackages = adPackageArray.length;
    for (var i=0; i < numPackages; i++)
    {
      this.adPackageArray[i] = new Object();
      this.adPackageArray[i].conDefID = adPackageArray[i].conDefID;
      this.adPackageArray[i].objects = new Array();
      var numObjects = adPackageArray[i].objects.length;
      for (var oi=0; oi < numObjects; oi++)
      {
        this.adPackageArray[i].objects[oi] = new Object();
        this.adPackageArray[i].objects[oi].objectID = adPackageArray[i].objects[oi].objectID;
        this.adPackageArray[i].objects[oi].adType = adPackageArray[i].objects[oi].adType;
        this.adPackageArray[i].objects[oi].track = adPackageArray[i].objects[oi].track;
        this.adPackageArray[i].objects[oi].elementRef = null;
      }
    }
  }
  this.adArray = new Array();  // Possible values for adRequestState property: "uninitialized", "waiting", "loading", "loaded"
  /*
  this.adArray["ConDef_2"] = {
                               adRequestRef: 1,
                               adRequestState: "uninitialized"
                             };
  */
  if ((DayPortVideo.system.osPlatform == "Windows") && (DayPortVideo.system.browser == "Opera"))
  {
    this.autoAdInsertion = false;
  }
  else
  {
    if (this.adPackageArray.length > 0)
    {
      this.autoAdInsertion = true;
    }
    else
    {
      this.autoAdInsertion = false;
    }
  }
  this.adState = "inactive";  // Possible values: "inactive", "tracking", "queued", "loading", "playing"
  this.consecutiveAdQueued = false;  // Whether or not a consecutive advertisement is queued for insertion (i.e., playback of back-to-back ads)
  this.processingAdPackages = false;  // Whether or not the ad-package settings are actively in use.
  this.queuedVideoAdParameters = null;  // Used by callback for last ad package to set the source to the advertisement video
  this.queuedAdPackageArray = null;  // Used by callback for last ad package to change the queued ad-package settings changes
  this.queuedBannerAdElementArray = null;  // Used by callback for last ad package to change the queued ad-package settings changes
  this.thirdPartyAdParameters = null;  // Used by callback for last ad package to request a third-party ad
  this.trackedArticle = null;
  this.playbackCount = 0;
  // Seconds of video playback before inserting an advertisement (before next selected video).
  this.adInsertionThreshold = null;
  // Number of videos played back (playback started but not necessarily completed) before inserting an advertisement (before next selected video).
  this.adInsertionFrequency = 1;
  this.adInsertionCount = 0;
  // Number of advertisements inserted before the insertion rate is increased.
  this.adInsertionChangeInterval = null;
  // Amount DayPortFLVVideo.adInsertionThreshold is adjusted when DayPortFLVVideo.adInsertionChangeInterval is reached.
  this.adInsertionThresholdChange = null;
  // Amount DayPortFLVVideo.adInsertionFrequency is adjusted when DayPortFLVVideo.adInsertionChangeInterval is reached.
  this.adInsertionFrequencyChange = null;
  // Maximum value DayPortFLVVideo.adInsertionThreshold can be set to as a result of DayPortFLVVideo.adInsertionChangeInterval being reached.
  this.adInsertionThresholdMax = null;
  // Maximum value DayPortFLVVideo.adInsertionFrequency can be set to as a result of DayPortFLVVideo.adInsertionChangeInterval being reached.
  this.adInsertionFrequencyMax = null;
  this.events = new Array();
  // Events that listeners can be registered for
  this.events["BeforeFullScreen"] = new Array();
  this.events["Buffering"] = new Array();
  this.events["DurationUpdated"] = new Array();
  this.events["EndOfAd"] = new Array();
  this.events["EndOfStream"] = new Array();
  this.events["MetadataRetrieved"] = new Array();
  this.events["Mute"] = new Array();
  this.events["Paused"] = new Array();
  this.events["Playing"] = new Array();
  this.events["PlayStateChange"] = new Array();
  this.events["PositionUpdated"] = new Array();
  this.events["Stopped"] = new Array();
  this.events["Transitioning"] = new Array();
  this.events["UnMute"] = new Array();
  this.elements = new Array();
  // Elements that can be registered
  //this.elements["bannerAd_1"] = null;

  this.duration = null;
  this.muted = false;
  this.volumeLevel = 100;  // Percentage level of volume (valid range: 0-100)
  this.scriptControlSupported = true;  // Denotes whether control of the embedded WMP object via script is supported
  this.pageLoadedReceipt = false;

  this.requirementsMet = this.requirementsCheck();
  
  if(!disableAutoFormatChange && !this.requirementsMet)
  {
    //document.getElementById("debugTA").value += "\nRequirements not met for this format (FLV).";
    // Requirements not met, so just return.
    return;
  }
  else
  {
    this.mdRetrieverObject = null;
    this.flashBrokerObject = null;
    this.localConnectionName = "DayPortFlashBroker_" + DayPortVideo.genRandom();
    this.videoObject = this.generateTag(videoID, width, height);
    this.currPlayState = null;
    this.prevPlayState = null;
    this.currentPosition = null;
    this.wasBuffering = false;
    this.articleID = null;
    this.metadata = new Object();
    this.metadata.formatsAvailable = new Array();
    this.metadataState = "uninitialized";  // Possible values: "uninitialized", "loading", "loaded"
    this.contentDomain = "";
    this.interval = 1000;
    this.intervalStopped = true;
    this.clickURL = null;
    this.impressionTrackURL = null;
    this.externalImpressionTrackURL = null;
    this.completionTrackURL = null;
    this.externalCompletionTrackURL = null;
    this.commandQueue = new Array();
    this.queueProcessingEnabled = false;
    this.queueProcessState = "inactive";  // Possible values: "inactive", "processing", "processed"

    // Check if page has already loaded
    if (DayPortVideo.pageLoaded)
    {
      // Raise OnPageLoaded event
      this.OnPageLoaded();
    }
  }
}

DayPortFLVVideo.prototype.addToQueue = function(commandStr)
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.addToQueue() called.";
  //document.getElementById("debugTA").value += "\n commandStr="+commandStr;

  this.commandQueue.push(commandStr);

  if (this.queueProcessingEnabled && (this.queueProcessState == "inactive"))
  {
    // The Queue was empty so begin processing
    this.processQueue();
  }
};

DayPortFLVVideo.prototype.adInsertionCount_reset = function()
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.adInsertionCount_reset() called.";

  this.adInsertionCount = 0;
};

// Track number of video advertisements inserted
DayPortFLVVideo.prototype.adInsertionCount_track = function()
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.adInsertionCount_track() called.";

  // Increment adInsertionCount property
  this.adInsertionCount++;
  //document.getElementById("debugTA").value += "\n adInsertionCount="+this.adInsertionCount;

  if (this.adInsertionCount >= this.adInsertionChangeInterval)
  {
    //document.getElementById("debugTA").value += "\n DayPortFLVVideo.adInsertionChangeInterval reached.";
    this.adInsertionCount_reset();

    // See if any insertion rates should be adjusted
    if ((this.adInsertionFrequency != null) && (this.adInsertionFrequencyChange != null))
    {
      // Adjust adInsertionFrequency property, account for a maximum limit if set
      if (this.adInsertionFrequencyMax == null)
      {
        this.adInsertionFrequency += this.adInsertionFrequencyChange;
      }
      else
      {
        this.adInsertionFrequency = Math.min((this.adInsertionFrequency + this.adInsertionFrequencyChange), this.adInsertionFrequencyMax);
      }
      //document.getElementById("debugTA").value += "\n DayPortFLVVideo.adInsertionFrequency adjusted to "+this.adInsertionFrequency+" video(s).";
    }

    if ((this.adInsertionThreshold != null) && (this.adInsertionThresholdChange != null))
    {
      // Adjust adInsertionThreshold property, account for a maximum limit if set
      if (this.adInsertionFrequencyMax == null)
      {
        this.setAdInsertionThreshold((this.adInsertionThreshold + this.adInsertionThresholdChange));
      }
      else
      {
        this.setAdInsertionThreshold(Math.min((this.adInsertionThreshold + this.adInsertionThresholdChange), this.adInsertionThresholdMax));
      }
      //document.getElementById("debugTA").value += "\n DayPortFLVVideo.adInsertionThreshold adjusted to "+this.adInsertionThreshold+" second(s).";
    }
  }
};

DayPortFLVVideo.prototype.brokerVideoCommand = function(commandStr)
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.brokerVideoCommand() called.";
  //document.getElementById("debugTA").value += "\n commandStr="+commandStr;

  this.flashBrokerObject.innerHTML = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="1" height="1">' +
                                     '<param name="movie" value="http://' + this.imageDomain + '/img/DayPortFlashBroker.swf?v=012308&objectArrayIndex=' + this.objectArrayIndex + '&lcn=' + this.localConnectionName + '&cmd=' + commandStr + '" />' +
                                     //'<param name="movie" value="http://cdn.dayport.com/vlnimg/img/PartnerPlayer/DayPortFlashBroker.swf?v=012306&objectArrayIndex=' + this.objectArrayIndex + '&lcn=' + this.localConnectionName + '&cmd=' + commandStr + '" />' +
                                     '<param name="menu" value="false" />' +
                                     '<param name="wmode" value="transparent" />' +
                                     '<embed src="http://' + this.imageDomain + '/img/DayPortFlashBroker.swf?v=012307&objectArrayIndex=' + this.objectArrayIndex + '&lcn=' + this.localConnectionName + '&cmd=' + commandStr + '" wmode="transparent" menu="false" width="1" height="1" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />' +
                                     //'<embed src="http://cdn.dayport.com/vlnimg/img/PartnerPlayer/DayPortFlashBroker.swf?v=012308&objectArrayIndex=' + this.objectArrayIndex + '&lcn=' + this.localConnectionName + '&cmd=' + commandStr + '" wmode="transparent" menu="false" width="1" height="1" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />' +
                                     '</object>';
};

DayPortFLVVideo.prototype.changeAds = function()
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.changeAds() called.";

  this.adState = "loading";
  this.processingAdPackages = true;
  // Raise OnTransitioning event
  this.OnTransitioning();
  this.elapsedPlayback_reset();
  this.playbackCount_reset();
  // Reset queuedVideoAdParameters property
  this.queuedVideoAdParameters = null;
  // Reset thirdPartyAdParameters property
  this.thirdPartyAdParameters = null;

  // Set the adRequestState property for all registered ad packages to the waiting state.
  for (var conDefIDStr in this.adArray)
  {
    this.adArray[conDefIDStr].adRequestState = "waiting";
  }

  // Change ads for all registered ad packages
  var numPackages = this.adPackageArray.length;
  for (var i=0; i < numPackages; i++)
  {
    //document.getElementById("debugTA").value += "\n Requesting new ad(s) for Contract Definition of "+this.adPackageArray[i].conDefID+".";
    this.requestAd(this.adPackageArray[i].conDefID);
  }
};

DayPortFLVVideo.prototype.disableQueueProcessing = function()
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.disableQueueProcessing() called.";

  this.queueProcessingEnabled = false;
};

DayPortFLVVideo.prototype.dispatchEvent = function(objEvent, param1, param2, param3)
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.dispatchEvent() called.";

  // Call all registered listener functions for this event
  for (var listenerFunc in this.events[objEvent])
  {
    this.events[objEvent][listenerFunc](param1, param2, param3);
  }
};

DayPortFLVVideo.prototype.elapsedPlayback_reset = function()
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.elapsedPlayback_reset() called.";

  try
  {
    this.videoObject.SetVariable("videoCommand", "ElapsedPlaybackReset");
  }
  catch(errorObject)
  {
    // ActiveX method not supported/available, so broker request
    // Add command to the Queue
    this.addToQueue("ElapsedPlaybackReset");
  }
};

DayPortFLVVideo.prototype.enableQueueProcessing = function()
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.enableQueueProcessing() called.";

  if (this.queueProcessingEnabled)
  {
    // Processing is already enabled, so just return.
    return;
  }

  this.queueProcessingEnabled = true;

  if (this.queueProcessState == "inactive")
  {
    // The Queue is not currently being processed so begin processing
    this.processQueue();
  }
};

DayPortFLVVideo.prototype.fullScreen = function()
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.fullScreen() called.";

  /*
  // Raise OnBeforeFullScreen event
  this.OnBeforeFullScreen();
  */

  // Not implemented.
  return false;
};

DayPortFLVVideo.prototype.generateTag = function(id, width, height)
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.generateTag() called.";

  // Validate parameters, set default values if necessary
  if ((id == "") || (id == null) || (typeof id == "undefined"))
    id = "DayPortFLVObject_" + this.objectArrayIndex;

  if ((width == "") || (width == null) || (typeof width == "undefined"))
    width = "320";

  if ((height == "") || (height == null) || (typeof height == "undefined"))
    height = "240";

  this.videoID = id;
  this.width = width;
  this.height = height;

  var tmpObjStr = '<div id="' + id + '_videoContainer" style="width:' + width + 'px; height:' + height + 'px;"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" id="' + id + '" width="100%" height="100%" align="middle">' +
                  '<param name="allowScriptAccess" value="always" />' +
                  '<param name="movie" value="http://' + this.imageDomain + '/img/DayPortFlashPlayer.swf?v=20071011&videoWidth=' + width + '&videoHeight=' + height + '&objectArrayIndex=' + this.objectArrayIndex + '&domain=' + this.domain + '&lcn=' + this.localConnectionName + '&autoAdInsertion=' + this.autoAdInsertion + '" />' +
                  //'<param name="movie" value="http://cdn.dayport.com/vlnimg/img/PartnerPlayer/DayPortFlashPlayer.swf?v=20071011&videoWidth=' + width + '&videoHeight=' + height + '&objectArrayIndex=' + this.objectArrayIndex + '&domain=' + this.domain + '&lcn=' + this.localConnectionName + '&autoAdInsertion=' + this.autoAdInsertion + '" />' +
                  '<param name="quality" value="high" />' +
                  '<param name="bgcolor" value="#000000" />' +
                  '<param name="wmode" value="opaque" />' +
                  '<param name="menu" value="false" />' +
                  '<param name="scale" value="noscale" />' +
                  '<param name="salign" value="lt" />' +
                  '<embed src="http://' + this.imageDomain + '/img/DayPortFlashPlayer.swf?v=20071011&videoWidth=' + width + '&videoHeight=' + height + '&objectArrayIndex=' + this.objectArrayIndex + '&domain=' + this.domain + '&lcn=' + this.localConnectionName + '&autoAdInsertion=' + this.autoAdInsertion + '" quality="high" bgcolor="#000000" wmode="opaque" menu="false" scale="noscale" salign="lt" width="100%" height="100%" swLiveConnect=true id="' + id + '" name="' + id + '" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />' +
                  //'<embed src="http://cdn.dayport.com/vlnimg/img/PartnerPlayer/DayPortFlashPlayer.swf?v=20071011&videoWidth=' + width + '&videoHeight=' + height + '&objectArrayIndex=' + this.objectArrayIndex + '&domain=' + this.domain + '&lcn=' + this.localConnectionName + '&autoAdInsertion=' + this.autoAdInsertion + '" quality="high" bgcolor="#000000" wmode="opaque" menu="false" scale="noscale" salign="lt" width="100%" height="100%" swLiveConnect=true id="' + id + '" name="' + id + '" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />' +
                  '</object></div>';
  var numPackages = this.adPackageArray.length;
  if ((DayPortVideo.system.osPlatform == "Mac") && (DayPortVideo.system.browser == "Internet Explorer"))
  {
    tmpObjStr +=  '<span id="' + id + '_metadataRetriever" style="position:static; left:0px; top:0px; width:1px; height:1px; visibility:hidden; display:none;"></span>' +
                  '<span id="' + id + '_trackImageContainer" style="position:static; left:0px; top:0px; width:1px; height:1px; visibility:hidden; display:none;">' +
                  '  <img id="' + id + '_impressionTrackImage" src="" width="1" height="1" border="0" style="position:static; left:0px; top:0px; visibility:hidden; display:none;" />' +
                  '  <img id="' + id + '_completionTrackImage" src="" width="1" height="1" border="0" style="position:static; left:0px; top:0px; visibility:hidden; display:none;" />' +
                  '  <img id="' + id + '_externalImpressionTrackImage_1" src="" width="1" height="1" border="0" style="position:static; left:0px; top:0px; visibility:hidden; display:none;" />' +
                  '  <img id="' + id + '_externalCompletionTrackImage_1" src="" width="1" height="1" border="0" style="position:static; left:0px; top:0px; visibility:hidden; display:none;" />' +
                  '</span>' +
                  '<span id="' + id + '_thirdPartyAdRequester" style="position:static; left:0px; top:0px; width:1px; height:1px; visibility:hidden; display:none;"></span>' +
                  '<span id="' + id + '_adRequesterContainer" style="position:static; left:0px; top:0px; width:1px; height:1px; visibility:hidden; display:none;">';

    for (var i=0; i < numPackages; i++)
    {
      tmpObjStr += '<span id="' + id + '_adRequester_' + (i + 1) + '" style="position:static; left:0px; top:0px; width:1px; height:1px; visibility:hidden; display:none;"></span>';

      this.adArray["ConDef_"+this.adPackageArray[i].conDefID] = {
                                                                  adRequestRef:(i + 1),
                                                                  adRequestState:"uninitialized"
                                                                };
    }

    tmpObjStr +=  '</span>' +
                  '<span id="' + id + '_flashBroker" style="position:static; left:0px; top:0px; width:1px; height:1px; visibility:hidden; display:none;"></span>' +
                  '<scr' + 'ipt language="JavaScript" type="text/javascript" defer>' +
                  'setTimeout("DayPortVideo.objectArray[' + eval(this.objectArrayIndex) + '].video.mdRetrieverObject.style.position = \\"absolute\\"; ' +
                  'document.getElementById(\\"' + id + '_trackImageContainer\\").style.position = \\"absolute\\"; ' +
                  'document.getElementById(\\"' + id + '_thirdPartyAdRequester\\").style.position = \\"absolute\\"; ';

    /*
    for (var i=0; i < numPackages; i++)
    {
      tmpObjStr += 'document.getElementById(\\"' + id + '_adRequester_' + (i + 1) + '\\").style.position = \\"absolute\\"; ';
    }
    */
    tmpObjStr += 'document.getElementById(\\"' + id + '_adRequesterContainer\\").style.position = \\"absolute\\"; ';

    tmpObjStr +=  'DayPortVideo.objectArray[' + eval(this.objectArrayIndex) + '].video.flashBrokerObject.style.position = \\"absolute\\"; ' +
                  'DayPortVideo.objectArray[' + eval(this.objectArrayIndex) + '].video.flashBrokerObject.style.visibility = \\"visible\\"; ' +
                  'DayPortVideo.objectArray[' + eval(this.objectArrayIndex) + '].video.flashBrokerObject.style.display = \\"inline\\";", 100);' +
                  '</scr' + 'ipt>';
  }
  else
  {
    tmpObjStr +=  '<span id="' + id + '_metadataRetriever" style="position:absolute; left:0px; top:0px; width:1px; height:1px; visibility:hidden; display:none;"></span>' +
                  '<span id="' + id + '_trackImageContainer" style="position:absolute; left:0px; top:0px; width:1px; height:1px; visibility:hidden; display:none;">' +
                  '  <img id="' + id + '_impressionTrackImage" src="" width="1" height="1" border="0" style="position:absolute; left:0px; top:0px; visibility:hidden; display:none;" />' +
                  '  <img id="' + id + '_completionTrackImage" src="" width="1" height="1" border="0" style="position:absolute; left:0px; top:0px; visibility:hidden; display:none;" />' +
                  '  <img id="' + id + '_externalImpressionTrackImage_1" src="" width="1" height="1" border="0" style="position:absolute; left:0px; top:0px; visibility:hidden; display:none;" />' +
                  '  <img id="' + id + '_externalCompletionTrackImage_1" src="" width="1" height="1" border="0" style="position:absolute; left:0px; top:0px; visibility:hidden; display:none;" />' +
                  '</span>' +
                  '<span id="' + id + '_thirdPartyAdRequester" style="position:absolute; left:0px; top:0px; width:1px; height:1px; visibility:hidden; display:none;"></span>' +
                  '<span id="' + id + '_adRequesterContainer" style="position:absolute; left:0px; top:0px; width:1px; height:1px; visibility:hidden; display:none;">';

    for (var i=0; i < numPackages; i++)
    {
      tmpObjStr += '<span id="' + id + '_adRequester_' + (i + 1) + '" style="position:absolute; left:0px; top:0px; width:1px; height:1px; visibility:hidden; display:none;"></span>';

      this.adArray["ConDef_"+this.adPackageArray[i].conDefID] = {
                                                                  adRequestRef:(i + 1),
                                                                  adRequestState:"uninitialized"
                                                                };
    }

    tmpObjStr +=  '</span>';

    if (this.containerObject.style.position == "relative")
    {
      tmpObjStr += '<span id="' + id + '_flashBroker" style="position:absolute; left:0px; top:0px; width:1px; height:1px; z-index:1000;"></span>';
    }
    else
    {
      tmpObjStr += '<span id="' + id + '_flashBroker" style="position:absolute; left:0px; width:1px; height:1px; z-index:1000;"></span>';
    }
  }

  this.containerObject.innerHTML = tmpObjStr;

  this.mdRetrieverObject = document.getElementById(id+"_metadataRetriever");
  this.flashBrokerObject = document.getElementById(id+"_flashBroker");

  return document.getElementById(id);
};

DayPortFLVVideo.prototype.getDuration = function()
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.getDuration() called.";

  //var retDur = this.videoObject.GetVariable("videoData.metadata.duration");
  //document.getElementById("debugTA").value += "\n retDur="+retDur;

  return this.duration;
};

DayPortFLVVideo.prototype.getHeight = function()
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.getHeight() called.";

  //var retHeight = this.videoObject.height;
  //var retHeight = this.videoObject.GetVariable("videoObj._height");

  return this.height;
};

DayPortFLVVideo.prototype.getPosition = function()
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.getPosition() called.";

  try
  {
    this.currentPosition = this.videoObject.GetVariable("netStream.time");
    //document.getElementById("debugTA").value += "\n DayPortFLVVideo.currentPosition="+this.currentPosition;

    // Raise OnPositionUpdated event
    var target = this;
    setTimeout(function()
    {
      target.OnPositionUpdated();
    }, 10);

    return this.currentPosition;
  }
  catch(errorObject)
  {
    // ActiveX method not supported/available, so broker request
    // Add command to the Queue
    this.addToQueue("GetPosition");

    return null;
  }
};

DayPortFLVVideo.prototype.getWidth = function()
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.getWidth() called.";

  //var retWidth = this.videoObject.width;
  //var retWidth = this.videoObject.GetVariable("videoObj._width");

  return this.width;
};

// Seek forward or backward desired number of seconds
DayPortFLVVideo.prototype.jump = function(seconds, backward)
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.jump() called.";
  //document.getElementById("debugTA").value += "\n seconds="+seconds+", backward="+backward;

  if ((this.adState == "loading") || (this.adState == "playing"))
  {
    // Disallow seeking during ad playback
    return false;
  }

  if ((seconds == "") || (typeof seconds == "undefined") || isNaN(parseFloat(seconds)))
  {
    // Invalid seconds parameter so just return.
    return false;
  }

  // Force seconds parameter to a number.
  seconds = parseFloat(seconds);

  var durationseconds = this.getDuration();
  //document.getElementById("debugTA").value += "\n durationseconds="+durationseconds;

  if (durationseconds == null)
  {
    //document.getElementById("debugTA").value += "\n Duration was not set yet.";
    this.stop();

    return false;
  }

  if (backward)
  {
    backward = "true";
  }
  else
  {
    backward = "false";
  }

  try
  {
    this.videoObject.SetVariable("videoCommand", "Jump|"+escape(seconds)+","+escape(backward));
  }
  catch(errorObject)
  {
    // ActiveX method not supported/available, so broker request
    // Add command to the Queue
    this.addToQueue("Jump|"+escape(seconds)+","+escape(backward));
  }

  return true;
};

DayPortFLVVideo.prototype.mute = function(manual, mute)
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.mute() called.";

  if (manual)
  {
    if (mute)
    {
      //document.getElementById("debugTA").value += "\n Muting audio.";
      try
      {
        this.videoObject.SetVariable("videoCommand", "Mute|true");
      }
      catch(errorObject)
      {
        // ActiveX method not supported/available, so broker request
        // Add command to the Queue
        this.addToQueue("Mute|true");
      }
      this.muted = true;
      // Raise OnMute event
      this.OnMute();
    }
    else
    {
      //document.getElementById("debugTA").value += "\n Unmuting audio.";
      try
      {
        this.videoObject.SetVariable("videoCommand", "Mute|false");
      }
      catch(errorObject)
      {
        // ActiveX method not supported/available, so broker request
        // Add command to the Queue
        this.addToQueue("Mute|false");
      }
      this.muted = false;
      // Raise OnUnMute event
      this.OnUnMute();
    }
  }
  else
  {
    //if (this.videoObject.GetVariable("videoData.mute") == "false")
    if (!this.muted)
    {
      //document.getElementById("debugTA").value += "\n Muting audio.";
      try
      {
        this.videoObject.SetVariable("videoCommand", "Mute|true");
      }
      catch(errorObject)
      {
        // ActiveX method not supported/available, so broker request
        // Add command to the Queue
        this.addToQueue("Mute|true");
      }
      this.muted = true;
      // Raise OnMute event
      this.OnMute();
    }
    else
    {
      //document.getElementById("debugTA").value += "\n Unmuting audio.";
      try
      {
        this.videoObject.SetVariable("videoCommand", "Mute|false");
      }
      catch(errorObject)
      {
        // ActiveX method not supported/available, so broker request
        // Add command to the Queue
        this.addToQueue("Mute|false");
      }
      this.muted = false;
      // Raise OnUnMute event
      this.OnUnMute();
    }
  }
};

DayPortFLVVideo.prototype.OnBeforeFullScreen = function()
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.OnBeforeFullScreen() called.";

  // Dispatch event to registered listeners
  this.dispatchEvent("BeforeFullScreen");
};

DayPortFLVVideo.prototype.OnBuffering = function(bStart)
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.OnBuffering() called.";
  //document.getElementById("debugTA").value += "\n bStart="+bStart+", wasBuffering="+this.wasBuffering;

  // Convert bStart parameter to boolean equivalent if passed in as a string.
  if (typeof(bStart) == "string")
  {
    if (bStart.toLowerCase() == "true")
      bStart = true;
    else
      bStart = false;
  }

  if (bStart == this.wasBuffering)
  {
    // This buffering change has already been handled.
    return false;
  }

  this.wasBuffering = bStart;

  // Dispatch event to registered listeners
  this.dispatchEvent("Buffering", bStart);
};

// Event raised when DayPortFLVVideo.duration property is updated
DayPortFLVVideo.prototype.OnDurationUpdated = function(updateDuration, newDuration)
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.OnDurationUpdated() called.";
  //document.getElementById("debugTA").value += "\n updateDuration="+updateDuration+", newDuration="+newDuration;

  // See if the duration should be updated via passed in parameter
  if (updateDuration)
  {
    // Update duration
    this.duration = newDuration;
  }

  // Dispatch event to registered listeners
  this.dispatchEvent("DurationUpdated", this.duration);
};

DayPortFLVVideo.prototype.OnEndOfAd = function()
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.OnEndOfAd() called.";

  // Dispatch event to registered listeners
  this.dispatchEvent("EndOfAd");
};

DayPortFLVVideo.prototype.OnEndOfStream = function(lResult)
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.OnEndOfStream() called.";
  //document.getElementById("debugTA").value += "\n lResult="+lResult;

  // Convert lResult parameter to integer equivalent if passed in as a string.
  if (typeof(lResult) == "string")
  {
    lResult = parseInt(lResult, 10);
  }

  var tmpAdState = this.adState;

  this.stopUpdateStatus();

  // See if playback of the video completed successfully
  //document.getElementById("debugTA").value += "\n lResult="+lResult;
  if (lResult === 0)
  {
    //document.getElementById("debugTA").value += "\n Playback of the video completed successfully.";

    //document.getElementById("debugTA").value += "\n DayPortFLVVideo.completionTrackURL="+this.completionTrackURL;
    if (this.completionTrackURL != null)
    {
      // Track video via completion tracking URL
      document.getElementById(this.videoID+"_completionTrackImage").src = this.completionTrackURL;

      this.completionTrackURL = null;
    }

    //document.getElementById("debugTA").value += "\n DayPortFLVVideo.externalCompletionTrackURL="+this.externalCompletionTrackURL;
    if (this.externalCompletionTrackURL != null)
    {
      var numURLs = this.externalCompletionTrackURL.length;
      //document.getElementById("debugTA").value += "\n numURLs="+numURLs;
      for (var i=0; i < numURLs; i++)
      {
        var trackImageObj = document.getElementById(this.videoID+"_externalCompletionTrackImage_"+(i + 1));
        //document.getElementById("debugTA").value += "\n trackImageObj="+trackImageObj;
        // See if the impression tracking image exists
        if (trackImageObj)
        {
          // Track video via external completion tracking URL
          trackImageObj.src = this.externalCompletionTrackURL[i];
        }
        else
        {
          var imageObj = document.createElement("img");
          imageObj.id = this.videoID + "_externalCompletionTrackImage_" + (i + 1);
          imageObj.src = null;
          imageObj.width = 1;
          imageObj.height = 1;
          imageObj.border = 0;
          imageObj.style.position = "absolute";
          imageObj.style.left = "0px";
          imageObj.style.top = "0px";
          imageObj.style.visibility = "hidden";
          imageObj.style.display = "none";
          var trackImageContainerObj = document.getElementById(this.videoID+"_trackImageContainer");
          //document.getElementById("debugTA").value += "\n trackImageContainerObj="+trackImageContainerObj;
          if (trackImageContainerObj)
          {
            trackImageObj = trackImageContainerObj.appendChild(imageObj);

            // Track video via external completion tracking URL
            trackImageObj.src = this.externalCompletionTrackURL[i];
          }
        }
      }

      this.externalCompletionTrackURL = null;
    }
  }

  if (tmpAdState == "playing")
  {
    // See if a consecutive advertisement is queued for insertion
    //document.getElementById("debugTA").value += "\n DayPortFLVVideo.consecutiveAdQueued="+this.consecutiveAdQueued;
    if (this.autoAdInsertion && this.consecutiveAdQueued)
    {
      //document.getElementById("debugTA").value += "\n Advertisement finished, processing queued consecutive advertisement.";
      this.consecutiveAdQueued = false;
      this.adState = "queued";
      this.changeAds();
    }
    else
    {
      if (this.consecutiveAdQueued)
      {
        this.consecutiveAdQueued = false;
        this.adState = "queued";
      }
      else
      {
        this.adState = "inactive";
      }

      if (this.articleID != null)
      {
        //document.getElementById("debugTA").value += "\n Advertisement finished, triggering play of queued article (ID of "+this.articleID+").";
        var tmpArtID = this.articleID;
        if ((DayPortVideo.system.osPlatform == "Mac") && (DayPortVideo.system.browser == "Internet Explorer"))
        {
          setTimeout("DayPortVideo.objectArray[" + eval(this.objectArrayIndex) + "].video.setSource('article', " + tmpArtID + ");", 100);
        }
        else
        {
          var target = this;
          setTimeout(function()
          {
            target.setSource("article", tmpArtID);
          }, 100);
        }
      }
    }
  }

  // Dispatch event to registered listeners
  this.dispatchEvent("EndOfStream", tmpAdState, lResult);

  if (tmpAdState == "playing")
  {
    // Raise OnEndOfAd event
    this.OnEndOfAd();
  }
};

// Event raised when LocalConnection is opened (used for JavaScript to Flash communication)
DayPortFLVVideo.prototype.OnLCOpen = function(cnChanged, newCN)
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.OnLCOpen() called.";
  //document.getElementById("debugTA").value += "\n cnChanged="+cnChanged+", newCN="+newCN;

  // See if the connectionName was changed (due to original already being in use)
  if (cnChanged)
  {
    // change connectionName
    this.localConnectionName = newCN;
  }
};

DayPortFLVVideo.prototype.OnMetadataRetrieved = function()
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.OnMetadataRetrieved() called.";

  // Dispatch event to registered listeners
  this.dispatchEvent("MetadataRetrieved");
};

DayPortFLVVideo.prototype.OnMute = function()
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.OnMute() called.";

  // Dispatch event to registered listeners
  this.dispatchEvent("Mute");
};

DayPortFLVVideo.prototype.OnPageLoaded = function()
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.OnPageLoaded() called.";

  if (this.pageLoadedReceipt)
  {
    // Re-check the Queue for items to process
    this.processQueue();

    // OnPageLoaded event has already been raised in DayPortFlashPlayer, so just return.
    return;
  }

  try
  {
    this.videoObject.SetVariable("videoCommand", "OnPageLoaded");
  }
  catch(errorObject)
  {
    // ActiveX method not supported/available, so broker request
    if (this.queueProcessingEnabled)
    {
      // Disable processing of the Queue
      this.disableQueueProcessing();
    }

    this.queueProcessState = "inactive";
    // Add the item to the top of the Queue
    this.commandQueue.unshift("OnPageLoaded");

    // Enable processing of the Queue
    this.enableQueueProcessing();
  }
};

DayPortFLVVideo.prototype.OnPageLoadedReceipt = function()
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.OnPageLoadedReceipt() called.";

  this.pageLoadedReceipt = true;
};

DayPortFLVVideo.prototype.OnPaused = function()
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.OnPaused() called.";

  this.stopUpdateStatus();
  // Call updateStatus once to make sure synchronized.
  //this.updateStatus();
  this.getPosition();

  // Dispatch event to registered listeners
  this.dispatchEvent("Paused");
};

DayPortFLVVideo.prototype.OnPlaying = function()
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.OnPlaying() called.";

  if (this.autoAdInsertion && (this.adInsertionFrequency != null) && (this.adState != "playing"))
  {
    // Track playback of video
    this.playbackCount_track();
  }

  //document.getElementById("debugTA").value += "\n DayPortFLVVideo.impressionTrackURL="+this.impressionTrackURL;
  if (this.impressionTrackURL != null)
  {
    // Track video via impression tracking URL
    document.getElementById(this.videoID+"_impressionTrackImage").src = this.impressionTrackURL;

    this.impressionTrackURL = null;
  }

  //document.getElementById("debugTA").value += "\n DayPortFLVVideo.externalImpressionTrackURL="+this.externalImpressionTrackURL;
  if (this.externalImpressionTrackURL != null)
  {
    var numURLs = this.externalImpressionTrackURL.length;
    //document.getElementById("debugTA").value += "\n numURLs="+numURLs;
    for (var i=0; i < numURLs; i++)
    {
      var trackImageObj = document.getElementById(this.videoID+"_externalImpressionTrackImage_"+(i + 1));
      //document.getElementById("debugTA").value += "\n trackImageObj="+trackImageObj;
      // See if the impression tracking image exists
      if (trackImageObj)
      {
        // Track video via external impression tracking URL
        trackImageObj.src = this.externalImpressionTrackURL[i];
      }
      else
      {
        var imageObj = document.createElement("img");
        imageObj.id = this.videoID + "_externalImpressionTrackImage_" + (i + 1);
        imageObj.src = null;
        imageObj.width = 1;
        imageObj.height = 1;
        imageObj.border = 0;
        imageObj.style.position = "absolute";
        imageObj.style.left = "0px";
        imageObj.style.top = "0px";
        imageObj.style.visibility = "hidden";
        imageObj.style.display = "none";
        var trackImageContainerObj = document.getElementById(this.videoID+"_trackImageContainer");
        //document.getElementById("debugTA").value += "\n trackImageContainerObj="+trackImageContainerObj;
        if (trackImageContainerObj)
        {
          trackImageObj = trackImageContainerObj.appendChild(imageObj);

          // Track video via external impression tracking URL
          trackImageObj.src = this.externalImpressionTrackURL[i];
        }
      }
    }

    this.externalImpressionTrackURL = null;
  }

  this.startUpdateStatus();

  // Dispatch event to registered listeners
  this.dispatchEvent("Playing");
};

DayPortFLVVideo.prototype.OnPlayStateChange = function(newState)
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.OnPlayStateChange() called.";
  //document.getElementById("debugTA").value += "\n newState="+newState;

  // Convert newState parameter to integer equivalent if passed in as a string.
  if (typeof(newState) == "string")
  {
    newState = parseInt(newState, 10);
  }

  if (newState == this.currPlayState)
  {
    // This PlayState change has already been handled.
    return false;
  }

  this.prevPlayState = this.currPlayState;
  this.currPlayState = newState;

  // Dispatch event to registered listeners
  this.dispatchEvent("PlayStateChange", this.prevPlayState, this.currPlayState);

  // Handle PlayState change
  switch (newState)
  {
    case 0:
      // Playback is stopped.
      this.OnStopped();
      break;

    case 1:
      // Playback is paused.
      this.OnPaused();
      break;

    case 2:
      // Stream is playing.
      this.OnPlaying();
      break;

    case 3:
      // Waiting for stream to begin.
      break;

    case 4:
      // Stream is scanning forward.
      break;

    case 5:
      // Stream is scanning in reverse.
      break;

    case 6:
      // Skipping to next.
      break;

    case 7:
      // Skipping to previous.
      break;

    case 8:
      // Stream is not open.
      break;

    default:
  }
};

// Event raised when DayPortFLVVideo.currentPosition property is updated
DayPortFLVVideo.prototype.OnPositionUpdated = function(updatePosition, newPosition)
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.OnPositionUpdated() called.";
  //document.getElementById("debugTA").value += "\n updatePosition="+updatePosition+", newPosition="+newPosition;

  // See if the currentPosition should be updated via passed in parameter
  if (updatePosition)
  {
    // Update currentPosition
    this.currentPosition = newPosition;
  }

  // Dispatch event to registered listeners
  this.dispatchEvent("PositionUpdated", this.currentPosition);
};

// Event raised when it is detected that control of the embedded WMP object via script is not supported
DayPortWMVVideo.prototype.OnScriptControlUnsupported = function()
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.OnScriptControlUnsupported() called.";

  // Dispatch event to registered listeners
  this.dispatchEvent("ScriptControlUnsupported");
};

// Event raised when DayPortFLVVideo.adInsertionThreshold is reached to queue an advertisement for insertion
DayPortFLVVideo.prototype.OnQueueAd = function()
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.OnQueueAd() called.";

  if ((this.adState == "loading") || (this.adState == "playing"))
  {
    // An advertisement is currently being processed, so just return.
    return false;
  }

  if (this.adState == "queued")
  {
    // An advertisement is already queued, so just return.
    return true;
  }

  // Queue an advertisement for insertion
  this.adState = "queued";
  //document.getElementById("debugTA").value += "\n DayPortFLVVideo.adInsertionThreshold reached, queued an ad for insertion.";

  return true;
};

DayPortFLVVideo.prototype.OnStopped = function()
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.OnStopped() called.";

  this.stopUpdateStatus();

  // Reset currentPosition
  this.getPosition();

  // Dispatch event to registered listeners
  this.dispatchEvent("Stopped");
};

DayPortFLVVideo.prototype.OnTransitioning = function()
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.OnTransitioning() called.";

  // Dispatch event to registered listeners
  this.dispatchEvent("Transitioning");
};

DayPortFLVVideo.prototype.OnUnMute = function()
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.OnUnMute() called.";

  // Dispatch event to registered listeners
  this.dispatchEvent("UnMute");
};

DayPortFLVVideo.prototype.OnVideoCommandBrokered = function(success)
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.OnVideoCommandBrokered() called.";
  //document.getElementById("debugTA").value += "\n success="+success;

  // Convert success parameter to boolean equivalent if passed in as a string.
  if (typeof(success) == "string")
  {
    if (success.toLowerCase() == "true")
      success = true;
    else
      success = false;
  }

  this.queueProcessState = "processed";

  if (!this.pageLoadedReceipt)
  {
    // OnPageLoaded event has not been raised in DayPortFlashPlayer yet.
    if ((DayPortVideo.system.osPlatform == "Mac") && (DayPortVideo.system.browser == "Internet Explorer"))
    {
      // Raise OnPageLoaded event again in case previous attempts were not received (e.g., if DayPortFlashPlayer had not loaded yet)
      setTimeout("DayPortVideo.objectArray[" + eval(this.objectArrayIndex) + "].video.OnPageLoaded();", 1000);
    }
    else
    {
      // Raise OnPageLoaded event again in case previous attempts were not received (e.g., if DayPortFlashPlayer had not loaded yet)
      setTimeout("DayPortVideo.objectArray[" + eval(this.objectArrayIndex) + "].video.OnPageLoaded();", 500);
    }

    return;
  }

  // Re-check the Queue for items to process
  this.processQueue();
};

DayPortFLVVideo.prototype.pause = function()
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.pause() called.";

  try
  {
    //this.videoObject.TCallLabel("/VideoActions", "Pause");
    this.videoObject.SetVariable("videoCommand", "Pause");
  }
  catch(errorObject)
  {
    // ActiveX method not supported/available, so broker request
    // Add command to the Queue
    this.addToQueue("Pause");
  }
};

DayPortFLVVideo.prototype.play = function()
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.play() called.";

  try
  {
    //this.videoObject.TCallLabel("/VideoActions", "Play");
    this.videoObject.SetVariable("videoCommand", "Play");
  }
  catch(errorObject)
  {
    // ActiveX method not supported/available, so broker request
    // Add command to the Queue
    this.addToQueue("Play");
  }

  this.startUpdateStatus();
};

DayPortFLVVideo.prototype.playbackCount_reset = function()
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.playbackCount_reset() called.";

  this.trackedArticle = null;
  this.playbackCount = 0;
};

// Track playback of user-selected video
DayPortFLVVideo.prototype.playbackCount_track = function()
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.playbackCount_track() called.";

  // Don't track playback of advertisements
  if ((this.adState != "playing") && (this.articleID != this.trackedArticle))
  {
    // Flag this article as being tracked
    this.trackedArticle = this.articleID;

    // Increment playbackCount property
    this.playbackCount++;

    if ((this.adState != "queued") && (this.playbackCount >= this.adInsertionFrequency))
    {
      this.adState = "queued";
      //document.getElementById("debugTA").value += "\n DayPortFLVVideo.adInsertionFrequency reached, queued an ad for insertion.";
    }
  }

  //document.getElementById("debugTA").value += "\n playbackCount="+this.playbackCount+"\n adInsertionFrequency="+this.adInsertionFrequency+"\n adState="+this.adState;
};

DayPortFLVVideo.prototype.playPause = function()
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.playPause() called.";

  try
  {
    //this.videoObject.TCallLabel("/VideoActions", "PlayPause");
    this.videoObject.SetVariable("videoCommand", "PlayPause");
  }
  catch(errorObject)
  {
    // ActiveX method not supported/available, so broker request
    // Add command to the Queue
    this.addToQueue("PlayPause");
  }
};

DayPortFLVVideo.prototype.processQueue = function()
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.processQueue() called.";
  //document.getElementById("debugTA").value += "\n commandQueue="+this.commandQueue;

  if (this.queueProcessState == "processing")
  {
    // The Queue is currently being processed so just return.
    return;
  }

  this.queueProcessState = "processing";

  if (!this.queueProcessingEnabled)
  {
    // Processing of the Queue is disabled so reset queueProcessState property and return.
    this.queueProcessState = "inactive";
    return;
  }

  if (this.commandQueue.length == 0)
  {
    // The Queue is empty so reset queueProcessState property and return.
    this.queueProcessState = "inactive";
    return;
  }

  // Get next item from the Queue
  var processItem = this.commandQueue.shift();

  // Process the item
  this.brokerVideoCommand(processItem);
};

// Manually queue an advertisement for insertion
DayPortFLVVideo.prototype.queueAd = function(allowConsecutiveAds)
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.queueAd() called.";
  //document.getElementById("debugTA").value += "\n allowConsecutiveAds="+allowConsecutiveAds;

  //document.getElementById("debugTA").value += "\n DayPortFLVVideo.adState="+this.adState;
  if ((this.adState == "loading") || (this.adState == "playing"))
  {
    if (allowConsecutiveAds)
    {
      // Queue a consecutive advertisement for insertion
      this.consecutiveAdQueued = true;
      //document.getElementById("debugTA").value += "\n Manually queued a consecutive ad for insertion.";

      return true;
    }
    else
    {
      // An advertisement is currently being processed so just return.
      return false;
    }
  }

  if (this.adState == "queued")
  {
    // An advertisement is already queued, so just return.
    return true;
  }

  // Queue an advertisement for insertion
  this.adState = "queued";
  //document.getElementById("debugTA").value += "\n Manually queued an ad for insertion.";

  return true;
};

DayPortFLVVideo.prototype.registerElement = function(idStr)
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.registerElement() called.";
  //document.getElementById("debugTA").value += "\n idStr="+idStr;

  // Force idStr parameter to lower case if passed in as a string.
  if (typeof(idStr) == "string")
  {
    idStr = idStr.toLowerCase();
  }

  var numArgs = arguments.length;
  switch (idStr)
  {
    case "bannerad":
      if (numArgs < 2)
      {
        //document.getElementById("debugTA").value += "\n Invalid number of arguments for ID string of 'bannerad'. (arguments="+arguments+")";
        return false;
      }

      if (typeof arguments[1] != "object")
      {
        // Invalid parameters type
        //document.getElementById("debugTA").value += "\n Invalid parameters type. (type="+typeof(arguments[1])+")";
        return false;
      }

      // Determine next available element name
      var limitReached = true;
      for (var i=1; i < 101; i++)
      {
        if (typeof this.elements["bannerAd_"+i] == "undefined")
        {
          limitReached = false;
          break;
        }
      }

      if (limitReached)
      {
        //document.getElementById("debugTA").value += "\n Maximum limit of registered banner ad elements ("+i+") has been reached.";
        return false;
      }

      // Validate Contract Definition ID and Object ID reference
      var invalidRef = true;
      var numPackages = this.adPackageArray.length;
      for (var ci=0; ci < numPackages; ci++)
      {
        if (this.adPackageArray[ci].conDefID == arguments[1].conDefID)
        {
          var numObjects = this.adPackageArray[ci].objects.length;
          for (var oi=0; oi < numObjects; oi++)
          {
            if (this.adPackageArray[ci].objects[oi].objectID == arguments[1].objectID)
            {
              invalidRef = false;
              break;
            }
          }
          break;
        }
      }

      if (invalidRef)
      {
        //document.getElementById("debugTA").value += "\n Invalid Contract Definition ID and/or Object ID reference(s).";
        return false;
      }

      // Register Banner ad
      this.elements["bannerAd_"+i] = new Object();
      this.elements["bannerAd_"+i].idStr = idStr;
      this.elements["bannerAd_"+i].containerObject = arguments[1].containerObject;
      this.elements["bannerAd_"+i].width = arguments[1].width;
      this.elements["bannerAd_"+i].height = arguments[1].height;
      this.elements["bannerAd_"+i].conDefID = arguments[1].conDefID;
      this.elements["bannerAd_"+i].objectID = arguments[1].objectID;

      var imageObj = document.createElement("img");
      imageObj.id = this.videoID + "_impressionTrackImage_bannerAd_" + i;
      imageObj.src = "";
      imageObj.width = 1;
      imageObj.height = 1;
      imageObj.border = 0;
      imageObj.style.position = "absolute";
      imageObj.style.left = "0px";
      imageObj.style.top = "0px";
      imageObj.style.visibility = "hidden";
      imageObj.style.display = "none";
      var trackImageContainerObj = document.getElementById(this.videoID+"_trackImageContainer");
      //document.getElementById("debugTA").value += "\n trackImageContainerObj="+trackImageContainerObj;
      if (trackImageContainerObj)
      {
        this.elements["bannerAd_"+i].impressionTrackImageObject = trackImageContainerObj.appendChild(imageObj);
      }
      else
      {
        this.elements["bannerAd_"+i].impressionTrackImageObject = null;
      }

      // Update associated elementRef property in adPackageArray
      this.adPackageArray[ci].objects[oi].elementRef = i;
      break;

    default:
      // Invalid ID string
      //document.getElementById("debugTA").value += "\n Invalid ID string. (idStr="+idStr+")";
      return false;
  }

  return true;
};

DayPortFLVVideo.prototype.registerEventListener = function(objEvent, listenerFunc)
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.registerEventListener() called.";

  if (typeof this.events[objEvent] == "undefined")
  {
    // This event cannot be registered for
    return false;
  }

  if (typeof listenerFunc != "function")
  {
    // Listener is not a function
    return false;
  }

  if (typeof this.events[objEvent][listenerFunc] != "undefined")
  {
    // This listener function has already been registered for this event
    return true;
  }

  // Register event listener
  this.events[objEvent][listenerFunc] = listenerFunc;

  return true;
};

// Request an ad contract from a contract definition.
DayPortFLVVideo.prototype.requestAd = function(conDefID)
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.requestAd() called.";
  //document.getElementById("debugTA").value += "\n conDefID="+conDefID;

  this.adArray["ConDef_"+conDefID].adRequestState = "loading";

  var rndm = DayPortVideo.genRandom();
  if ((DayPortVideo.system.osPlatform == "Mac") && (DayPortVideo.system.browser == "Internet Explorer"))
  {
    setTimeout("document.getElementById('" + this.videoID + "_adRequester_" + this.adArray["ConDef_"+conDefID].adRequestRef + "').innerHTML = '_<scr' + 'ipt id=\"" + this.videoID + "_adRequesterJS_" + this.adArray["ConDef_"+conDefID].adRequestRef + "\" language=\"JavaScript\" type=\"text/javascript\" src=\"http://" + this.domain + "/ads/select/" + conDefID + "/?extended=true&mt=1&rndm=" + rndm + "\" defer></scr' + 'ipt>';", 100);
  }
  else if ((DayPortVideo.system.osPlatform == "Mac") && (DayPortVideo.system.browser == "Safari"))
  {
    document.getElementById(this.videoID+"_adRequester_"+this.adArray["ConDef_"+conDefID].adRequestRef).innerHTML = "";
    var scrObj = document.createElement("script");
    scrObj.id = this.videoID + "_adRequesterJS_" + this.adArray["ConDef_"+conDefID].adRequestRef;
    scrObj.defer = true;
    scrObj.src = "http://" + this.domain + "/ads/select/" + conDefID + "/?extended=true&mt=1&rndm=" + rndm;
    var target = this;
    setTimeout(function()
    {
      document.getElementById(target.videoID+"_adRequester_"+target.adArray["ConDef_"+conDefID].adRequestRef).appendChild(scrObj);
    }, 10);
  }
  else
  {
    document.getElementById(this.videoID+"_adRequester_"+this.adArray["ConDef_"+conDefID].adRequestRef).innerHTML = '_<scr' + 'ipt id="' + this.videoID + '_adRequesterJS_' + this.adArray["ConDef_"+conDefID].adRequestRef + '" language="JavaScript" type="text/javascript" defer></scr' + 'ipt>';
    var target = this;
    setTimeout(function()
    {
      document.getElementById(target.videoID+"_adRequesterJS_"+target.adArray["ConDef_"+conDefID].adRequestRef).src = "http://" + target.domain + "/ads/select/" + conDefID + "/?extended=true&mt=1&rndm=" + rndm;
    }, 10);
  }
};

// Callback for DayPortFLVVideo.requestAd method.
DayPortFLVVideo.prototype.requestAdCB = function(adObj)
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.requestAdCB() called.";
  //document.getElementById("debugTA").value += "\n adObj="+adObj;

  /*
  var tmpStr = "";
  for (var prop in adObj)
  {
    tmpStr += "\n  " + prop + "=" + adObj[prop];

    for (var prop2 in adObj[prop])
    {
      tmpStr += "\n   " + prop2 + "=" + adObj[prop][prop2];

      for (var prop3 in adObj[prop][prop2])
      {
        tmpStr += "\n    " + prop3 + "=" + adObj[prop][prop2][prop3];

        for (var prop4 in adObj[prop][prop2][prop3])
        {
          tmpStr += "\n     " + prop4 + "=" + adObj[prop][prop2][prop3][prop4];

          for (var prop5 in adObj[prop][prop2][prop3][prop4])
          {
            tmpStr += "\n      " + prop5 + "=" + adObj[prop][prop2][prop3][prop4][prop5];
          }
        }
      }
    }
  }
  document.getElementById("debugTA").value += tmpStr;
  */

  document.getElementById(this.videoID+"_adRequester_"+this.adArray["ConDef_"+adObj.conDefID].adRequestRef).innerHTML = "";
  this.adArray["ConDef_"+adObj.conDefID].adRequestState = "loaded";

  //document.getElementById("debugTA").value += "\n conDefID="+adObj.conDefID+", contractID="+adObj.contractID;
  if (adObj.contractID == -1)
  {
    // No active contracts for selected contract definition pool
    // See if there are any other ad packages still waiting or loading
    var lastAdPackage = true;
    for (var conDefIDStr in this.adArray)
    {
      if ((this.adArray[conDefIDStr].adRequestState == "waiting") || (this.adArray[conDefIDStr].adRequestState == "loading"))
      {
        lastAdPackage = false;
        break;
      }
    }

    // Callback for last ad package should handle changing the adState property
    //document.getElementById("debugTA").value += "\n lastAdPackage="+lastAdPackage;
    if (lastAdPackage)
    {
      //document.getElementById("debugTA").value += "\n DayPortFLVVideo.thirdPartyAdParameters="+this.thirdPartyAdParameters;
      if ((this.thirdPartyAdParameters != null) && (this.thirdPartyAdParameters.video != null))
      {
        //document.getElementById("debugTA").value += "\n Requesting new ad(s) from a third-party system.";
        this.requestThirdPartyAd();
      }
      else
      {
        if ((this.thirdPartyAdParameters != null) && (this.thirdPartyAdParameters.video == null))
        {
          //document.getElementById("debugTA").value += "\n Missing video placeholder for a third-party ad reqeust detected.";
          // Reset thirdPartyAdParameters property
          this.thirdPartyAdParameters = null;
        }

        // Need to handle changing the adState property
        // Set the source to a video advertisement if one queued from other ad package, or look for a queued article

        this.processingAdPackages = false;

        // See if ad-package settings changes have been queued
        if ((this.queuedAdPackageArray != null) && (this.queuedBannerAdElementArray != null))
        {
          this.setAdPackages(this.queuedAdPackageArray, this.queuedBannerAdElementArray);
        }

        //document.getElementById("debugTA").value += "\n DayPortFLVVideo.queuedVideoAdParameters="+this.queuedVideoAdParameters;
        if (this.queuedVideoAdParameters != null)
        {
          this.setSource("advertisement", this.queuedVideoAdParameters.objID, this.queuedVideoAdParameters.contractID, this.queuedVideoAdParameters.clickURL, this.queuedVideoAdParameters.impressionTrackURL, this.queuedVideoAdParameters.externalImpressionTrackURL, this.queuedVideoAdParameters.completionTrackURL, this.queuedVideoAdParameters.externalCompletionTrackURL, this.queuedVideoAdParameters.videoURL);

          if (this.adInsertionChangeInterval != null)
          {
            // Track insertion of video advertisement
            this.adInsertionCount_track();
          }

          // Reset queuedVideoAdParameters property
          this.queuedVideoAdParameters = null;
        }
        else
        {
          if (this.metadataState == "loading")
          {
            // Let callback for DayPortFLVVideo.retrieveMetadata method (DayPortFLVVideo.retrieveMetadataCB method) handle continuing on
            this.adState = "inactive";
          }
          else
          {
            this.adState = "inactive";

            if (this.articleID != null)
            {
              // Raise OnEndOfAd event
              this.OnEndOfAd();

              //document.getElementById("debugTA").value += "\n No advertisement to play, triggering play of queued article (ID of "+this.articleID+").";
              this.setSource("article", this.articleID);
            }
            else
            {
              if (this.currPlayState != 0)
              {
                this.stop();
              }
              else
              {
                // Raise OnStopped event
                this.OnStopped();
              }

              // Raise OnEndOfAd event
              this.OnEndOfAd();
            }
          }
        }
      }
    }

    return;
  }

  var numItems = adObj.contractItems.length;
  //document.getElementById("debugTA").value += "\n numItems="+numItems;
  var numPackages = this.adPackageArray.length;
  //document.getElementById("debugTA").value += "\n numPackages="+numPackages;
  for (var ci=0; ci < numPackages; ci++)
  {
    //document.getElementById("debugTA").value += "\n this.adPackageArray["+ci+"].conDefID="+this.adPackageArray[ci].conDefID;
    if (this.adPackageArray[ci].conDefID == adObj.conDefID)
    {
      var numObjects = this.adPackageArray[ci].objects.length;
      //document.getElementById("debugTA").value += "\n numObjects="+numObjects;
      for (var i=0; i < numItems; i++)
      {
        //document.getElementById("debugTA").value += "\n description="+adObj.contractItems[i].description+", typeID="+adObj.contractItems[i].typeID+", objID="+adObj.contractItems[i].objID;
        for (var oi=0; oi < numObjects; oi++)
        {
          //document.getElementById("debugTA").value += "\n this.adPackageArray["+ci+"].objects["+oi+"].objectID="+this.adPackageArray[ci].objects[oi].objectID;
          if (this.adPackageArray[ci].objects[oi].objectID == adObj.contractItems[i].objID)
          {
            var adType = this.adPackageArray[ci].objects[oi].adType;
            // Force adType parameter to lower case if passed in as a string.
            if (typeof(adType) == "string")
            {
              adType = adType.toLowerCase();
            }

            //document.getElementById("debugTA").value += "\n adType="+adType;
            switch (adType)
            {
              case "video":
                // Video Ad
                // See if contract item is a placeholder for a request to a third-party system
                //document.getElementById("debugTA").value += "\n adObj.contractItems["+i+"].placeholder="+adObj.contractItems[i].placeholder;
                if (typeof adObj.contractItems[i].placeholder != "undefined")
                {
                  // Third-party system
                  //document.getElementById("debugTA").value += "\n DayPortFLVVideo.thirdPartyAdParameters="+this.thirdPartyAdParameters;
                  if (this.thirdPartyAdParameters == null)
                  {
                    // Initialize thirdPartyAdParameters property
                    this.thirdPartyAdParameters = {
                      adRequestState:"waiting",
                      banners:[],
                      ord:DayPortVideo.genRandom(),
                      video:null
                    };
                  }

                  // Process/map response data
                  // DoubleClick format
                  this.thirdPartyAdParameters.video = {
                    completionTrackURL:"",
                    impressionTrackURL:adObj.contractItems[i].trackURL,
                    requestURL:adObj.contractItems[i].placeholder.url
                  };

                  if (this.thirdPartyAdParameters.video.completionTrackURL != "")
                  {
                    // Add random value to the URL to help prevent caching
                    this.thirdPartyAdParameters.video.completionTrackURL += DayPortVideo.appendRandom(this.thirdPartyAdParameters.video.completionTrackURL);
                  }

                  if (this.thirdPartyAdParameters.video.impressionTrackURL != "")
                  {
                    // Add random value to the URL to help prevent caching
                    this.thirdPartyAdParameters.video.impressionTrackURL += DayPortVideo.appendRandom(this.thirdPartyAdParameters.video.impressionTrackURL);
                  }

                  if (this.thirdPartyAdParameters.video.requestURL != "")
                  {
                    // Add random value to the URL to help prevent caching
                    this.thirdPartyAdParameters.video.requestURL = this.thirdPartyAdParameters.video.requestURL.toString().replace("[timestamp]", this.thirdPartyAdParameters.ord);
                  }
                }
                else
                {
                  // DayPort system
                  // Queue setting the source to the advertisement video
                  this.queuedVideoAdParameters = {
                    objID:adObj.contractItems[i].objID,
                    contractID:adObj.contractID,
                    clickURL:adObj.contractItems[i].clickURL,
                    impressionTrackURL:adObj.contractItems[i].trackURL,
                    externalImpressionTrackURL:[adObj.contractItems[i].trackURL_external],
                    completionTrackURL:"",
                    externalCompletionTrackURL:[""],
                    videoURL:null
                  };

                  if (this.queuedVideoAdParameters.impressionTrackURL != "")
                  {
                    // Add random value to the URL to help prevent caching
                    this.queuedVideoAdParameters.impressionTrackURL += DayPortVideo.appendRandom(this.queuedVideoAdParameters.impressionTrackURL);
                  }

                  if (this.queuedVideoAdParameters.externalImpressionTrackURL[0] != "")
                  {
                    // Add random value to the URL to help prevent caching
                    this.queuedVideoAdParameters.externalImpressionTrackURL[0] += DayPortVideo.appendRandom(this.queuedVideoAdParameters.externalImpressionTrackURL[0]);
                  }
                  else
                  {
                    this.queuedVideoAdParameters.externalImpressionTrackURL = null;
                  }

                  if (this.queuedVideoAdParameters.completionTrackURL != "")
                  {
                    // Add random value to the URL to help prevent caching
                    this.queuedVideoAdParameters.completionTrackURL += DayPortVideo.appendRandom(this.queuedVideoAdParameters.completionTrackURL);
                  }

                  if (this.queuedVideoAdParameters.externalCompletionTrackURL[0] != "")
                  {
                    // Add random value to the URL to help prevent caching
                    this.queuedVideoAdParameters.externalCompletionTrackURL[0] += DayPortVideo.appendRandom(this.queuedVideoAdParameters.externalCompletionTrackURL[0]);
                  }
                  else
                  {
                    this.queuedVideoAdParameters.externalCompletionTrackURL = null;
                  }
                  //document.getElementById("debugTA").value += "\n Queued setting the source to the advertisement video.";
                }
                break;

              case "bannerad":
                // Banner Ad
                // Verify element is registered
                if (this.adPackageArray[ci].objects[oi].elementRef != null)
                {
                  var elementRef = this.adPackageArray[ci].objects[oi].elementRef;

                  // See if contract item is a placeholder for a request to a third-party system
                  //document.getElementById("debugTA").value += "\n adObj.contractItems["+i+"].placeholder="+adObj.contractItems[i].placeholder;
                  if (typeof adObj.contractItems[i].placeholder != "undefined")
                  {
                    // Third-party system
                    //document.getElementById("debugTA").value += "\n DayPortFLVVideo.thirdPartyAdParameters="+this.thirdPartyAdParameters;
                    if (this.thirdPartyAdParameters == null)
                    {
                      // Initialize thirdPartyAdParameters property
                      this.thirdPartyAdParameters = {
                        adRequestState:"waiting",
                        banners:[],
                        video:null
                      };
                    }

                    var bannerIndex = this.thirdPartyAdParameters.banners.length;

                    // Process/map response data
                    // DoubleClick format
                    this.thirdPartyAdParameters.banners[bannerIndex] = {
                      calloutURL:adObj.contractItems[i].placeholder.url,
                      elementRef:elementRef,
                      impressionTrackURL:adObj.contractItems[i].trackURL
                    };

                    if (this.thirdPartyAdParameters.banners[bannerIndex].calloutURL != "")
                    {
                      // Add random value to the URL to help prevent caching
                      this.thirdPartyAdParameters.banners[bannerIndex].calloutURL = this.thirdPartyAdParameters.banners[bannerIndex].calloutURL.toString().replace("[timestamp]", this.thirdPartyAdParameters.ord);
                    }

                    if (this.thirdPartyAdParameters.banners[bannerIndex].impressionTrackURL != "")
                    {
                      // Add random value to the URL to help prevent caching
                      this.thirdPartyAdParameters.banners[bannerIndex].impressionTrackURL += DayPortVideo.appendRandom(this.thirdPartyAdParameters.banners[bannerIndex].impressionTrackURL);
                    }
                  }
                  else
                  {
                    // DayPort system
                    this.setAd(this.elements["bannerAd_"+elementRef].containerObject, adObj.conDefID, adObj.contractItems[i].objID, adObj.contractID, this.adPackageArray[ci].objects[oi].track, this.elements["bannerAd_"+elementRef].width, this.elements["bannerAd_"+elementRef].height, adObj.contractItems[i].typeID);
                  }
                }
                break;
            }
            break;
          }
        }
      }
      break;
    }
  }

  // See if there are any other ad packages still waiting or loading
  var lastAdPackage = true;
  for (var conDefIDStr in this.adArray)
  {
    if ((this.adArray[conDefIDStr].adRequestState == "waiting") || (this.adArray[conDefIDStr].adRequestState == "loading"))
    {
      lastAdPackage = false;
      break;
    }
  }

  // Callback for last ad package should handle changing the adState property
  //document.getElementById("debugTA").value += "\n lastAdPackage="+lastAdPackage;
  if (lastAdPackage)
  {
    //document.getElementById("debugTA").value += "\n DayPortFLVVideo.thirdPartyAdParameters="+this.thirdPartyAdParameters;
    if ((this.thirdPartyAdParameters != null) && (this.thirdPartyAdParameters.video != null))
    {
      //document.getElementById("debugTA").value += "\n Requesting new ad(s) from a third-party system.";
      this.requestThirdPartyAd();
    }
    else
    {
      if ((this.thirdPartyAdParameters != null) && (this.thirdPartyAdParameters.video == null))
      {
        //document.getElementById("debugTA").value += "\n Missing video placeholder for a third-party ad reqeust detected.";
        // Reset thirdPartyAdParameters property
        this.thirdPartyAdParameters = null;
      }

      // Need to handle changing the adState property
      // Set the source to a video advertisement if one queued from other ad package, or look for a queued article

      this.processingAdPackages = false;

      // See if ad-package settings changes have been queued
      if ((this.queuedAdPackageArray != null) && (this.queuedBannerAdElementArray != null))
      {
        this.setAdPackages(this.queuedAdPackageArray, this.queuedBannerAdElementArray);
      }

      //document.getElementById("debugTA").value += "\n DayPortFLVVideo.queuedVideoAdParameters="+this.queuedVideoAdParameters;
      if (this.queuedVideoAdParameters != null)
      {
        this.setSource("advertisement", this.queuedVideoAdParameters.objID, this.queuedVideoAdParameters.contractID, this.queuedVideoAdParameters.clickURL, this.queuedVideoAdParameters.impressionTrackURL, this.queuedVideoAdParameters.externalImpressionTrackURL, this.queuedVideoAdParameters.completionTrackURL, this.queuedVideoAdParameters.externalCompletionTrackURL, this.queuedVideoAdParameters.videoURL);

        if (this.adInsertionChangeInterval != null)
        {
          // Track insertion of video advertisement
          this.adInsertionCount_track();
        }

        // Reset queuedVideoAdParameters property
        this.queuedVideoAdParameters = null;
      }
      else
      {
        if (this.metadataState == "loading")
        {
          // Let callback for DayPortFLVVideo.retrieveMetadata method (DayPortFLVVideo.retrieveMetadataCB method) handle continuing on
          this.adState = "inactive";
        }
        else
        {
          this.adState = "inactive";

          if (this.articleID != null)
          {
            // Raise OnEndOfAd event
            this.OnEndOfAd();

            //document.getElementById("debugTA").value += "\n No advertisement to play, triggering play of queued article (ID of "+this.articleID+").";
            this.setSource("article", this.articleID);
          }
          else
          {
            if (this.currPlayState != 0)
            {
              this.stop();
            }
            else
            {
              // Raise OnStopped event
              this.OnStopped();
            }

            // Raise OnEndOfAd event
            this.OnEndOfAd();
          }
        }
      }
    }
  }
};

// Request an ad contract from a third-party ad system.
DayPortFLVVideo.prototype.requestThirdPartyAd = function()
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.requestThirdPartyAd() called.";

  //document.getElementById("debugTA").value += "\n DayPortFLVVideo.thirdPartyAdParameters="+this.thirdPartyAdParameters;
  if (this.thirdPartyAdParameters == null)
  {
    // Third-party ad parameters not set so just return
    //document.getElementById("debugTA").value += "\n Third-party ad parameters not set.";
    return false;
  }

  /*
  var tmpStr = "";
  for (var prop in this.thirdPartyAdParameters)
  {
    tmpStr += "\n  " + prop + "=" + this.thirdPartyAdParameters[prop];

    for (var prop2 in this.thirdPartyAdParameters[prop])
    {
      tmpStr += "\n   " + prop2 + "=" + this.thirdPartyAdParameters[prop][prop2];

      for (var prop3 in this.thirdPartyAdParameters[prop][prop2])
      {
        tmpStr += "\n    " + prop3 + "=" + this.thirdPartyAdParameters[prop][prop2][prop3];
      }
    }
  }
  document.getElementById("debugTA").value += tmpStr;
  */

  this.thirdPartyAdParameters.adRequestState = "loading";

  if ((DayPortVideo.system.osPlatform == "Mac") && (DayPortVideo.system.browser == "Internet Explorer"))
  {
    setTimeout("document.getElementById('" + this.videoID + "_thirdPartyAdRequester').innerHTML = '_<scr' + 'ipt id=\"" + this.videoID + "_thirdPartyAdRequesterJS\" language=\"JavaScript\" type=\"text/javascript\" src=\"" + this.thirdPartyAdParameters.video.requestURL + "\" defer></scr' + 'ipt>';", 100);
  }
  else
  {
    document.getElementById(this.videoID+"_thirdPartyAdRequester").innerHTML = "";
    var scriptObj = document.createElement("script");
    scriptObj.id = this.videoID + "_thirdPartyAdRequesterJS";
    scriptObj.defer = true;
    scriptObj.src = this.thirdPartyAdParameters.video.requestURL;
    var target = this;
    setTimeout(function()
    {
      document.getElementById(target.videoID+"_thirdPartyAdRequester").appendChild(scriptObj);
    }, 10);
  }

  return true;
};

// Callback for DayPortFLVVideo.requestThirdPartyAd method.
DayPortFLVVideo.prototype.requestThirdPartyAdCB = function(adObject)
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.requestThirdPartyAdCB() called.";
  //document.getElementById("debugTA").value += "\n adObject="+adObject;

  /*
  var tmpStr = "";
  for (var prop in adObject)
  {
    tmpStr += "\n  " + prop + "=" + adObject[prop];
  }
  document.getElementById("debugTA").value += tmpStr;
  */

  document.getElementById(this.videoID+"_thirdPartyAdRequester").innerHTML = "";
  this.thirdPartyAdParameters.adRequestState = "loaded";

  // Set default values for the response data
  this.thirdPartyAdParameters.video.clickURL = "";
  this.thirdPartyAdParameters.video.externalImpressionTrackURL = null;
  this.thirdPartyAdParameters.video.externalCompletionTrackURL = null;
  this.thirdPartyAdParameters.video.videoURL = null;

  // Process/map response data
  // DoubleClick format
  this.thirdPartyAdParameters.video.clickURL = adObject.clickURL;
  this.videoAdName = adObject.adname;

  var numURLs = adObject.impression.length;
  //document.getElementById("debugTA").value += "\n numURLs="+numURLs;
  for (var i=0; i < numURLs; i++)
  {
    if (adObject.impression[i] != "")
    {
      if (this.thirdPartyAdParameters.video.externalImpressionTrackURL == null)
      {
        this.thirdPartyAdParameters.video.externalImpressionTrackURL = new Array();
      }

      // Add random value to the URL to help prevent caching
      this.thirdPartyAdParameters.video.externalImpressionTrackURL[this.thirdPartyAdParameters.video.externalImpressionTrackURL.length] = adObject.impression[i] + DayPortVideo.appendRandom(adObject.impression[i]);
    }
  }

  var numURLs = adObject.click.length;
  //document.getElementById("debugTA").value += "\n numURLs="+numURLs;
  for (var i=0; i < numURLs; i++)
  {
    if (adObject.click[i] != "")
    {
      if (this.thirdPartyAdParameters.video.externalCompletionTrackURL == null)
      {
        this.thirdPartyAdParameters.video.externalCompletionTrackURL = new Array();
      }

      // Add random value to the URL to help prevent caching
      this.thirdPartyAdParameters.video.externalCompletionTrackURL[this.thirdPartyAdParameters.video.externalCompletionTrackURL.length] = adObject.click[i] + DayPortVideo.appendRandom(adObject.click[i]);
    }
  }

  this.thirdPartyAdParameters.video.videoURL = adObject.flvhigh;

  var numBanners = this.thirdPartyAdParameters.banners.length;
  //document.getElementById("debugTA").value += "\n numBanners="+numBanners;
  for (var i=0; i < numBanners; i++)
  {
    // Add the ad ID to the callout URL
    this.thirdPartyAdParameters.banners[i].calloutURL = this.thirdPartyAdParameters.banners[i].calloutURL.replace("[adID]", adObject.adid);
    //document.getElementById("debugTA").value += "\n DayPortFLVVideo.thirdPartyAdParameters.banners["+i+"].calloutURL="+this.thirdPartyAdParameters.banners[i].calloutURL;

    // Set the callout method to use
    this.thirdPartyAdParameters.banners[i].calloutMethod = "javascript";
  }


  // Set banner ad(s)
  for (var i=0; i < numBanners; i++)
  {
    var elementRef = this.thirdPartyAdParameters.banners[i].elementRef;

    this.setAd(this.elements["bannerAd_"+elementRef].containerObject, null, null, null, null, this.elements["bannerAd_"+elementRef].width, this.elements["bannerAd_"+elementRef].height, null, this.thirdPartyAdParameters.banners[i].calloutURL, this.thirdPartyAdParameters.banners[i].calloutMethod);

    //document.getElementById("debugTA").value += "\n DayPortFLVVideo.thirdPartyAdParameters.banners["+i+"].impressionTrackURL="+this.thirdPartyAdParameters.banners[i].impressionTrackURL;
    if (this.thirdPartyAdParameters.banners[i].impressionTrackURL != null)
    {
      // Track banner via impression tracking URL
      this.elements["bannerAd_"+elementRef].impressionTrackImageObject.src = this.thirdPartyAdParameters.banners[i].impressionTrackURL;
    }
  }

  // Need to handle changing the adState property
  // Set the source to a video advertisement if one returned in response data, or look for a queued article

  this.processingAdPackages = false;

  // See if ad-package settings changes have been queued
  if ((this.queuedAdPackageArray != null) && (this.queuedBannerAdElementArray != null))
  {
    this.setAdPackages(this.queuedAdPackageArray, this.queuedBannerAdElementArray);
  }

  //document.getElementById("debugTA").value += "\n DayPortFLVVideo.thirdPartyAdParameters.video.videoURL="+this.thirdPartyAdParameters.video.videoURL;
  if ((typeof this.thirdPartyAdParameters.video.videoURL != "undefined") && (this.thirdPartyAdParameters.video.videoURL != null))
  {
    this.setSource("advertisement", null, null, this.thirdPartyAdParameters.video.clickURL, this.thirdPartyAdParameters.video.impressionTrackURL, this.thirdPartyAdParameters.video.externalImpressionTrackURL, this.thirdPartyAdParameters.video.completionTrackURL, this.thirdPartyAdParameters.video.externalCompletionTrackURL, this.thirdPartyAdParameters.video.videoURL);

    if (this.adInsertionChangeInterval != null)
    {
      // Track insertion of video advertisement
      this.adInsertionCount_track();
    }
  }
  else
  {
    //document.getElementById("debugTA").value += "\n Invalid video advertisement from a third-party ad request detected. (DayPortFLVVideo.thirdPartyAdParameters.video.videoURL="+this.thirdPartyAdParameters.video.videoURL+").";

    if (this.metadataState == "loading")
    {
      // Let callback for DayPortFLVVideo.retrieveMetadata method (DayPortFLVVideo.retrieveMetadataCB method) handle continuing on
      this.adState = "inactive";
    }
    else
    {
      this.adState = "inactive";

      if (this.articleID != null)
      {
        // Raise OnEndOfAd event
        this.OnEndOfAd();

        //document.getElementById("debugTA").value += "\n No advertisement to play, triggering play of queued article (ID of "+this.articleID+").";
        if(this.contentDomain != this.domain && typeof this.contentDomain != "undefined") 
        	var tmpArticleID = this.articleID+"@"+this.contentDomain;
        else
         var tmpArticleID = this.articleID;

        this.setSource("article", tmpArticleID);
      }
      else
      {
        if (this.currPlayState != 0)
        {
          this.stop();
        }
        else
        {
          // Raise OnStopped event
          this.OnStopped();
        }

        // Raise OnEndOfAd event
        this.OnEndOfAd();
      }
    }
  }

  // Reset thirdPartyAdParameters property
  this.thirdPartyAdParameters = null;
};

DayPortFLVVideo.prototype.requirementsCheck = function()
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.requirementsCheck() called.";

  // Check for installation and version of Flash player

  return true;
};

// Retrieve metadata for an article.
DayPortFLVVideo.prototype.retrieveMetadata = function()
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.retrieveMetadata() called.";

  this.metadataState = "loading";
  
  if(this.contentDomain == "") this.contentDomain = this.domain;

  // Clear metadata object properties
  this.metadata = new Object();
  // Define formatsAvailable property as an array
  this.metadata.formatsAvailable = new Array();

  //this.mdRetrieverObject.src = "http://" + this.domain + "/nw/article/view/" + this.articleID + "/?tf=DayPortPlayerArticleMetadata.tpl&mt=1";
  //document.getElementById("debugTA").value += "\n retrieveMetadata=http://" + this.domain + "/nw/article/view/" + this.articleID + "/?tf=DayPortPlayerArticleMetadata.tpl&UserDef=true&mt=1";
  if ((DayPortVideo.system.osPlatform == "Mac") && (DayPortVideo.system.browser == "Internet Explorer"))
  {
    setTimeout("DayPortVideo.objectArray[" + eval(this.objectArrayIndex) + "].video.mdRetrieverObject.innerHTML = '_<scr' + 'ipt language=\"JavaScript\" type=\"text/javascript\" src=\"http://" + this.contentDomain + "/nw/article/view/" + this.articleID + "/?tf=DayPortPlayerArticleMetadata.tpl&UserDef=true&mt=1\" defer></scr' + 'ipt>';", 100);
  }
  else if ((DayPortVideo.system.osPlatform == "Mac") && (DayPortVideo.system.browser == "Safari"))
  {
    this.mdRetrieverObject.innerHTML = "";
    var scrObj = document.createElement("script");
    scrObj.id = this.videoID + "_metadataRetrieverJS";
    scrObj.defer = true;
    scrObj.src = "http://" + this.contentDomain + "/nw/article/view/" + this.articleID + "/?tf=DayPortPlayerArticleMetadata.tpl&UserDef=true&mt=1";
    var target = this;
    setTimeout(function()
    {
      target.mdRetrieverObject.appendChild(scrObj);
    }, 10);
  }
  else
  {
    this.mdRetrieverObject.innerHTML = '_<scr' + 'ipt id="' + this.videoID + '_metadataRetrieverJS" language="JavaScript" type="text/javascript" defer></scr' + 'ipt>';
    var target = this;
    setTimeout(function()
    {
      document.getElementById(target.videoID+"_metadataRetrieverJS").src = "http://" + target.contentDomain + "/nw/article/view/" + target.articleID + "/?tf=DayPortPlayerArticleMetadata.tpl&UserDef=true&mt=1";
    }, 10);
  }
};

// Callback for DayPortFLVVideo.retrieveMetadata method.
DayPortFLVVideo.prototype.retrieveMetadataCB = function(metadataObj)
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.retrieveMetadataCB() called.";
  //document.getElementById("debugTA").value += "\n metadataObj="+metadataObj;

  /*
  var tmpStr = "";
  for (var prop in metadataObj)
  {
    tmpStr += "\n  " + prop + "=" + metadataObj[prop];

    for (var prop2 in metadataObj[prop])
    {
      tmpStr += "\n   " + prop2 + "=" + metadataObj[prop][prop2];

      for (var prop3 in metadataObj[prop][prop2])
      {
        tmpStr += "\n    " + prop3 + "=" + metadataObj[prop][prop2][prop3];
      }
    }
  }
  document.getElementById("debugTA").value += tmpStr;
  */

  this.mdRetrieverObject.innerHTML = "";

  if (metadataObj == null)
  {
    // Article content is currently unavailable.
    this.metadataState = "loaded";
    // Raise OnMetadataRetrieved event
    this.OnMetadataRetrieved();
    return;
  }

  this.metadata.body = metadataObj.body;
  this.metadata.duration = metadataObj.duration;
  var numFormats = metadataObj.formatsAvailable.length;
  for (var i=0; i < numFormats; i++)
  {
    this.metadata.formatsAvailable[i] = {
                                          bitrateID: metadataObj.formatsAvailable[i].bitrateID,
                                          formatID: metadataObj.formatsAvailable[i].formatID,
                                          url: metadataObj.formatsAvailable[i].url
                                        };
  }
  this.metadata.hasVideo = metadataObj.hasVideo;
  this.metadata.id = metadataObj.id;
  this.metadata.intro = metadataObj.intro;
  this.metadata.introHTML = metadataObj.introHTML;
  this.metadata.isLive = metadataObj.isLive;
  this.metadata.name = metadataObj.name;
  this.metadata.previewImage = metadataObj.previewImage;
  this.metadata.userDef1 = metadataObj.userDef1;
  this.metadata.userDef2 = metadataObj.userDef2;
  this.metadata.userDef3 = metadataObj.userDef3;
  this.metadata.userDef4 = metadataObj.userDef4;
  this.metadata.userDef5 = metadataObj.userDef5;
  this.metadata.userDef6 = metadataObj.userDef6;
  this.metadata.userDef7 = metadataObj.userDef7;
  this.metadata.userDef8 = metadataObj.userDef8;
  this.metadata.userDef9 = metadataObj.userDef9;
  this.metadata.userDef10 = metadataObj.userDef10;
  this.metadata.userDef11 = metadataObj.userDef11;
  this.metadata.userDef12 = metadataObj.userDef12;
  this.metadata.userDef13 = metadataObj.userDef13;
  this.metadata.userDef14 = metadataObj.userDef14;
  this.metadata.userDef15 = metadataObj.userDef15;
  this.metadata.userDef16 = metadataObj.userDef16;
  this.metadata.userDef17 = metadataObj.userDef17;
  this.metadata.userDef18 = metadataObj.userDef18;
  this.metadata.userDef19 = metadataObj.userDef19;
  this.metadata.userDef20 = metadataObj.userDef20;
  
  this.metadata.domain = this.contentDomain;

  /*
  for (var prop in metadataObj)
  {
    //this.metadata.formatsAvailable[i] = metadataObj.formatsAvailable[i];
    if (prop == "formatsAvailable")
    {
      var numFormats = metadataObj.formatsAvailable.length;
      for (var i=0; i < numFormats; i++)
      {
        this.metadata[prop][i] = new Object();
        for (var faProp in metadataObj[prop])
        {
          this.metadata[prop][i][faProp] = metadataObj[prop][i][faProp];
        }
      }
    }
    else
    {
      this.metadata[prop] = metadataObj[prop];
    }
  }
  */
  //document.getElementById("debugTA").value += "\n this.metadata.isLive="+this.metadata.isLive;
  if(this.metadata.isLive == "true")
  {
  	this.isLive = true;
  }else{
  	this.isLive = false;
  }

  this.metadataState = "loaded";
  // Raise OnMetadataRetrieved event
  this.OnMetadataRetrieved();

  if ((this.adState != "loading") && (this.adState != "playing"))
  {
    // Set the source
    this.stop();

    this.clickURL = null;
    this.impressionTrackURL = null;
    this.externalImpressionTrackURL = null;
    this.completionTrackURL = null;
    this.externalCompletionTrackURL = null;
      
    if(this.isLive)
    {
		DayPortVideo.objectArray[this.objectArrayIndex].changeFormat(2,true);
		return false;
    }
      
    try
    {
      this.videoObject.SetVariable("videoCommand", "SetSource|article,"+escape(this.articleID)+","+escape(this.clickURL));
    }
    catch(errorObject)
    {
      // ActiveX method not supported/available, so broker request
      // Add command to the Queue
      this.addToQueue("SetSource|article,"+escape(this.articleID)+","+escape(this.clickURL));
    }

    // Raise OnTransitioning event
    this.OnTransitioning();

    this.startUpdateStatus();
  }
};

DayPortFLVVideo.prototype.seek = function(seekPos)
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.seek() called.";

  if ((this.adState == "loading") || (this.adState == "playing"))
  {
    // Disallow seeking during ad playback
    return false;
  }

  try
  {
    this.videoObject.SetVariable("videoCommand", "Seek|"+escape(seekPos));

    if (this.currPlayState != 2)
    {
      this.getPosition();
    }
  }
  catch(errorObject)
  {
    // ActiveX method not supported/available, so broker request
    // Add command to the Queue
    this.addToQueue("Seek|"+escape(seekPos));
  }

  return true;
};

DayPortFLVVideo.prototype.setAd = function(adObj, conDefID, objID, conID, track, width, height, typeID, calloutURL, calloutMethod)
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.setAd() called.";

  if (typeID == 4)
  {
    this.setSource("advertisement", objID, conID, null, null, null, null, null, null);
    return true;
  }

  if (adObj == null)
  {
    // Ad object not registered
    //document.getElementById("debugTA").value += "\n Ad object not registered.";
    return false;
  }

  //document.getElementById("debugTA").value += "\n calloutURL="+calloutURL;
  if ((typeof calloutURL == "undefined") || (calloutURL == null))
  {
    //document.getElementById("debugTA").value += "\n Calling out a banner advertisement from the DayPort system.";

    var conTrack = "-1";
    if (track)
    {
      conTrack = "";
    }

    var rndm = DayPortVideo.genRandom();
    //adObj.innerHTML = '<iframe id="'+adObj.id+'_adcallout_' + rndm + '" onload="" src="http://' + this.domain + '/DayPortVideo_adcallout/?conDefID='+conDefID+'&objID='+objID+'&conID='+conID+'&conTrack='+conTrack+'&width='+width+'&height='+height+'&rndm='+rndm+'" style="width:'+width+'px; height:'+height+'px;" frameborder="0" scrolling="no"></iframe>';
    // Create Iframe with blank source first, then set it to avoid possible IE bug that can occur (previous Iframe source used despite new source specified).
    adObj.innerHTML = '<iframe id="'+adObj.id+'_adcallout_' + rndm + '" onload="" src="" style="width:'+width+'px; height:'+height+'px;" frameborder="0" scrolling="no"></iframe>';
    //document.getElementById("debugTA").value += "\n adObj.innerHTML="+adObj.innerHTML;
    document.getElementById(adObj.id+"_adcallout_"+rndm).src = 'http://' + this.domain + '/DayPortVideo_adcallout/?conDefID='+conDefID+'&objID='+objID+'&conID='+conID+'&conTrack='+conTrack+'&width='+width+'&height='+height+'&rndm='+rndm;
    //document.getElementById("debugTA").value += "\n adObj.innerHTML="+adObj.innerHTML;
  }
  else
  {
    //document.getElementById("debugTA").value += "\n Calling out a banner advertisement from a third-party system.";

    //document.getElementById("debugTA").value += "\n calloutMethod="+calloutMethod;
    // Force calloutMethod parameter to lower case if passed in as a string.
    if (typeof(calloutMethod) == "string")
    {
      calloutMethod = calloutMethod.toLowerCase();
    }

    switch (calloutMethod)
    {
      case "html":
        var rndm = DayPortVideo.genRandom();
        // Create Iframe with blank source first, then set it to avoid possible IE bug that can occur (previous Iframe source used despite new source specified).
        adObj.innerHTML = '<iframe id="'+adObj.id+'_adcallout_' + rndm + '" onload="" src="" style="width:'+width+'px; height:'+height+'px;" frameborder="0" scrolling="no"></iframe>';
        //document.getElementById("debugTA").value += "\n adObj.innerHTML="+adObj.innerHTML;
        document.getElementById(adObj.id+"_adcallout_"+rndm).src = calloutURL;
        //document.getElementById("debugTA").value += "\n adObj.innerHTML="+adObj.innerHTML;
        break;

      case "javascript":
      default:
        var rndm = DayPortVideo.genRandom();
        // Create Iframe with blank source first, then set it to avoid possible IE bug that can occur (previous Iframe source used despite new source specified).
        adObj.innerHTML = '<iframe id="'+adObj.id+'_adcallout_' + rndm + '" onload="" src="" style="width:'+width+'px; height:'+height+'px;" frameborder="0" scrolling="no"></iframe>';
        //document.getElementById("debugTA").value += "\n adObj.innerHTML="+adObj.innerHTML;
        document.getElementById(adObj.id+"_adcallout_"+rndm).src = "http://" + this.domain + "/DayPortVideo_adcallout/?calloutURL=" + escape(calloutURL) + "&width=" + width + "&height=" + height + "&rndm=" + rndm;
        //document.getElementById("debugTA").value += "\n adObj.innerHTML="+adObj.innerHTML;
    }
  }

  return true;
};

DayPortFLVVideo.prototype.setAdInsertionChangeInterval = function(numAds)
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.setAdInsertionChangeInterval() called.";
  //document.getElementById("debugTA").value += "\n numAds="+numAds;

  if (numAds == null)
  {
    // Disable adInsertionChangeInterval
    this.adInsertionChangeInterval = null;

    return true;
  }

  if (isNaN(parseInt(numAds, 10)))
  {
    // Invalid numAds parameter so just return.
    return false;
  }

  // Force numAds parameter to a number and a valid range (i.e., integer greater than 0).
  numAds = Math.max(parseInt(numAds, 10), 1);

  //document.getElementById("debugTA").value += "\n Setting adInsertionChangeInterval to "+numAds+" ad(s).";
  this.adInsertionChangeInterval = numAds;
  
  return true;
};

DayPortFLVVideo.prototype.setAdInsertionFrequency = function(numVideos)
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.setAdInsertionFrequency() called.";
  //document.getElementById("debugTA").value += "\n numVideos="+numVideos;

  if (numVideos == null)
  {
    // Disable adInsertionFrequency
    this.adInsertionFrequency = null;

    return true;
  }

  if (isNaN(parseInt(numVideos, 10)))
  {
    // Invalid numVideos parameter so just return.
    return false;
  }

  // Force numVideos parameter to a number and a valid range (i.e., integer greater than 0).
  numVideos = Math.max(parseInt(numVideos, 10), 1);

  //document.getElementById("debugTA").value += "\n Setting adInsertionFrequency to "+numVideos+" video(s).";
  this.adInsertionFrequency = numVideos;
  
  return true;
};

DayPortFLVVideo.prototype.setAdInsertionFrequencyChange = function(numVideos)
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.setAdInsertionFrequencyChange() called.";
  //document.getElementById("debugTA").value += "\n numVideos="+numVideos;

  if (numVideos == null)
  {
    // Disable adInsertionFrequencyChange
    this.adInsertionFrequencyChange = null;

    return true;
  }

  if (isNaN(parseInt(numVideos, 10)))
  {
    // Invalid numVideos parameter so just return.
    return false;
  }

  // Force numVideos parameter to a number and a valid range (i.e., integer greater than 0).
  numVideos = Math.max(parseInt(numVideos, 10), 1);

  //document.getElementById("debugTA").value += "\n Setting adInsertionFrequencyChange to "+numVideos+" video(s).";
  this.adInsertionFrequencyChange = numVideos;
  
  return true;
};

DayPortFLVVideo.prototype.setAdInsertionFrequencyMax = function(numVideos)
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.setAdInsertionFrequencyMax() called.";
  //document.getElementById("debugTA").value += "\n numVideos="+numVideos;

  if (numVideos == null)
  {
    // Disable adInsertionFrequencyMax (i.e., no maximum limit)
    this.adInsertionFrequencyMax = null;

    return true;
  }

  if (isNaN(parseInt(numVideos, 10)))
  {
    // Invalid numVideos parameter so just return.
    return false;
  }

  // Force numVideos parameter to a number and a valid range (i.e., integer greater than 0).
  numVideos = Math.max(parseInt(numVideos, 10), 1);

  //document.getElementById("debugTA").value += "\n Setting adInsertionFrequencyMax to "+numVideos+" video(s).";
  this.adInsertionFrequencyMax = numVideos;
  
  return true;
};

DayPortFLVVideo.prototype.setAdInsertionThreshold = function(numSeconds)
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.setAdInsertionThreshold() called.";
  //document.getElementById("debugTA").value += "\n numSeconds="+numSeconds;

  if (numSeconds == null)
  {
    // Disable adInsertionThreshold
    this.adInsertionThreshold = null;

    try
    {
      this.videoObject.SetVariable("videoCommand", "SetAdInsertionThreshold|null");
    }
    catch(errorObject)
    {
      // ActiveX method not supported/available, so broker request
      // Add command to the Queue
      this.addToQueue("SetAdInsertionThreshold|null");
    }

    return true;
  }

  if (isNaN(parseInt(numSeconds, 10)))
  {
    // Invalid numSeconds parameter so just return.
    return false;
  }

  // Force numSeconds parameter to a number and a valid range (i.e., integer greater than 0).
  numSeconds = Math.max(parseInt(numSeconds, 10), 1);

  //document.getElementById("debugTA").value += "\n Setting adInsertionThreshold to "+numSeconds+" second(s).";
  this.adInsertionThreshold = numSeconds;

  try
  {
    this.videoObject.SetVariable("videoCommand", "SetAdInsertionThreshold|"+escape(this.adInsertionThreshold));
  }
  catch(errorObject)
  {
    // ActiveX method not supported/available, so broker request
    // Add command to the Queue
    this.addToQueue("SetAdInsertionThreshold|"+escape(this.adInsertionThreshold));
  }
  
  return true;
};

DayPortFLVVideo.prototype.setAdInsertionThresholdChange = function(numSeconds)
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.setAdInsertionThresholdChange() called.";
  //document.getElementById("debugTA").value += "\n numSeconds="+numSeconds;

  if (numSeconds == null)
  {
    // Disable adInsertionThresholdChange
    this.adInsertionThresholdChange = null;

    return true;
  }

  if (isNaN(parseInt(numSeconds, 10)))
  {
    // Invalid numSeconds parameter so just return.
    return false;
  }

  // Force numSeconds parameter to a number and a valid range (i.e., integer greater than 0).
  numSeconds = Math.max(parseInt(numSeconds, 10), 1);

  //document.getElementById("debugTA").value += "\n Setting adInsertionThresholdChange to "+numSeconds+" second(s).";
  this.adInsertionThresholdChange = numSeconds;
  
  return true;
};

DayPortFLVVideo.prototype.setAdInsertionThresholdMax = function(numSeconds)
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.setAdInsertionThresholdMax() called.";
  //document.getElementById("debugTA").value += "\n numSeconds="+numSeconds;

  if (numSeconds == null)
  {
    // Disable adInsertionThresholdMax (i.e., no maximum limit)
    this.adInsertionThresholdMax = null;

    return true;
  }

  if (isNaN(parseInt(numSeconds, 10)))
  {
    // Invalid numSeconds parameter so just return.
    return false;
  }

  // Force numSeconds parameter to a number and a valid range (i.e., integer greater than 0).
  numSeconds = Math.max(parseInt(numSeconds, 10), 1);

  //document.getElementById("debugTA").value += "\n Setting adInsertionThresholdMax to "+numSeconds+" second(s).";
  this.adInsertionThresholdMax = numSeconds;
  
  return true;
};

DayPortFLVVideo.prototype.setAdPackages = function(adPackageArray, bannerAdElementArray)
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.setAdPackages() called.";
  //document.getElementById("debugTA").value += "\n adPackageArray="+adPackageArray+", bannerAdElementArray="+bannerAdElementArray;

  // See if ad-package settings are actively in use
  //document.getElementById("debugTA").value += "\n DayPortFLVVideo.processingAdPackages="+this.processingAdPackages;
  if (this.processingAdPackages)
  {
    // Queue changing the ad-package settings
    if (adPackageArray == null)
    {
      adPackageArray = new Array();
    }

    if (bannerAdElementArray == null)
    {
      bannerAdElementArray = new Array();
    }

    this.queuedAdPackageArray = adPackageArray;
    this.queuedBannerAdElementArray = bannerAdElementArray;
    return true;
  }

  // Reset queuedAdPackageArray and queuedBannerAdElementArray properties
  this.queuedAdPackageArray = null;
  this.queuedBannerAdElementArray = null;

  var tmpAutoAdInsertion = this.autoAdInsertion;
  var tmpAdPackageArray = new Array();
  var tmpBannerAdElementArray = new Array();

  if ((adPackageArray != "") && (adPackageArray != null) && (typeof adPackageArray != "undefined"))
  {
    var numPackages = adPackageArray.length;
    //document.getElementById("debugTA").value += "\n numPackages="+numPackages;
    for (var i=0; i < numPackages; i++)
    {
      tmpAdPackageArray[i] = new Object();
      tmpAdPackageArray[i].conDefID = adPackageArray[i].conDefID;
      tmpAdPackageArray[i].objects = new Array();
      var numObjects = adPackageArray[i].objects.length;
      for (var oi=0; oi < numObjects; oi++)
      {
        tmpAdPackageArray[i].objects[oi] = new Object();
        tmpAdPackageArray[i].objects[oi].objectID = adPackageArray[i].objects[oi].objectID;
        tmpAdPackageArray[i].objects[oi].adType = adPackageArray[i].objects[oi].adType;
        tmpAdPackageArray[i].objects[oi].track = adPackageArray[i].objects[oi].track;
        tmpAdPackageArray[i].objects[oi].elementRef = null;
      }
    }

    if ((bannerAdElementArray != "") && (bannerAdElementArray != null) && (typeof bannerAdElementArray != "undefined"))
    {
      var numElements = bannerAdElementArray.length;
      //document.getElementById("debugTA").value += "\n numElements="+numElements;
      for (var i=0; i < numElements; i++)
      {
        tmpBannerAdElementArray[i] = bannerAdElementArray[i];
      }
    }
  }

  // See if need to temporarily disable automatic ad insertion
  if (this.autoAdInsertion)
  {
    this.setAutoAdInsertion(false);
  }

  // Unregister any previously registered banner-ad elements
  for (var elementObj in this.elements)
  {
    if (this.elements[elementObj].idStr == "bannerad")
    {
      // Remove the impressionTrackImageObject
      document.getElementById(this.videoID+"_trackImageContainer").removeChild(this.elements[elementObj].impressionTrackImageObject);
      this.elements[elementObj].impressionTrackImageObject = null;

      // Delete the element from the array
      delete this.elements[elementObj];
    }
  }

  // Change ad-package settings
  this.adPackageArray = tmpAdPackageArray;

  this.adArray = new Array();
  var adRequesterStr = "";
  var numPackages = this.adPackageArray.length;
  for (var i=0; i < numPackages; i++)
  {
    adRequesterStr +=  '<span id="' + this.videoID + '_adRequester_' + (i + 1) + '" style="position:absolute; left:0px; top:0px; width:1px; height:1px; visibility:hidden; display:none;"></span>';

    this.adArray["ConDef_"+this.adPackageArray[i].conDefID] = {
                                                                adRequestRef:(i + 1),
                                                                adRequestState:"uninitialized"
                                                              };
  }
  document.getElementById(this.videoID+"_adRequesterContainer").innerHTML = adRequesterStr;

  // Register any banner-ad elements that were passed in
  var numElements = tmpBannerAdElementArray.length;
  //document.getElementById("debugTA").value += "\n numElements="+numElements;
  for (var i=0; i < numElements; i++)
  {
    this.registerElement("bannerad", tmpBannerAdElementArray[i]);
  }

  // See if need to re-enable automatic ad insertion
  if (tmpAutoAdInsertion)
  {
    this.setAutoAdInsertion(true);
  }

  return true;
};

DayPortFLVVideo.prototype.setAutoAdInsertion = function(enabled)
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.setAutoAdInsertion() called.";
  //document.getElementById("debugTA").value += "\n enabled="+enabled;

  if ((DayPortVideo.system.osPlatform == "Windows") && (DayPortVideo.system.browser == "Opera"))
  {
    this.autoAdInsertion = false;
    return;
  }

  if (enabled && (this.adPackageArray.length > 0))
  {
    this.autoAdInsertion = true;

    if (!this.intervalStopped && (this.adState == "inactive"))
    {
      this.adState = "tracking";
    }

    try
    {
      this.videoObject.SetVariable("videoCommand", "SetAutoAdInsertion|true");
    }
    catch(errorObject)
    {
      // ActiveX method not supported/available, so broker request
      // Add command to the Queue
      this.addToQueue("SetAutoAdInsertion|true");
    }
  }
  else
  {
    this.autoAdInsertion = false;

    if (this.adState == "tracking")
    {
      this.adState = "inactive";
    }

    try
    {
      this.videoObject.SetVariable("videoCommand", "SetAutoAdInsertion|false");
    }
    catch(errorObject)
    {
      // ActiveX method not supported/available, so broker request
      // Add command to the Queue
      this.addToQueue("SetAutoAdInsertion|false");
    }
  }
};

DayPortFLVVideo.prototype.setDomain = function(domain)
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.setDomain() called.";

  if ((domain == "") || (domain == null) || (typeof domain == "undefined"))
    domain = this.domain;
  else
    this.domain = domain;

  try
  {
    this.videoObject.SetVariable("videoCommand", "SetDomain|"+escape(domain));
  }
  catch(errorObject)
  {
    // ActiveX method not supported/available, so broker request
    // Add command to the Queue
    this.addToQueue("SetDomain|"+escape(domain));
  }
};

DayPortFLVVideo.prototype.setSize = function(width, height)
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.setSize() called.";

  if ((width == "") || (width == null) || (typeof width == "undefined"))
    width = this.getWidth();

  if ((height == "") || (height == null) || (typeof height == "undefined"))
    height = this.getHeight();

  this.width = width;
  this.height = height;

  // Set width and height of the video container
  var videoContainerObj = document.getElementById(this.videoID+"_videoContainer");
  videoContainerObj.style.width = width;
  videoContainerObj.style.height = height;
  // Set width and height of Flash object
  this.videoObject.width = width;
  this.videoObject.height = height;
  // Set width and height of FLV video in Flash object
  try
  {
    this.videoObject.SetVariable("videoCommand", "SetSize|"+escape(width)+","+escape(height));
  }
  catch(errorObject)
  {
    // ActiveX method not supported/available, so broker request
    // Add command to the Queue
    this.addToQueue("SetSize|"+escape(width)+","+escape(height));
  }
};

DayPortFLVVideo.prototype.setSource = function(type)
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.setSource() called.";
  //document.getElementById("debugTA").value += "\n type="+type;

  var numArgs = arguments.length;

  // Force type parameter to lower case if passed in as a string.
  if (typeof(type) == "string")
  {
    type = type.toLowerCase();
  }

  switch (type)
  {
    case "advertisement":
      // Play an advertisement
      if (numArgs < 9)
      {
        //document.getElementById("debugTA").value += "\n Invalid number of arguments for source type of 'advertisement'. (arguments="+arguments+")";
        return false;
      }

      this.stop();

      // Handle click URL
      if (arguments[3] != "")
      {
        this.clickURL = arguments[3];
      }
      else
      {
        this.clickURL = null;
      }
      //document.getElementById("debugTA").value += "\n clickURL="+this.clickURL;

      // Handle impression tracking URL
      // For now, only set if playing an advertisement from a third-party system.
      if ((arguments[4] != "") && (arguments[1] == null) && (arguments[2] == null))
      {
        this.impressionTrackURL = arguments[4];
      }
      else
      {
        this.impressionTrackURL = null;
      }

      // Handle external impression tracking URL(s)
      if ((arguments[5] != null) && (arguments[5].length > 0))
      {
        this.externalImpressionTrackURL = arguments[5];
      }
      else
      {
        this.externalImpressionTrackURL = null;
      }

      // Handle completion tracking URL
      if (arguments[6] != "")
      {
        this.completionTrackURL = arguments[6];
      }
      else
      {
        this.completionTrackURL = null;
      }

      // Handle external completion tracking URL(s)
      if ((arguments[7] != null) && (arguments[7].length > 0))
      {
        this.externalCompletionTrackURL = arguments[7];
      }
      else
      {
        this.externalCompletionTrackURL = null;
      }

      if ((arguments[1] != null) && (arguments[2] != null))
      {
        //document.getElementById("debugTA").value += "\n Playing an advertisement from the DayPort system. (arguments[1]="+arguments[1]+", arguments[2]="+arguments[2]+")";
        try
        {
          this.videoObject.SetVariable("videoCommand", "SetSource|advertisement,"+escape(arguments[1])+","+escape(arguments[2])+","+escape(this.clickURL)+",null");
        }
        catch(errorObject)
        {
          // ActiveX method not supported/available, so broker request
          // Add command to the Queue
          this.addToQueue("SetSource|advertisement,"+escape(arguments[1])+","+escape(arguments[2])+","+escape(this.clickURL)+",null");
        }
      }
      else
      {
        //document.getElementById("debugTA").value += "\n Playing an advertisement from a third-party system. (arguments[8]="+arguments[8]+")";
        try
        {
          this.videoObject.SetVariable("videoCommand", "SetSource|advertisement,null,null,"+escape(this.clickURL)+","+escape(arguments[8]));
        }
        catch(errorObject)
        {
          // ActiveX method not supported/available, so broker request
          // Add command to the Queue
          this.addToQueue("SetSource|advertisement,null,null,"+escape(this.clickURL)+","+escape(arguments[8]));
        }
      }
      this.adState = "playing";
      break;

    case "article":
      // Play an article
      if (numArgs < 2)
      {
        //document.getElementById("debugTA").value += "\n Invalid number of arguments for source type of 'article'. (arguments="+arguments+")";
        return false;
      }
      
      //find alternate domain
      var articleTempID = String(arguments[1]);
      var atSign = articleTempID.indexOf("@");
      if(atSign != -1)
      {
			
			//document.getElementById("debugTA").value += "\n atSign="+atSign;

			var temp_article_split = articleTempID.split("@");
			if(temp_article_split[1] != "" && typeof temp_article_split[1] != "undefined")
			{
				this.contentDomain = temp_article_split[1];
				arguments[1] = temp_article_split[0];
				
			}else{
				this.contentDomain = this.domain;
			}
		}else{
			this.contentDomain = this.domain;
		}
      
      if (this.autoAdInsertion)
      {
        switch (this.adState)
        {
          case "queued":
            this.stop();
            // See if metadata is already set
            if (this.metadata.id != arguments[1])
            {
              // Changing article
              this.articleID = arguments[1];

              // Retrieve article metadata
              this.retrieveMetadata();
            }
            this.changeAds();
            return false;
            break;

          case "loading":
          case "playing":
            // See if metadata is already set
            if (this.metadata.id != arguments[1])
            {
              // Changing article
              this.articleID = arguments[1];

              // Retrieve article metadata
              this.retrieveMetadata();
            }
            return false;
            break;
        }
      }

      this.stop();

      // See if metadata is already set
      if (this.metadata.id != arguments[1] && this.metadata.domain != this.contentDomain)
      {
        // Changing article
        this.articleID = arguments[1];

        // Retrieve article metadata before actually setting the source
        this.retrieveMetadata();

        // Raise OnTransitioning event
        this.OnTransitioning();

        return true;
      }
		
		this.contentDomain = this.metadata.domain;
      this.clickURL = null;
      this.impressionTrackURL = null;
      this.externalImpressionTrackURL = null;
      this.completionTrackURL = null;
      this.externalCompletionTrackURL = null;
	
      //document.getElementById("debugTA").value += "\n this.isLive="+this.isLive;
      if(this.isLive)
      {
		DayPortVideo.objectArray[this.objectArrayIndex].changeFormat(2,true);
		return false;
      }
      
      //document.getElementById("debugTA").value += "\n Playing article ID of "+arguments[1]+".";
      try
      {
        this.videoObject.SetVariable("videoCommand", "SetSource|article,"+escape(arguments[1])+","+escape(this.clickURL));
      }
      catch(errorObject)
      {
        // ActiveX method not supported/available, so broker request
        // Add command to the Queue
        this.addToQueue("SetSource|article,"+escape(arguments[1])+","+escape(this.clickURL));
      }
      break;

    default:
      // Invalid source type
      //document.getElementById("debugTA").value += "\n Invalid source type. (type="+type+")";
      return false;
  }

  // Raise OnTransitioning event
  this.OnTransitioning();

  this.startUpdateStatus();

  return true;
};

DayPortFLVVideo.prototype.setVolume = function(volumePercent)
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.setVolume() called.";
  //document.getElementById("debugTA").value += "\n volumePercent="+volumePercent;

  if ((typeof volumePercent == "undefined") || isNaN(parseInt(volumePercent, 10)))
  {
    // Invalid volumePercent parameter so just return.
    return false;
  }

  // Force volumePercent parameter to a number and a valid range (i.e., 0-100).
  volumePercent = parseInt(volumePercent, 10);
  volumePercent = Math.min(volumePercent, 100);
  volumePercent = Math.max(volumePercent, 0);

  //document.getElementById("debugTA").value += "\n Setting volume level to "+volumePercent+"%.";
  try
  {
    this.videoObject.SetVariable("videoCommand", "SetVolume|"+escape(volumePercent));
  }
  catch(errorObject)
  {
    // ActiveX method not supported/available, so broker request
    // Add command to the Queue
    this.addToQueue("SetVolume|"+escape(volumePercent));
  }
  this.volumeLevel = volumePercent;

  return true;
};

DayPortFLVVideo.prototype.startUpdateStatus = function()
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.startUpdateStatus() called.";

  if ((DayPortVideo.system.osPlatform == "Mac") && (DayPortVideo.system.browser == "Internet Explorer"))
  {
    // Disable auto-updating the status for IE on a Mac
    return false;
  }

  // If timer already started just return.
  if (!this.intervalStopped)
  {
    return false;
  }

  this.intervalStopped = false;
  if (this.autoAdInsertion && (this.adState == "inactive"))
  {
    this.adState = "tracking";
  }

  try
  {
    this.videoObject.SetVariable("videoCommand", "StartUpdateStatus|"+escape(this.interval));
  }
  catch(errorObject)
  {
    // ActiveX method not supported/available, so broker request
    // Add command to the Queue
    this.addToQueue("StartUpdateStatus|"+escape(this.interval));
  }
};

DayPortFLVVideo.prototype.stop = function()
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.stop() called.";

  try
  {
    this.videoObject.SetVariable("videoCommand", "Stop");
  }
  catch(errorObject)
  {
    // ActiveX method not supported/available, so broker request
    // Add command to the Queue
    this.addToQueue("Stop");
  }
};

DayPortFLVVideo.prototype.stopUpdateStatus = function()
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.stopUpdateStatus() called.";

  this.intervalStopped = true;
  try
  {
    this.videoObject.SetVariable("videoCommand", "StopUpdateStatus");
  }
  catch(errorObject)
  {
    // ActiveX method not supported/available, so broker request
    // Add command to the Queue
    this.addToQueue("StopUpdateStatus");
  }

  if (this.autoAdInsertion && (this.adState == "tracking"))
  {
    this.adState = "inactive";
  }
};

DayPortFLVVideo.prototype.toString = function()
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.toString() called.";

  return "[object DayPortFLVVideo]";
};

DayPortFLVVideo.prototype.unregisterEventListener = function(objEvent, listenerFunc)
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.unregisterEventListener() called.";

  if (typeof this.events[objEvent] == "undefined")
  {
    // This event cannot be registered for
    return false;
  }

  if (typeof this.events[objEvent][listenerFunc] == "undefined")
  {
    // This listener function was not registered for this event
    return true;
  }

  delete this.events[objEvent][listenerFunc];

  return true;
};
/******************** End of DayPortFLVVideo Class ********************/

/******************** DayPortWMVVideo Class ********************/
function DayPortWMVVideo(objectArrayIndex, containerHndl, domain, imageDomain, videoID, width, height, adPackageArray, disableAutoFormatChange)
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo class constructor called.";

  // Initialize properties
  // Store reference to DayPortVideo object in global array.
  this.objectArrayIndex = objectArrayIndex;
  this.format = "WMV";
  this.formatID = 2;
  this.containerObject = containerHndl;
  this.domain = domain;
  this.imageDomain = imageDomain;
  this.isLive = false;  //whether or not content video is a live broadcast
  this.videoID = videoID;
  this.width = width;
  this.height = height;
  this.adPackageArray = new Array();
  if ((adPackageArray != "") && (adPackageArray != null) && (typeof adPackageArray != "undefined"))
  {
    var numPackages = adPackageArray.length;
    for (var i=0; i < numPackages; i++)
    {
      this.adPackageArray[i] = new Object();
      this.adPackageArray[i].conDefID = adPackageArray[i].conDefID;
      this.adPackageArray[i].objects = new Array();
      var numObjects = adPackageArray[i].objects.length;
      for (var oi=0; oi < numObjects; oi++)
      {
        this.adPackageArray[i].objects[oi] = new Object();
        this.adPackageArray[i].objects[oi].objectID = adPackageArray[i].objects[oi].objectID;
        this.adPackageArray[i].objects[oi].adType = adPackageArray[i].objects[oi].adType;
        this.adPackageArray[i].objects[oi].track = adPackageArray[i].objects[oi].track;
        this.adPackageArray[i].objects[oi].elementRef = null;
      }
    }
  }
  this.adArray = new Array();  // Possible values for adRequestState property: "uninitialized", "waiting", "loading", "loaded"
  /*
  this.adArray["ConDef_2"] = {
                               adRequestRef: 1,
                               adRequestState: "uninitialized"
                             };
  */
  if (this.adPackageArray.length > 0)
  {
    this.autoAdInsertion = true;
  }
  else
  {
    this.autoAdInsertion = false;
  }
  this.adState = "inactive";  // Possible values: "inactive", "tracking", "queued", "loading", "playing"
  this.consecutiveAdQueued = false;  // Whether or not a consecutive advertisement is queued for insertion (i.e., playback of back-to-back ads)
  this.processingAdPackages = false;  // Whether or not the ad-package settings are actively in use.
  this.queuedVideoAdParameters = null;  // Used by callback for last ad package to set the source to the advertisement video
  this.queuedAdPackageArray = null;  // Used by callback for last ad package to change the queued ad-package settings changes
  this.queuedBannerAdElementArray = null;  // Used by callback for last ad package to change the queued ad-package settings changes
  this.thirdPartyAdParameters = null;  // Used by callback for last ad package to request a third-party ad
  this.trackedPos = 0;
  this.elapsedPlayback = 0;
  this.trackedArticle = null;
  this.playbackCount = 0;
  // Seconds of video playback before inserting an advertisement (before next selected video).
  this.adInsertionThreshold = null;
  // Number of videos played back (playback started but not necessarily completed) before inserting an advertisement (before next selected video).
  this.adInsertionFrequency = 1;
  this.adInsertionCount = 0;
  // Number of advertisements inserted before the insertion rate is increased.
  this.adInsertionChangeInterval = null;
  // Amount DayPortWMVVideo.adInsertionThreshold is adjusted when DayPortWMVVideo.adInsertionChangeInterval is reached.
  this.adInsertionThresholdChange = null;
  // Amount DayPortWMVVideo.adInsertionFrequency is adjusted when DayPortWMVVideo.adInsertionChangeInterval is reached.
  this.adInsertionFrequencyChange = null;
  // Maximum value DayPortWMVVideo.adInsertionThreshold can be set to as a result of DayPortWMVVideo.adInsertionChangeInterval being reached.
  this.adInsertionThresholdMax = null;
  // Maximum value DayPortWMVVideo.adInsertionFrequency can be set to as a result of DayPortWMVVideo.adInsertionChangeInterval being reached.
  this.adInsertionFrequencyMax = null;
  this.events = new Array();
  // Events that listeners can be registered for
  this.events["BeforeFullScreen"] = new Array();
  this.events["Buffering"] = new Array();
  this.events["DurationUpdated"] = new Array();
  this.events["EndOfAd"] = new Array();
  this.events["EndOfStream"] = new Array();
  this.events["MetadataRetrieved"] = new Array();
  this.events["Mute"] = new Array();
  this.events["Paused"] = new Array();
  this.events["Playing"] = new Array();
  this.events["PlayStateChange"] = new Array();
  this.events["PositionUpdated"] = new Array();
  this.events["ScriptControlUnsupported"] = new Array();
  this.events["Stopped"] = new Array();
  this.events["Transitioning"] = new Array();
  this.events["UnMute"] = new Array();
  this.elements = new Array();
  // Elements that can be registered
  //this.elements["bannerAd_1"] = null;

  this.duration = null;
  this.muted = false;
  this.volumeLevel = 94;  // Percentage level of volume (valid range: 0-100)
  this.scriptControlSupported = true;  // Denotes whether control of the embedded WMP object via script is supported
  
  this.requirementsMet = this.requirementsCheck();
  
  if(!disableAutoFormatChange && !this.requirementsMet)
  {
    //document.getElementById("debugTA").value += "\n Requirements not met for this format (WMV).";
    
    // Requirements not met, so try changing formats.
    setTimeout("DayPortVideo.objectArray[" + eval(this.objectArrayIndex) + "].changeFormat(4);", 10);
  }
  else
  {
    //document.getElementById("debugTA").value += "\n Requirements were met (WMV).";
    
    this.mdRetrieverObject = null;
    this.videoObject = this.generateTag(videoID, width, height);
	 this.videoAdName = "";
    this.currPlayState = null;
    this.prevPlayState = null;
    this.currentPosition = null;
    this.wasBuffering = false;
    this.articleID = null;
    this.metadata = new Object();
    this.metadata.formatsAvailable = new Array();
    this.metadataState = "uninitialized";  // Possible values: "uninitialized", "loading", "loaded"
    this.contentDomain = "";
    this.interval = 500;
    this.intervalID = -1;
    this.intervalStopped = true;
    this.clickURL = null;
    this.impressionTrackURL = null;
    this.externalImpressionTrackURL = null;
    this.completionTrackURL = null;
    this.externalCompletionTrackURL = null;

    // Check if page has already loaded
    if (DayPortVideo.pageLoaded)
    {
      // Raise OnPageLoaded event
      this.OnPageLoaded();
    }
  }
}

DayPortWMVVideo.prototype.adInsertionCount_reset = function()
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.adInsertionCount_reset() called.";

  this.adInsertionCount = 0;
};

// Track number of video advertisements inserted
DayPortWMVVideo.prototype.adInsertionCount_track = function()
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.adInsertionCount_track() called.";

  // Increment adInsertionCount property
  this.adInsertionCount++;
  //document.getElementById("debugTA").value += "\n adInsertionCount="+this.adInsertionCount;

  if (this.adInsertionCount >= this.adInsertionChangeInterval)
  {
    //document.getElementById("debugTA").value += "\n DayPortWMVVideo.adInsertionChangeInterval reached.";
    this.adInsertionCount_reset();

    // See if any insertion rates should be adjusted
    if ((this.adInsertionFrequency != null) && (this.adInsertionFrequencyChange != null))
    {
      // Adjust adInsertionFrequency property, account for a maximum limit if set
      if (this.adInsertionFrequencyMax == null)
      {
        this.adInsertionFrequency += this.adInsertionFrequencyChange;
      }
      else
      {
        this.adInsertionFrequency = Math.min((this.adInsertionFrequency + this.adInsertionFrequencyChange), this.adInsertionFrequencyMax);
      }
      //document.getElementById("debugTA").value += "\n DayPortWMVVideo.adInsertionFrequency adjusted to "+this.adInsertionFrequency+" video(s).";
    }

    if ((this.adInsertionThreshold != null) && (this.adInsertionThresholdChange != null))
    {
      // Adjust adInsertionThreshold property, account for a maximum limit if set
      if (this.adInsertionFrequencyMax == null)
      {
        this.adInsertionThreshold += this.adInsertionThresholdChange;
      }
      else
      {
        this.adInsertionThreshold = Math.min((this.adInsertionThreshold + this.adInsertionThresholdChange), this.adInsertionThresholdMax);
      }
      //document.getElementById("debugTA").value += "\n DayPortWMVVideo.adInsertionThreshold adjusted to "+this.adInsertionThreshold+" second(s).";
    }
  }
};

DayPortWMVVideo.prototype.changeAds = function()
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.changeAds() called.";

  this.adState = "loading";
  this.processingAdPackages = true;
  // Raise OnTransitioning event
  this.OnTransitioning();
  this.elapsedPlayback_reset();
  this.playbackCount_reset();
  // Reset queuedVideoAdParameters property
  this.queuedVideoAdParameters = null;
  // Reset thirdPartyAdParameters property
  this.thirdPartyAdParameters = null;

  // Set the adRequestState property for all registered ad packages to the waiting state.
  for (var conDefIDStr in this.adArray)
  {
    this.adArray[conDefIDStr].adRequestState = "waiting";
  }

  // Change ads for all registered ad packages
  var numPackages = this.adPackageArray.length;
  for (var i=0; i < numPackages; i++)
  {
    //document.getElementById("debugTA").value += "\n Requesting new ad(s) for Contract Definition of "+this.adPackageArray[i].conDefID+".";
    this.requestAd(this.adPackageArray[i].conDefID);
  }
};

DayPortWMVVideo.prototype.dispatchEvent = function(objEvent, param1, param2, param3)
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.dispatchEvent() called.";

  // Call all registered listener functions for this event
  for (var listenerFunc in this.events[objEvent])
  {
    this.events[objEvent][listenerFunc](param1, param2, param3);
  }
};

DayPortWMVVideo.prototype.elapsedPlayback_reset = function()
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.elapsedPlayback_reset() called.";

  this.trackedPos = 0;
  this.elapsedPlayback = 0;
};

// Track elapsed time of user-selected video playback
DayPortWMVVideo.prototype.elapsedPlayback_track = function(cpSecs)
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.elapsedPlayback_track() called.";

  // Don't track playback of advertisements
  if (this.adState != "playing")
  {
    if (cpSecs > this.trackedPos)
    {
      // Update elapsed playback time
      var secDiff = (cpSecs - this.trackedPos);
      if ((secDiff * 1000) > this.interval)
        this.elapsedPlayback += (this.interval / 1000);
      else
        this.elapsedPlayback += secDiff;

      if ((this.adState != "queued") && (this.elapsedPlayback >= this.adInsertionThreshold))
      {
        this.adState = "queued";
        //document.getElementById("debugTA").value += "\n DayPortWMVVideo.adInsertionThreshold reached, queued an ad for insertion.";
      }
    }
  }

  this.trackedPos = cpSecs;
  //document.getElementById("debugTA").value = "trackedPos="+this.trackedPos+"\nelapsedPlayback="+this.elapsedPlayback+"\nadInsertionThreshold="+this.adInsertionThreshold+"\nadState="+this.adState;
};

DayPortWMVVideo.prototype.fullScreen = function()
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.fullScreen() called.";
  
  if (!this.scriptControlSupported)
  {
    return false;
  }
  
  if ((this.currPlayState == 2) || (this.currPlayState == 1))
  {
    // Raise OnBeforeFullScreen event
    this.OnBeforeFullScreen();

    this.videoObject.DisplaySize = 3;

    return true;
  }
  else
  {
    // Video must be either playing or paused to view Full-Screen mode.
    return false;
  }
};

DayPortWMVVideo.prototype.generateTag = function(id, width, height, emulateStop)
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.generateTag() called.";
	
  // Validate parameters, set default values if necessary
  if ((id == "") || (id == null) || (typeof id == "undefined"))
    id = "DayPortWMVObject_" + this.objectArrayIndex;

  if ((width == "") || (width == null) || (typeof width == "undefined"))
    width = "320";

  if ((height == "") || (height == null) || (typeof height == "undefined"))
    height = "240";

  this.videoID = id;
  this.width = width;
  this.height = height;
  
  if(this.domain != this.contentDomain  && typeof this.contentDomain != "undefined") 
  	var thisDomain = this.contentDomain;
  else
  	var thisDomain = this.domain;

  var tmpObjStr = '<object id="' + id + '" width="' + width + '" height="' + height + '"' +
                  '               classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95"' +
                  '               codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715"' +
                  '               align="baseline" border="0"' +
                  '               standby="Loading Microsoft Windows Media Player components..."' +
                  '               type="application/x-oleobject">';
                  
  //document.getElementById("debugTA").value += "\n this.articleID="+this.articleID;
  if (this.articleID == null || emulateStop == true)
  {
    tmpObjStr +=  '<param name="FileName" value="">';
  }
  else
  {
    //document.getElementById("debugTA").value += "\n Playing article ID of "+this.articleID+".";
    tmpObjStr +=  '<param name="FileName" value="http://' + thisDomain + '/viewer/content/special.php?Art_ID=' + this.articleID + '&Format_ID=2&BitRate_ID=8&Contract_ID=&Obj_ID=&NoAds=true">';
  }


    tmpObjStr +=  '<param name="ShowControls" value="0">' +
                  '<param name="ShowPositionControls" value="0">' +
                  '<param name="ShowAudioControls" value="0">' +
                  '<param name="ShowTracker" value="0">' +
                  '<param name="ShowDisplay" value="0">' +
                  '<param name="ShowStatusBar" value="0">' +
                  '<param name="AutoSize" value="0">' +
                  '<param name="ShowGotoBar" value="0">' +
                  '<param name="ShowCaptioning" value="0">' +
                  '<param name="AutoStart" value="1">' +
                  '<param name="AnimationAtStart" value="1">' +
                  '<param name="TransparentAtStart" value="0">' +
                  '<param name="AllowScan" value="0">' +
                  '<param name="EnableContextMenu" value="0">' +
                  '<param name="ClickToPlay" value="0">' +
                  '<param name="InvokeURLs" value="1">' +
                  '<param name="SendMouseClickEvents" value="1">' +
                  '<embed ';
  if (this.articleID == null || emulateStop == true)
  {
    tmpObjStr +=  '                src=""';
    }
  else
  {
    //document.getElementById("debugTA").value += "\n Playing article ID of "+this.articleID+".";
    tmpObjStr +=  '                src="http://' + thisDomain + '/viewer/content/special.php?Art_ID=' + this.articleID + '&Format_ID=2&BitRate_ID=8&Contract_ID=&Obj_ID=&NoAds=true"';
  }
    tmpObjStr +=  '                align="baseline" border="0"' +
                  '                width="' + width + '" height="' + height +'"' +
                  '                type="application/x-mplayer2"' +
                  '                pluginspage="http://www.microsoft.com/isapi/redir.dll?prd=windows&sbp=mediaplayer&ar=media&sba=plugin&"' +
                  '                name="' + id + '" showcontrols="0" showpositioncontrols="0"' +
                  '                showaudiocontrols="0" showtracker="0" showdisplay="0"' +
                  '                showstatusbar="0"' +
                  '                autosize="0"' +
                  '                showgotobar="0" showcaptioning="0" autostart="1" autorewind="0"' +
                  '                animationatstart="1" transparentatstart="0" allowscan="0"' +
                  '                enablecontextmenu="0" clicktoplay="0" sendmouseclickevents="1" invokeurls="1"></embed></object>' +
                  /*
                  '<SCR' + 'IPT FOR="' + id + '" EVENT="PlayStateChange(oldState,newState)" LANGUAGE="JScript">' +
                  'DayPortVideo.objectArray[' + eval(this.objectArrayIndex) + '].video.OnPlayStateChange(oldState, newState);' +
                  '</SCR' + 'IPT>' +
                  '<SCR' + 'IPT FOR="' + id + '" EVENT="Buffering(bStart)" LANGUAGE="JScript">' +
                  'DayPortVideo.objectArray[' + eval(this.objectArrayIndex) + '].video.OnBuffering(bStart);' +
                  '</SCR' + 'IPT>' +
                  '<SCR' + 'IPT FOR="' + id + '" EVENT="EndOfStream(lResult)" LANGUAGE="JScript">' +
                  'DayPortVideo.objectArray[' + eval(this.objectArrayIndex) + '].video.OnEndOfStream(lResult);' +
                  '</SCR' + 'IPT>' +
                  '<SCR' + 'IPT FOR="' + id + '" EVENT="Click(iButton, iShiftState, fX, fY)" LANGUAGE="JScript">' +
                  'if ((iButton == 1) && (DayPortVideo.objectArray[' + eval(this.objectArrayIndex) + '].video.clickURL != null)){ window.open(DayPortVideo.objectArray[' + eval(this.objectArrayIndex) + '].video.clickURL); };' +
                  '</SCR' + 'IPT>' +
                  */
                  '<span id="' + id + '_metadataRetriever" style="position:absolute; left:0px; top:0px; width:1px; height:1px; visibility:hidden; display:none;"></span>' +
                  '<span id="' + id + '_trackImageContainer" style="position:absolute; left:0px; top:0px; width:1px; height:1px; visibility:hidden; display:none;">' +
                  '  <img id="' + id + '_impressionTrackImage" src="" width="1" height="1" border="0" style="position:absolute; left:0px; top:0px; visibility:hidden; display:none;" />' +
                  '  <img id="' + id + '_completionTrackImage" src="" width="1" height="1" border="0" style="position:absolute; left:0px; top:0px; visibility:hidden; display:none;" />' +
                  '  <img id="' + id + '_externalImpressionTrackImage_1" src="" width="1" height="1" border="0" style="position:absolute; left:0px; top:0px; visibility:hidden; display:none;" />' +
                  '  <img id="' + id + '_externalCompletionTrackImage_1" src="" width="1" height="1" border="0" style="position:absolute; left:0px; top:0px; visibility:hidden; display:none;" />' +
                  '</span>' +
                  '<span id="' + id + '_thirdPartyAdRequester" style="position:absolute; left:0px; top:0px; width:1px; height:1px; visibility:hidden; display:none;"></span>' +
                  '<span id="' + id + '_adRequesterContainer" style="position:absolute; left:0px; top:0px; width:1px; height:1px; visibility:hidden; display:none;">';

  var numPackages = this.adPackageArray.length;
  for (var i=0; i < numPackages; i++)
  {
    tmpObjStr +=  '<span id="' + id + '_adRequester_' + (i + 1) + '" style="position:absolute; left:0px; top:0px; width:1px; height:1px; visibility:hidden; display:none;"></span>';

    this.adArray["ConDef_"+this.adPackageArray[i].conDefID] = {
                                                                adRequestRef:(i + 1),
                                                                adRequestState:"uninitialized"
                                                              };
  }

  tmpObjStr +=    '</span>';

  this.containerObject.innerHTML = tmpObjStr;

  this.mdRetrieverObject = document.getElementById(id+"_metadataRetriever");
  	

	var videoObject = document.getElementById(id);
	
	 
	
	// Iterate through videoObject properties.  Otherwise, the ActiveX methods and properties of the WMP object
	// may not stay exposed when dynamically written out to the DOM before the page has finished loading if using
	// Firefox/Mozilla (with the ActiveX plugin installed) on Windows.
	var tmpPropStr = "\n videoObject="+videoObject;
	for (var prop in videoObject)
	{
		//tmpPropStr += "\n  " + prop + "=" + videoObject[prop];
	}
	//document.getElementById("debugTA").value += tmpPropStr;

	// Register for events from the WMP object
	var scriptObj = document.createElement("script");
	scriptObj.defer = true;
	scriptObj.event = "PlayStateChange(oldState,newState)";
	scriptObj.htmlFor = id;
	scriptObj.text = 'DayPortVideo.objectArray[' + eval(this.objectArrayIndex) + '].video.OnPlayStateChange(oldState, newState);';
	scriptObj.language = "JScript";
	this.containerObject.appendChild(scriptObj);

	scriptObj = document.createElement("script");
	scriptObj.defer = true;
	scriptObj.event = "Buffering(bStart)";
	scriptObj.htmlFor = id;
	scriptObj.text = 'DayPortVideo.objectArray[' + eval(this.objectArrayIndex) + '].video.OnBuffering(bStart);';
	scriptObj.language = "JScript";
	this.containerObject.appendChild(scriptObj);

	scriptObj = document.createElement("script");
	scriptObj.defer = true;
	scriptObj.event = "EndOfStream(lResult)";
	scriptObj.htmlFor = id;
	scriptObj.text = 'DayPortVideo.objectArray[' + eval(this.objectArrayIndex) + '].video.OnEndOfStream(lResult);';
	scriptObj.language = "JScript";
	this.containerObject.appendChild(scriptObj);
	
	scriptObj = document.createElement("script");
	scriptObj.defer = true;
	scriptObj.event = "Click(iButton, iShiftState, fX, fY)";
	scriptObj.htmlFor = id;
	scriptObj.text = 'if ((iButton == 1) && (DayPortVideo.objectArray[' + eval(this.objectArrayIndex) + '].video.clickURL != null)){ window.open(DayPortVideo.objectArray[' + eval(this.objectArrayIndex) + '].video.clickURL); };';
	scriptObj.language = "JScript";
	this.containerObject.appendChild(scriptObj);

	return videoObject;
	  
};

DayPortWMVVideo.prototype.getDuration = function()
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.getDuration() called.";

  /*
  var tmpDur = this.videoObject.Duration;

  if ((this.videoObject.MarkerCount >= 1) && (this.videoObject.GetMarkerName(1) == "Begin"))
  {
    // Adjust for Begin marker
    tmpDur -= this.videoObject.GetMarkerTime(1);

    if (tmpDur < 0)
      tmpDur = 0;
  }
  this.duration = tmpDur;
  */
  //document.getElementById("debugTA").value += "\nduration="+this.duration;

  return this.duration;
};

DayPortWMVVideo.prototype.getHeight = function()
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.getHeight() called.";

  //return this.videoObject.height;

  return this.height;
};

DayPortWMVVideo.prototype.getPosition = function()
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.getPosition() called.";
  
  if (!this.scriptControlSupported)
  {
    return this.currentPosition;
  }
  
  //this.currentPosition = this.videoObject.CurrentPosition;

  var tmpCurrPos = this.videoObject.CurrentPosition;
  if ((this.videoObject.MarkerCount >= 1) && (this.videoObject.GetMarkerName(1) == "Begin"))
  {
    // Adjust for Begin marker
    tmpCurrPos -= this.videoObject.GetMarkerTime(1);

    if (tmpCurrPos < 0)
      tmpCurrPos = 0;
  }
  this.currentPosition = tmpCurrPos;
  //document.getElementById("debugTA").value += "\ncurrentPosition="+this.currentPosition;

  // Raise OnPositionUpdated event
  var target = this;
  setTimeout(function()
  {
    target.OnPositionUpdated();
  }, 10);

  return this.currentPosition;
};

DayPortWMVVideo.prototype.getWidth = function()
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.getWidth() called.";

  //return this.videoObject.width;

  return this.width;
};

// Seek forward or backward desired number of seconds
DayPortWMVVideo.prototype.jump = function(seconds, backward)
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.jump() called.";
  //document.getElementById("debugTA").value += "\n seconds="+seconds+", backward="+backward;
  
  if (!this.scriptControlSupported)
  {
    return false;
  }
  
  if ((this.adState == "loading") || (this.adState == "playing"))
  {
    // Disallow seeking during ad playback
    return false;
  }

  if ((seconds == "") || (typeof seconds == "undefined") || isNaN(parseFloat(seconds)))
  {
    // Invalid seconds parameter so just return.
    return false;
  }

  // Force seconds parameter to a number.
  seconds = parseFloat(seconds);

  var currPos = this.videoObject.CurrentPosition;
  var durationseconds = this.getDuration();
  //document.getElementById("debugTA").value += "\n durationseconds="+durationseconds;

  if (durationseconds == null)
  {
    //document.getElementById("debugTA").value += "\n Duration was not set yet.";
    this.stop();

    return false;
  }

  var adjCurrPos = currPos;
  var beginPos = 0;
  if ((this.videoObject.MarkerCount >= 1) && (this.videoObject.GetMarkerName(1) == "Begin"))
  {
    // Adjust for Begin marker
    beginPos = this.videoObject.GetMarkerTime(1);

    adjCurrPos -= beginPos;
    if (adjCurrPos < 0)
    {
      adjCurrPos = 0;
    }
  }

  if (backward)
  {
    // Seeking backward
    if ((adjCurrPos - seconds) > 0)
    {
      //document.getElementById("debugTA").value += "\n Seeking to "+(currPos - seconds)+" seconds";
      try
      {
        this.videoObject.CurrentPosition = (currPos - seconds);
        if (this.currPlayState != 2)
        {
          this.getPosition();
        }

        return true;
      }
      catch(errorObject)
      {
        //document.getElementById("debugTA").value += "\n Unable to seek to Seconds ("+(currPos - seconds)+"). Duration was ("+durationseconds+" - 0.001 = "+(durationseconds - 0.001)+").";
        this.stop();

        return false;
      }
    }
    else
    {
      //document.getElementById("debugTA").value += "\n Seconds ("+(currPos - seconds)+") was not greater than zero";
      //document.getElementById("debugTA").value += "\n Seeking to "+beginPos+" seconds";
      try
      {
        this.videoObject.CurrentPosition = beginPos;
        if (this.currPlayState != 2)
        {
          this.getPosition();
        }

        return true;
      }
      catch(errorObject)
      {
        //document.getElementById("debugTA").value += "\n Unable to seek to Seconds ("+beginPos+"). Duration was ("+durationseconds+" - 0.001 = "+(durationseconds - 0.001)+").";
        this.stop();

        return false;
      }
    }
  }
  else
  {
    // Seeking forward
    if ((adjCurrPos + seconds) < (durationseconds - 0.001))
    {
      //document.getElementById("debugTA").value += "\n Seeking to "+(currPos - seconds)+" seconds";
      try
      {
        this.videoObject.CurrentPosition = (currPos + seconds);
        if (this.currPlayState != 2)
        {
          this.getPosition();
        }

        return true;
      }
      catch(errorObject)
      {
        //document.getElementById("debugTA").value += "\n Unable to seek to Seconds ("+(currPos + seconds)+"). Duration was ("+durationseconds+" - 0.001 = "+(durationseconds - 0.001)+").";
        this.stop();

        return false;
      }
    }
    else
    {
      //document.getElementById("debugTA").value += "\n Seconds ("+(currPos + seconds)+") was not less than Duration ("+durationseconds+" - 0.001 = "+(durationseconds - 0.001)+").";
      //document.getElementById("debugTA").value += "\n Seeking to "+((durationseconds + beginPos) - 0.1)+" seconds";
      try
      {
        this.videoObject.CurrentPosition = ((durationseconds + beginPos) - 0.1);
        if (this.currPlayState != 2)
        {
          this.getPosition();
        }

        return true;
      }
      catch(errorObject)
      {
        //document.getElementById("debugTA").value += "\n Unable to seek to Seconds ("+((durationseconds + beginPos) - 0.1)+"). Duration was ("+durationseconds+" - 0.001 = "+(durationseconds - 0.001)+").";
        this.stop();

        return false;
      }
    }
  }
};

DayPortWMVVideo.prototype.mute = function(manual, mute)
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.mute() called.";
  
  if (!this.scriptControlSupported)
  {
    return;
  }
  
  if (manual)
  {
    if (mute)
    {
      //document.getElementById("debugTA").value += "\n Muting audio.";
      this.videoObject.Mute = true;
      this.muted = true;
      // Raise OnMute event
      this.OnMute();
    }
    else
    {
      //document.getElementById("debugTA").value += "\n Unmuting audio.";
      this.videoObject.Mute = false;
      this.muted = false;
      // Raise OnUnMute event
      this.OnUnMute();
    }
  }
  else
  {
    //if (!this.muted)
    if (!this.videoObject.Mute)
    {
      //document.getElementById("debugTA").value += "\n Muting audio.";
      this.videoObject.Mute = true;
      this.muted = true;
      // Raise OnMute event
      this.OnMute();
    }
    else
    {
      //document.getElementById("debugTA").value += "\n Unmuting audio.";
      this.videoObject.Mute = false;
      this.muted = false;
      // Raise OnUnMute event
      this.OnUnMute();
    }
  }
};

DayPortWMVVideo.prototype.OnBeforeFullScreen = function()
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.OnBeforeFullScreen() called.";

  // Dispatch event to registered listeners
  this.dispatchEvent("BeforeFullScreen");
};

DayPortWMVVideo.prototype.OnBuffering = function(bStart)
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.OnBuffering() called.";
  //document.getElementById("debugTA").value += "\n bStart="+bStart+", wasBuffering="+this.wasBuffering;

  if (bStart == this.wasBuffering)
  {
    // This buffering change has already been handled.
    return false;
  }

  this.wasBuffering = bStart;

  // Dispatch event to registered listeners
  this.dispatchEvent("Buffering", bStart);
};

// Event raised when DayPortWMVVideo.duration property is updated
DayPortWMVVideo.prototype.OnDurationUpdated = function()
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.OnDurationUpdated() called.";

  // Dispatch event to registered listeners
  this.dispatchEvent("DurationUpdated", this.duration);
};

DayPortWMVVideo.prototype.OnEndOfAd = function()
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.OnEndOfAd() called.";

  // Dispatch event to registered listeners
  this.dispatchEvent("EndOfAd");
};

DayPortWMVVideo.prototype.OnEndOfStream = function(lResult)
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.OnEndOfStream() called.";
  //document.getElementById("debugTA").value += "\n lResult="+lResult;

  // Convert lResult parameter to integer equivalent if passed in as a string.
  if (typeof(lResult) == "string")
  {
    lResult = parseInt(lResult, 10);
  }

  var tmpAdState = this.adState;

  this.stopUpdateStatus();

  // See if playback of the video completed successfully
  //document.getElementById("debugTA").value += "\n lResult="+lResult;
  if (lResult === 0)
  {
    //document.getElementById("debugTA").value += "\n Playback of the video completed successfully.";

    //document.getElementById("debugTA").value += "\n DayPortWMVVideo.completionTrackURL="+this.completionTrackURL;
    if (this.completionTrackURL != null)
    {
      // Track video via completion tracking URL
      document.getElementById(this.videoID+"_completionTrackImage").src = this.completionTrackURL;

      this.completionTrackURL = null;
    }

    //document.getElementById("debugTA").value += "\n DayPortWMVVideo.externalCompletionTrackURL="+this.externalCompletionTrackURL;
    if (this.externalCompletionTrackURL != null)
    {
      var numURLs = this.externalCompletionTrackURL.length;
      //document.getElementById("debugTA").value += "\n numURLs="+numURLs;
      for (var i=0; i < numURLs; i++)
      {
        var trackImageObj = document.getElementById(this.videoID+"_externalCompletionTrackImage_"+(i + 1));
        //document.getElementById("debugTA").value += "\n trackImageObj="+trackImageObj;
        // See if the impression tracking image exists
        if (trackImageObj)
        {
          // Track video via external completion tracking URL
          trackImageObj.src = this.externalCompletionTrackURL[i];
        }
        else
        {
          var imageObj = document.createElement("img");
          imageObj.id = this.videoID + "_externalCompletionTrackImage_" + (i + 1);
          imageObj.src = null;
          imageObj.width = 1;
          imageObj.height = 1;
          imageObj.border = 0;
          imageObj.style.position = "absolute";
          imageObj.style.left = "0px";
          imageObj.style.top = "0px";
          imageObj.style.visibility = "hidden";
          imageObj.style.display = "none";
          var trackImageContainerObj = document.getElementById(this.videoID+"_trackImageContainer");
          //document.getElementById("debugTA").value += "\n trackImageContainerObj="+trackImageContainerObj;
          if (trackImageContainerObj)
          {
            trackImageObj = trackImageContainerObj.appendChild(imageObj);

            // Track video via external completion tracking URL
            trackImageObj.src = this.externalCompletionTrackURL[i];
          }
        }
      }

      this.externalCompletionTrackURL = null;
    }
  }

  if (tmpAdState == "playing")
  {
    // See if a consecutive advertisement is queued for insertion
    //document.getElementById("debugTA").value += "\n DayPortWMVVideo.consecutiveAdQueued="+this.consecutiveAdQueued;
    if (this.autoAdInsertion && this.consecutiveAdQueued)
    {
      //document.getElementById("debugTA").value += "\n Advertisement finished, processing queued consecutive advertisement.";
      this.consecutiveAdQueued = false;
      this.adState = "queued";
      this.changeAds();
    }
    else
    {
      if (this.consecutiveAdQueued)
      {
        this.consecutiveAdQueued = false;
        this.adState = "queued";
      }
      else
      {
        this.adState = "inactive";
      }

      if (this.articleID != null)
      {
        //document.getElementById("debugTA").value += "\n Advertisement finished, triggering play of queued article (ID of "+this.articleID+").";
        if(this.contentDomain != this.domain && typeof this.contentDomain != "undefined") 
        	var tmpArticleID = this.articleID+"@"+this.contentDomain;
        else
         var tmpArticleID = this.articleID;

        var target = this;
        setTimeout(function()
        {
          target.setSource("article", tmpArticleID);
        }, 100);
      }
    }
  }

  // Dispatch event to registered listeners
  this.dispatchEvent("EndOfStream", tmpAdState, lResult);

  if (tmpAdState == "playing")
  {
    // Raise OnEndOfAd event
    this.OnEndOfAd();
  }
};

DayPortWMVVideo.prototype.OnMetadataRetrieved = function()
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.OnMetadataRetrieved() called.";

  // Dispatch event to registered listeners
  this.dispatchEvent("MetadataRetrieved");
};

DayPortWMVVideo.prototype.OnMute = function()
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.OnMute() called.";

  // Dispatch event to registered listeners
  this.dispatchEvent("Mute");
};

DayPortWMVVideo.prototype.OnPageLoaded = function()
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.OnPageLoaded() called.";
};

DayPortWMVVideo.prototype.OnPaused = function()
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.OnPaused() called.";

  this.stopUpdateStatus();
  
  // Call updateStatus once to make sure synchronized.
  //this.updateStatus();
  this.getPosition();

  // Dispatch event to registered listeners
  this.dispatchEvent("Paused");
};

DayPortWMVVideo.prototype.OnPlaying = function()
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.OnPlaying() called.";

  if (this.autoAdInsertion && (this.adInsertionFrequency != null) && (this.adState != "playing"))
  {
    // Track playback of video
    this.playbackCount_track();
  }

  //document.getElementById("debugTA").value += "\n DayPortWMVVideo.impressionTrackURL="+this.impressionTrackURL;
  if (this.impressionTrackURL != null)
  {
    // Track video via impression tracking URL
    document.getElementById(this.videoID+"_impressionTrackImage").src = this.impressionTrackURL;

    this.impressionTrackURL = null;
  }

  //document.getElementById("debugTA").value += "\n DayPortWMVVideo.externalImpressionTrackURL="+this.externalImpressionTrackURL;
  if (this.externalImpressionTrackURL != null)
  {
    var numURLs = this.externalImpressionTrackURL.length;
    //document.getElementById("debugTA").value += "\n numURLs="+numURLs;
    for (var i=0; i < numURLs; i++)
    {
      var trackImageObj = document.getElementById(this.videoID+"_externalImpressionTrackImage_"+(i + 1));
      //document.getElementById("debugTA").value += "\n trackImageObj="+trackImageObj;
      // See if the impression tracking image exists
      if (trackImageObj)
      {
        // Track video via external impression tracking URL
        trackImageObj.src = this.externalImpressionTrackURL[i];
      }
      else
      {
        var imageObj = document.createElement("img");
        imageObj.id = this.videoID + "_externalImpressionTrackImage_" + (i + 1);
        imageObj.src = null;
        imageObj.width = 1;
        imageObj.height = 1;
        imageObj.border = 0;
        imageObj.style.position = "absolute";
        imageObj.style.left = "0px";
        imageObj.style.top = "0px";
        imageObj.style.visibility = "hidden";
        imageObj.style.display = "none";
        var trackImageContainerObj = document.getElementById(this.videoID+"_trackImageContainer");
        //document.getElementById("debugTA").value += "\n trackImageContainerObj="+trackImageContainerObj;
        if (trackImageContainerObj)
        {
          trackImageObj = trackImageContainerObj.appendChild(imageObj);

          // Track video via external impression tracking URL
          trackImageObj.src = this.externalImpressionTrackURL[i];
        }
      }
    }

    this.externalImpressionTrackURL = null;
  }

  this.startUpdateStatus();
  
  if (this.scriptControlSupported)
  {
	  // See if duration needs to be updated
	  var tmpDur = this.videoObject.Duration;
	  if ((this.videoObject.MarkerCount >= 1) && (this.videoObject.GetMarkerName(1) == "Begin"))
	  {
	    // Adjust for Begin marker
	    tmpDur -= this.videoObject.GetMarkerTime(1);

	    if (tmpDur < 0)
	      tmpDur = 0;
	  }

	  if (this.duration != tmpDur)
	  {
	    this.duration = tmpDur;

	    // Raise OnDurationUpdated event
	    this.OnDurationUpdated();
	  }
  }
  
  // Dispatch event to registered listeners
  this.dispatchEvent("Playing");
};

DayPortWMVVideo.prototype.OnPlayStateChange = function(oldState, newState)
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.OnPlayStateChange() called.";
  //document.getElementById("debugTA").value += "\n oldState="+oldState+", newState="+newState;

  if (newState == this.currPlayState)
  {
    // This PlayState change has already been handled.
    return false;
  }

  this.currPlayState = newState;
  this.prevPlayState = oldState;

  // Dispatch event to registered listeners
  this.dispatchEvent("PlayStateChange", this.prevPlayState, this.currPlayState);

  // Handle PlayState change
  switch (newState)
  {
    case 0:
      // Playback is stopped.
      this.OnStopped();
      break;

    case 1:
      // Playback is paused.
      this.OnPaused();
      break;

    case 2:
      // Stream is playing.
      this.OnPlaying();
      break;

    case 3:
      // Waiting for stream to begin.
      break;

    case 4:
      // Stream is scanning forward.
      break;

    case 5:
      // Stream is scanning in reverse.
      break;

    case 6:
      // Skipping to next.
      break;

    case 7:
      // Skipping to previous.
      break;

    case 8:
      // Stream is not open.
      break;

    default:
  }
};

// Event raised when DayPortWMVVideo.currentPosition property is updated
DayPortWMVVideo.prototype.OnPositionUpdated = function()
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.OnPositionUpdated() called.";

  // Dispatch event to registered listeners
  this.dispatchEvent("PositionUpdated", this.currentPosition);
};

DayPortWMVVideo.prototype.OnStopped = function()
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.OnStopped() called.";

  this.stopUpdateStatus();

  // Reset currentPosition
  //this.currentPosition = 0;
  this.getPosition();

  // Dispatch event to registered listeners
  this.dispatchEvent("Stopped");
};

DayPortWMVVideo.prototype.OnTransitioning = function()
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.OnTransitioning() called.";

  // Dispatch event to registered listeners
  this.dispatchEvent("Transitioning");
};

DayPortWMVVideo.prototype.OnUnMute = function()
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.OnUnMute() called.";

  // Dispatch event to registered listeners
  this.dispatchEvent("UnMute");
};

DayPortWMVVideo.prototype.pause = function()
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.pause() called.";
  
  if (!this.scriptControlSupported)
  {
    return;
  }
  
  this.videoObject.Pause();
};

DayPortWMVVideo.prototype.play = function()
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.play() called.";

  if (!this.scriptControlSupported)
  {
    this.videoObject = this.generateTag(this.videoID, this.width, this.height);
    return;
  }
  
  var durationseconds = this.getDuration();
  //document.getElementById("debugTA").value += "\ncurrentPosition="+this.currentPosition+", durationseconds="+durationseconds;

  if (durationseconds == null)
  {
    if (this.currentPosition == 0)
    {
      this.videoObject.Play();

      this.startUpdateStatus();
    }
    else
    {
      //document.getElementById("debugTA").value += "\nDuration was not set yet, and Position ("+this.currentPosition+") was greater than zero.";
      if ((this.currPlayState == 0) || (this.currPlayState == 8))
      {
        // Raise OnStopped event
        this.OnStopped();
      }
      else
      {
        this.stop();
      }
    }

    return;
  }

  if ((this.currentPosition == 0) || (this.currentPosition < (durationseconds - 0.001)))
  {
    this.videoObject.Play();

    this.startUpdateStatus();
  }
  else
  {
    //document.getElementById("debugTA").value += "\nPosition ("+this.currentPosition+") was not less than Duration ("+durationseconds+" - 0.001 = "+(durationseconds - 0.001)+").";
    if ((this.currPlayState == 0) || (this.currPlayState == 8))
    {
      // Raise OnStopped event
      this.OnStopped();
    }
    else
    {
      this.stop();
    }
  }
};

DayPortWMVVideo.prototype.playbackCount_reset = function()
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.playbackCount_reset() called.";

  this.trackedArticle = null;
  this.playbackCount = 0;
};

// Track playback of user-selected video
DayPortWMVVideo.prototype.playbackCount_track = function()
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.playbackCount_track() called.";

  // Don't track playback of advertisements
  if ((this.adState != "playing") && (this.articleID != this.trackedArticle))
  {
    // Flag this article as being tracked
    this.trackedArticle = this.articleID;

    // Increment playbackCount property
    this.playbackCount++;

    if ((this.adState != "queued") && (this.playbackCount >= this.adInsertionFrequency))
    {
      this.adState = "queued";
      //document.getElementById("debugTA").value += "\n DayPortWMVVideo.adInsertionFrequency reached, queued an ad for insertion.";
    }
  }

  //document.getElementById("debugTA").value += "\n playbackCount="+this.playbackCount+"\n adInsertionFrequency="+this.adInsertionFrequency+"\n adState="+this.adState;
};

DayPortWMVVideo.prototype.playPause = function()
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.playPause() called.";

  if (this.currPlayState == 2)
  {
    this.pause();
  }
  else
  {
    var durationseconds = this.getDuration();
    //document.getElementById("debugTA").value += "\ncurrentPosition="+this.currentPosition+", durationseconds="+durationseconds;

    if (durationseconds == null)
    {
      if (this.currentPosition == 0)
      {
        this.play();
      }
      else
      {
        //document.getElementById("debugTA").value += "\nDuration was not set yet, and Position ("+this.currentPosition+") was greater than zero.";
        if ((this.currPlayState == 0) || (this.currPlayState == 8))
        {
          // Raise OnStopped event
          this.OnStopped();
        }
        else
        {
          this.stop();
        }
      }

      return;
    }

    if ((this.currentPosition == 0) || (this.currentPosition < (durationseconds - 0.001)))
    {
      this.play();
    }
    else
    {
      //document.getElementById("debugTA").value += "\nPosition ("+this.currentPosition+") was not less than Duration ("+durationseconds+" - 0.001 = "+(durationseconds - 0.001)+").";
      if ((this.currPlayState == 0) || (this.currPlayState == 8))
      {
        // Raise OnStopped event
        this.OnStopped();
      }
      else
      {
        this.stop();
      }
    }
  }
};

// Manually queue an advertisement for insertion
DayPortWMVVideo.prototype.queueAd = function(allowConsecutiveAds)
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.queueAd() called.";
  //document.getElementById("debugTA").value += "\n allowConsecutiveAds="+allowConsecutiveAds;

  //document.getElementById("debugTA").value += "\n DayPortWMVVideo.adState="+this.adState;
  if ((this.adState == "loading") || (this.adState == "playing"))
  {
    if (allowConsecutiveAds)
    {
      // Queue a consecutive advertisement for insertion
      this.consecutiveAdQueued = true;
      //document.getElementById("debugTA").value += "\n Manually queued a consecutive ad for insertion.";

      return true;
    }
    else
    {
      // An advertisement is currently being processed so just return.
      return false;
    }
  }

  if (this.adState == "queued")
  {
    // An advertisement is already queued, so just return.
    return true;
  }

  // Queue an advertisement for insertion
  this.adState = "queued";
  //document.getElementById("debugTA").value += "\n Manually queued an ad for insertion.";

  return true;
};

DayPortWMVVideo.prototype.registerElement = function(idStr)
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.registerElement() called.";
  //document.getElementById("debugTA").value += "\n idStr="+idStr;

  // Force idStr parameter to lower case if passed in as a string.
  if (typeof(idStr) == "string")
  {
    idStr = idStr.toLowerCase();
  }

  var numArgs = arguments.length;
  switch (idStr)
  {
    case "bannerad":
      if (numArgs < 2)
      {
        //document.getElementById("debugTA").value += "\n Invalid number of arguments for ID string of 'bannerad'. (arguments="+arguments+")";
        return false;
      }

      if (typeof arguments[1] != "object")
      {
        // Invalid parameters type
        //document.getElementById("debugTA").value += "\n Invalid parameters type. (type="+typeof(arguments[1])+")";
        return false;
      }

      // Determine next available element name
      var limitReached = true;
      for (var i=1; i < 101; i++)
      {
        if (typeof this.elements["bannerAd_"+i] == "undefined")
        {
          limitReached = false;
          break;
        }
      }

      if (limitReached)
      {
        //document.getElementById("debugTA").value += "\n Maximum limit of registered banner ad elements ("+i+") has been reached.";
        return false;
      }

      // Validate Contract Definition ID and Object ID reference
      var invalidRef = true;
      var numPackages = this.adPackageArray.length;
      for (var ci=0; ci < numPackages; ci++)
      {
        if (this.adPackageArray[ci].conDefID == arguments[1].conDefID)
        {
          var numObjects = this.adPackageArray[ci].objects.length;
          for (var oi=0; oi < numObjects; oi++)
          {
            if (this.adPackageArray[ci].objects[oi].objectID == arguments[1].objectID)
            {
              invalidRef = false;
              break;
            }
          }
          break;
        }
      }

      if (invalidRef)
      {
        //document.getElementById("debugTA").value += "\n Invalid Contract Definition ID and/or Object ID reference(s).";
        return false;
      }

      // Register Banner ad
      this.elements["bannerAd_"+i] = new Object();
      this.elements["bannerAd_"+i].idStr = idStr;
      this.elements["bannerAd_"+i].containerObject = arguments[1].containerObject;
      this.elements["bannerAd_"+i].width = arguments[1].width;
      this.elements["bannerAd_"+i].height = arguments[1].height;
      this.elements["bannerAd_"+i].conDefID = arguments[1].conDefID;
      this.elements["bannerAd_"+i].objectID = arguments[1].objectID;

      var imageObj = document.createElement("img");
      imageObj.id = this.videoID + "_impressionTrackImage_bannerAd_" + i;
      imageObj.src = "";
      imageObj.width = 1;
      imageObj.height = 1;
      imageObj.border = 0;
      imageObj.style.position = "absolute";
      imageObj.style.left = "0px";
      imageObj.style.top = "0px";
      imageObj.style.visibility = "hidden";
      imageObj.style.display = "none";
      var trackImageContainerObj = document.getElementById(this.videoID+"_trackImageContainer");
      //document.getElementById("debugTA").value += "\n trackImageContainerObj="+trackImageContainerObj;
      if (trackImageContainerObj)
      {
        this.elements["bannerAd_"+i].impressionTrackImageObject = trackImageContainerObj.appendChild(imageObj);
      }
      else
      {
        this.elements["bannerAd_"+i].impressionTrackImageObject = null;
      }

      // Update associated elementRef property in adPackageArray
      this.adPackageArray[ci].objects[oi].elementRef = i;
      break;

    default:
      // Invalid ID string
      //document.getElementById("debugTA").value += "\n Invalid ID string. (idStr="+idStr+")";
      return false;
  }

  return true;
};

DayPortWMVVideo.prototype.registerEventListener = function(objEvent, listenerFunc)
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.registerEventListener() called.";

  if (typeof this.events[objEvent] == "undefined")
  {
    // This event cannot be registered for
    return false;
  }

  if (typeof listenerFunc != "function")
  {
    // Listener is not a function
    return false;
  }

  if (typeof this.events[objEvent][listenerFunc] != "undefined")
  {
    // This listener function has already been registered for this event
    return true;
  }

  // Register event listener
  this.events[objEvent][listenerFunc] = listenerFunc;

  return true;
};

// Request an ad contract from a contract definition.
DayPortWMVVideo.prototype.requestAd = function(conDefID)
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.requestAd() called.";
  //document.getElementById("debugTA").value += "\n conDefID="+conDefID;

  this.adArray["ConDef_"+conDefID].adRequestState = "loading";

  var rndm = DayPortVideo.genRandom();
  if ((DayPortVideo.system.osPlatform == "Mac") && (DayPortVideo.system.browser == "Internet Explorer"))
  {
    setTimeout("document.getElementById('" + this.videoID + "_adRequester_" + this.adArray["ConDef_"+conDefID].adRequestRef + "').innerHTML = '_<scr' + 'ipt id=\"" + this.videoID + "_adRequesterJS_" + this.adArray["ConDef_"+conDefID].adRequestRef + "\" language=\"JavaScript\" type=\"text/javascript\" src=\"http://" + this.domain + "/ads/select/" + conDefID + "/?extended=true&mt=1&rndm=" + rndm + "\" defer></scr' + 'ipt>';", 100);
  }
  else if ((DayPortVideo.system.osPlatform == "Mac") && (DayPortVideo.system.browser == "Safari"))
  {
    document.getElementById(this.videoID+"_adRequester_"+this.adArray["ConDef_"+conDefID].adRequestRef).innerHTML = "";
    var scrObj = document.createElement("script");
    scrObj.id = this.videoID + "_adRequesterJS_" + this.adArray["ConDef_"+conDefID].adRequestRef;
    scrObj.defer = true;
    scrObj.src = "http://" + this.domain + "/ads/select/" + conDefID + "/?extended=true&mt=1&rndm=" + rndm;
    var target = this;
    setTimeout(function()
    {
      document.getElementById(target.videoID+"_adRequester_"+target.adArray["ConDef_"+conDefID].adRequestRef).appendChild(scrObj);
    }, 10);
  }
  else
  {
    document.getElementById(this.videoID+"_adRequester_"+this.adArray["ConDef_"+conDefID].adRequestRef).innerHTML = '_<scr' + 'ipt id="' + this.videoID + '_adRequesterJS_' + this.adArray["ConDef_"+conDefID].adRequestRef + '" language="JavaScript" type="text/javascript" defer></scr' + 'ipt>';
    var target = this;
    setTimeout(function()
    {
      document.getElementById(target.videoID+"_adRequesterJS_"+target.adArray["ConDef_"+conDefID].adRequestRef).src = "http://" + target.domain + "/ads/select/" + conDefID + "/?extended=true&mt=1&rndm=" + rndm;
    }, 10);
  }
};

// Callback for DayPortWMVVideo.requestAd method.
DayPortWMVVideo.prototype.requestAdCB = function(adObj)
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.requestAdCB() called.";
  //document.getElementById("debugTA").value += "\n adObj="+adObj;

  /*
  var tmpStr = "";
  for (var prop in adObj)
  {
    tmpStr += "\n  " + prop + "=" + adObj[prop];

    for (var prop2 in adObj[prop])
    {
      tmpStr += "\n   " + prop2 + "=" + adObj[prop][prop2];

      for (var prop3 in adObj[prop][prop2])
      {
        tmpStr += "\n    " + prop3 + "=" + adObj[prop][prop2][prop3];

        for (var prop4 in adObj[prop][prop2][prop3])
        {
          tmpStr += "\n     " + prop4 + "=" + adObj[prop][prop2][prop3][prop4];

          for (var prop5 in adObj[prop][prop2][prop3][prop4])
          {
            tmpStr += "\n      " + prop5 + "=" + adObj[prop][prop2][prop3][prop4][prop5];
          }
        }
      }
    }
  }
  document.getElementById("debugTA").value += tmpStr;
  */

  document.getElementById(this.videoID+"_adRequester_"+this.adArray["ConDef_"+adObj.conDefID].adRequestRef).innerHTML = "";
  this.adArray["ConDef_"+adObj.conDefID].adRequestState = "loaded";

  //document.getElementById("debugTA").value += "\n conDefID="+adObj.conDefID+", contractID="+adObj.contractID;
  if (adObj.contractID == -1)
  {
    // No active contracts for selected contract definition pool
    // See if there are any other ad packages still waiting or loading
    var lastAdPackage = true;
    for (var conDefIDStr in this.adArray)
    {
      if ((this.adArray[conDefIDStr].adRequestState == "waiting") || (this.adArray[conDefIDStr].adRequestState == "loading"))
      {
        lastAdPackage = false;
        break;
      }
    }

    // Callback for last ad package should handle changing the adState property
    //document.getElementById("debugTA").value += "\n lastAdPackage="+lastAdPackage;
    if (lastAdPackage)
    {
      //document.getElementById("debugTA").value += "\n DayPortWMVVideo.thirdPartyAdParameters="+this.thirdPartyAdParameters;
      if ((this.thirdPartyAdParameters != null) && (this.thirdPartyAdParameters.video != null))
      {
        //document.getElementById("debugTA").value += "\n Requesting new ad(s) from a third-party system.";
        this.requestThirdPartyAd();
      }
      else
      {
        if ((this.thirdPartyAdParameters != null) && (this.thirdPartyAdParameters.video == null))
        {
          //document.getElementById("debugTA").value += "\n Missing video placeholder for a third-party ad reqeust detected.";
          // Reset thirdPartyAdParameters property
          this.thirdPartyAdParameters = null;
        }

        // Need to handle changing the adState property
        // Set the source to a video advertisement if one queued from other ad package, or look for a queued article

        this.processingAdPackages = false;

        // See if ad-package settings changes have been queued
        if ((this.queuedAdPackageArray != null) && (this.queuedBannerAdElementArray != null))
        {
          this.setAdPackages(this.queuedAdPackageArray, this.queuedBannerAdElementArray);
        }

        //document.getElementById("debugTA").value += "\n DayPortWMVVideo.queuedVideoAdParameters="+this.queuedVideoAdParameters;
        if (this.queuedVideoAdParameters != null)
        {
          this.setSource("advertisement", this.queuedVideoAdParameters.objID, this.queuedVideoAdParameters.contractID, this.queuedVideoAdParameters.clickURL, this.queuedVideoAdParameters.impressionTrackURL, this.queuedVideoAdParameters.externalImpressionTrackURL, this.queuedVideoAdParameters.completionTrackURL, this.queuedVideoAdParameters.externalCompletionTrackURL, this.queuedVideoAdParameters.videoURL);

          if (this.adInsertionChangeInterval != null)
          {
            // Track insertion of video advertisement
            this.adInsertionCount_track();
          }

          // Reset queuedVideoAdParameters property
          this.queuedVideoAdParameters = null;
        }
        else
        {
          if (this.metadataState == "loading")
          {
            // Let callback for DayPortWMVVideo.retrieveMetadata method (DayPortWMVVideo.retrieveMetadataCB method) handle continuing on
            this.adState = "inactive";
          }
          else
          {
            this.adState = "inactive";

            if (this.articleID != null)
            {
              // Raise OnEndOfAd event
              this.OnEndOfAd();

              //document.getElementById("debugTA").value += "\n No advertisement to play, triggering play of queued article (ID of "+this.articleID+").";
              this.setSource("article", this.articleID);
            }
            else
            {
              if (this.currPlayState != 0)
              {
                this.stop();
              }
              else
              {
                // Raise OnStopped event
                this.OnStopped();
              }

              // Raise OnEndOfAd event
              this.OnEndOfAd();
            }
          }
        }
      }
    }

    return;
  }

  var numItems = adObj.contractItems.length;
  //document.getElementById("debugTA").value += "\n numItems="+numItems;
  var numPackages = this.adPackageArray.length;
  //document.getElementById("debugTA").value += "\n numPackages="+numPackages;
  for (var ci=0; ci < numPackages; ci++)
  {
    //document.getElementById("debugTA").value += "\n this.adPackageArray["+ci+"].conDefID="+this.adPackageArray[ci].conDefID;
    if (this.adPackageArray[ci].conDefID == adObj.conDefID)
    {
      var numObjects = this.adPackageArray[ci].objects.length;
      //document.getElementById("debugTA").value += "\n numObjects="+numObjects;
      for (var i=0; i < numItems; i++)
      {
        //document.getElementById("debugTA").value += "\n description="+adObj.contractItems[i].description+", typeID="+adObj.contractItems[i].typeID+", objID="+adObj.contractItems[i].objID;
        for (var oi=0; oi < numObjects; oi++)
        {
          //document.getElementById("debugTA").value += "\n this.adPackageArray["+ci+"].objects["+oi+"].objectID="+this.adPackageArray[ci].objects[oi].objectID;
          if (this.adPackageArray[ci].objects[oi].objectID == adObj.contractItems[i].objID)
          {
            var adType = this.adPackageArray[ci].objects[oi].adType;
            // Force adType parameter to lower case if passed in as a string.
            if (typeof(adType) == "string")
            {
              adType = adType.toLowerCase();
            }

            //document.getElementById("debugTA").value += "\n adType="+adType;
            switch (adType)
            {
              case "video":
                // Video Ad
                // See if contract item is a placeholder for a request to a third-party system
                //document.getElementById("debugTA").value += "\n adObj.contractItems["+i+"].placeholder="+adObj.contractItems[i].placeholder;
                if (typeof adObj.contractItems[i].placeholder != "undefined")
                {
                  // Third-party system
                  //document.getElementById("debugTA").value += "\n DayPortWMVVideo.thirdPartyAdParameters="+this.thirdPartyAdParameters;
                  if (this.thirdPartyAdParameters == null)
                  {
                    // Initialize thirdPartyAdParameters property
                    this.thirdPartyAdParameters = {
                      adRequestState:"waiting",
                      banners:[],
                      ord:DayPortVideo.genRandom(),
                      video:null
                    };
                  }

                  // Process/map response data
                  // DoubleClick format
                  this.thirdPartyAdParameters.video = {
                    completionTrackURL:"",
                    impressionTrackURL:adObj.contractItems[i].trackURL,
                    requestURL:adObj.contractItems[i].placeholder.url
                  };

                  if (this.thirdPartyAdParameters.video.completionTrackURL != "")
                  {
                    // Add random value to the URL to help prevent caching
                    this.thirdPartyAdParameters.video.completionTrackURL += DayPortVideo.appendRandom(this.thirdPartyAdParameters.video.completionTrackURL);
                  }

                  if (this.thirdPartyAdParameters.video.impressionTrackURL != "")
                  {
                    // Add random value to the URL to help prevent caching
                    this.thirdPartyAdParameters.video.impressionTrackURL += DayPortVideo.appendRandom(this.thirdPartyAdParameters.video.impressionTrackURL);
                  }

                  if (this.thirdPartyAdParameters.video.requestURL != "")
                  { 
                    // Add random value to the URL to help prevent caching
                    this.thirdPartyAdParameters.video.requestURL = this.thirdPartyAdParameters.video.requestURL.toString().replace("[timestamp]", this.thirdPartyAdParameters.ord);
                  }
                }
                else
                {
                  // DayPort system
                  // Queue setting the source to the advertisement video
                  this.queuedVideoAdParameters = {
                    objID:adObj.contractItems[i].objID,
                    contractID:adObj.contractID,
                    clickURL:adObj.contractItems[i].clickURL,
                    impressionTrackURL:adObj.contractItems[i].trackURL,
                    externalImpressionTrackURL:[adObj.contractItems[i].trackURL_external],
                    completionTrackURL:"",
                    externalCompletionTrackURL:[""],
                    videoURL:null
                  };

                  if (this.queuedVideoAdParameters.impressionTrackURL != "")
                  {
                    // Add random value to the URL to help prevent caching
                    this.queuedVideoAdParameters.impressionTrackURL += DayPortVideo.appendRandom(this.queuedVideoAdParameters.impressionTrackURL);
                  }

                  if (this.queuedVideoAdParameters.externalImpressionTrackURL[0] != "")
                  {
                    // Add random value to the URL to help prevent caching
                    this.queuedVideoAdParameters.externalImpressionTrackURL[0] += DayPortVideo.appendRandom(this.queuedVideoAdParameters.externalImpressionTrackURL[0]);
                  }
                  else
                  {
                    this.queuedVideoAdParameters.externalImpressionTrackURL = null;
                  }

                  if (this.queuedVideoAdParameters.completionTrackURL != "")
                  {
                    // Add random value to the URL to help prevent caching
                    this.queuedVideoAdParameters.completionTrackURL += DayPortVideo.appendRandom(this.queuedVideoAdParameters.completionTrackURL);
                  }

                  if (this.queuedVideoAdParameters.externalCompletionTrackURL[0] != "")
                  {
                    // Add random value to the URL to help prevent caching
                    this.queuedVideoAdParameters.externalCompletionTrackURL[0] += DayPortVideo.appendRandom(this.queuedVideoAdParameters.externalCompletionTrackURL[0]);
                  }
                  else
                  {
                    this.queuedVideoAdParameters.externalCompletionTrackURL = null;
                  }
                  //document.getElementById("debugTA").value += "\n Queued setting the source to the advertisement video.";
                }
                break;

              case "bannerad":
                // Banner Ad
                // Verify element is registered
                if (this.adPackageArray[ci].objects[oi].elementRef != null)
                {
                  var elementRef = this.adPackageArray[ci].objects[oi].elementRef;

                  // See if contract item is a placeholder for a request to a third-party system
                  //document.getElementById("debugTA").value += "\n adObj.contractItems["+i+"].placeholder="+adObj.contractItems[i].placeholder;
                  if (typeof adObj.contractItems[i].placeholder != "undefined")
                  {
                    // Third-party system
                    //document.getElementById("debugTA").value += "\n DayPortWMVVideo.thirdPartyAdParameters="+this.thirdPartyAdParameters;
                    if (this.thirdPartyAdParameters == null)
                    {
                      // Initialize thirdPartyAdParameters property
                      this.thirdPartyAdParameters = {
                        adRequestState:"waiting",
                        banners:[],
                        video:null
                      };
                    }

                    var bannerIndex = this.thirdPartyAdParameters.banners.length;

                    // Process/map response data
                    // DoubleClick format
                    this.thirdPartyAdParameters.banners[bannerIndex] = {
                      calloutURL:adObj.contractItems[i].placeholder.url,
                      elementRef:elementRef,
                      impressionTrackURL:adObj.contractItems[i].trackURL
                    };

                    if (this.thirdPartyAdParameters.banners[bannerIndex].calloutURL != "")
                    {
                      // Add random value to the URL to help prevent caching
                      this.thirdPartyAdParameters.banners[bannerIndex].calloutURL = this.thirdPartyAdParameters.banners[bannerIndex].calloutURL.toString().replace("[timestamp]", this.thirdPartyAdParameters.ord);
                    }

                    if (this.thirdPartyAdParameters.banners[bannerIndex].impressionTrackURL != "")
                    {
                      // Add random value to the URL to help prevent caching
                      this.thirdPartyAdParameters.banners[bannerIndex].impressionTrackURL += DayPortVideo.appendRandom(this.thirdPartyAdParameters.banners[bannerIndex].impressionTrackURL);
                    }
                  }
                  else
                  {
                    // DayPort system
                    this.setAd(this.elements["bannerAd_"+elementRef].containerObject, adObj.conDefID, adObj.contractItems[i].objID, adObj.contractID, this.adPackageArray[ci].objects[oi].track, this.elements["bannerAd_"+elementRef].width, this.elements["bannerAd_"+elementRef].height, adObj.contractItems[i].typeID);
                  }
                }
                break;
            }
            break;
          }
        }
      }
      break;
    }
  }

  // See if there are any other ad packages still waiting or loading
  var lastAdPackage = true;
  for (var conDefIDStr in this.adArray)
  {
    if ((this.adArray[conDefIDStr].adRequestState == "waiting") || (this.adArray[conDefIDStr].adRequestState == "loading"))
    {
      lastAdPackage = false;
      break;
    }
  }

  // Callback for last ad package should handle changing the adState property
  //document.getElementById("debugTA").value += "\n lastAdPackage="+lastAdPackage;
  if (lastAdPackage)
  {
    //document.getElementById("debugTA").value += "\n DayPortWMVVideo.thirdPartyAdParameters="+this.thirdPartyAdParameters;
    if ((this.thirdPartyAdParameters != null) && (this.thirdPartyAdParameters.video != null))
    {
      //document.getElementById("debugTA").value += "\n Requesting new ad(s) from a third-party system.";
      this.requestThirdPartyAd();
    }
    else
    {
      if ((this.thirdPartyAdParameters != null) && (this.thirdPartyAdParameters.video == null))
      {
        //document.getElementById("debugTA").value += "\n Missing video placeholder for a third-party ad reqeust detected.";
        // Reset thirdPartyAdParameters property
        this.thirdPartyAdParameters = null;
      }

      // Need to handle changing the adState property
      // Set the source to a video advertisement if one queued from other ad package, or look for a queued article

      this.processingAdPackages = false;

      // See if ad-package settings changes have been queued
      if ((this.queuedAdPackageArray != null) && (this.queuedBannerAdElementArray != null))
      {
        this.setAdPackages(this.queuedAdPackageArray, this.queuedBannerAdElementArray);
      }

      //document.getElementById("debugTA").value += "\n DayPortWMVVideo.queuedVideoAdParameters="+this.queuedVideoAdParameters;
      if (this.queuedVideoAdParameters != null)
      {
        this.setSource("advertisement", this.queuedVideoAdParameters.objID, this.queuedVideoAdParameters.contractID, this.queuedVideoAdParameters.clickURL, this.queuedVideoAdParameters.impressionTrackURL, this.queuedVideoAdParameters.externalImpressionTrackURL, this.queuedVideoAdParameters.completionTrackURL, this.queuedVideoAdParameters.externalCompletionTrackURL, this.queuedVideoAdParameters.videoURL);

        if (this.adInsertionChangeInterval != null)
        {
          // Track insertion of video advertisement
          this.adInsertionCount_track();
        }

        // Reset queuedVideoAdParameters property
        this.queuedVideoAdParameters = null;
      }
      else
      {
        if (this.metadataState == "loading")
        {
          // Let callback for DayPortWMVVideo.retrieveMetadata method (DayPortWMVVideo.retrieveMetadataCB method) handle continuing on
          this.adState = "inactive";
        }
        else
        {
          this.adState = "inactive";

          if (this.articleID != null)
          {
            // Raise OnEndOfAd event
            this.OnEndOfAd();

            //document.getElementById("debugTA").value += "\n No advertisement to play, triggering play of queued article (ID of "+this.articleID+").";
            this.setSource("article", this.articleID);
          }
          else
          {
            if (this.currPlayState != 0)
            {
              this.stop();
            }
            else
            {
              // Raise OnStopped event
              this.OnStopped();
            }

            // Raise OnEndOfAd event
            this.OnEndOfAd();
          }
        }
      }
    }
  }
};

// Request an ad contract from a third-party ad system.
DayPortWMVVideo.prototype.requestThirdPartyAd = function()
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.requestThirdPartyAd() called.";

  //document.getElementById("debugTA").value += "\n DayPortWMVVideo.thirdPartyAdParameters="+this.thirdPartyAdParameters;
  if (this.thirdPartyAdParameters == null)
  {
    // Third-party ad parameters not set so just return
    //document.getElementById("debugTA").value += "\n Third-party ad parameters not set.";
    return false;
  }

  /*
  var tmpStr = "";
  for (var prop in this.thirdPartyAdParameters)
  {
    tmpStr += "\n  " + prop + "=" + this.thirdPartyAdParameters[prop];

    for (var prop2 in this.thirdPartyAdParameters[prop])
    {
      tmpStr += "\n   " + prop2 + "=" + this.thirdPartyAdParameters[prop][prop2];

      for (var prop3 in this.thirdPartyAdParameters[prop][prop2])
      {
        tmpStr += "\n    " + prop3 + "=" + this.thirdPartyAdParameters[prop][prop2][prop3];
      }
    }
  }
  document.getElementById("debugTA").value += tmpStr;
  */

  this.thirdPartyAdParameters.adRequestState = "loading";
  
  if ((DayPortVideo.system.osPlatform == "Mac") && (DayPortVideo.system.browser == "Internet Explorer"))
  {
    setTimeout("document.getElementById('" + this.videoID + "_thirdPartyAdRequester').innerHTML = '_<scr' + 'ipt id=\"" + this.videoID + "_thirdPartyAdRequesterJS\" language=\"JavaScript\" type=\"text/javascript\" src=\"" + this.thirdPartyAdParameters.video.requestURL + "\" defer></scr' + 'ipt>';", 100);
  }
  else
  {
    document.getElementById(this.videoID+"_thirdPartyAdRequester").innerHTML = "";
    var scriptObj = document.createElement("script");
    scriptObj.id = this.videoID + "_thirdPartyAdRequesterJS";
    scriptObj.defer = true;
    scriptObj.src = this.thirdPartyAdParameters.video.requestURL;
    var target = this;
    /*setTimeout(function()
    {
      document.getElementById(target.videoID+"_thirdPartyAdRequester").appendChild(scriptObj);
    }, 10);*/
    document.getElementById(this.videoID+"_thirdPartyAdRequester").appendChild(scriptObj);
  }
  
  

  return true;
};

// Callback for DayPortWMVVideo.requestThirdPartyAd method.
DayPortWMVVideo.prototype.requestThirdPartyAdCB = function(adObject)
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.requestThirdPartyAdCB() called.";
  //document.getElementById("debugTA").value += "\n adObject="+adObject;

  /*
  var tmpStr = "";
  for (var prop in adObject)
  {
    tmpStr += "\n  " + prop + "=" + adObject[prop];
  }
  document.getElementById("debugTA").value += tmpStr;
  */

  document.getElementById(this.videoID+"_thirdPartyAdRequester").innerHTML = "";
  this.thirdPartyAdParameters.adRequestState = "loaded";

  // Set default values for the response data
  this.thirdPartyAdParameters.video.clickURL = "";
  this.thirdPartyAdParameters.video.externalImpressionTrackURL = null;
  this.thirdPartyAdParameters.video.externalCompletionTrackURL = null;
  this.thirdPartyAdParameters.video.videoURL = null;
  this.thirdPartyAdParameters.video.adname = "";

  // Process/map response data
  // DoubleClick format
  this.thirdPartyAdParameters.video.clickURL = adObject.clickURL;
  this.thirdPartyAdParameters.video.adname = adObject.adname;
  this.videoAdName = adObject.adname;

  var numURLs = adObject.impression.length;
  //document.getElementById("debugTA").value += "\n numURLs="+numURLs;
  for (var i=0; i < numURLs; i++)
  {
    if (adObject.impression[i] != "")
    {
      if (this.thirdPartyAdParameters.video.externalImpressionTrackURL == null)
      {
        this.thirdPartyAdParameters.video.externalImpressionTrackURL = new Array();
      }

      // Add random value to the URL to help prevent caching
      this.thirdPartyAdParameters.video.externalImpressionTrackURL[this.thirdPartyAdParameters.video.externalImpressionTrackURL.length] = adObject.impression[i] + DayPortVideo.appendRandom(adObject.impression[i]);
    }
  }

  var numURLs = adObject.click.length;
  //document.getElementById("debugTA").value += "\n numURLs="+numURLs;
  for (var i=0; i < numURLs; i++)
  {
    if (adObject.click[i] != "")
    {
      if (this.thirdPartyAdParameters.video.externalCompletionTrackURL == null)
      {
        this.thirdPartyAdParameters.video.externalCompletionTrackURL = new Array();
      }

      // Add random value to the URL to help prevent caching
      this.thirdPartyAdParameters.video.externalCompletionTrackURL[this.thirdPartyAdParameters.video.externalCompletionTrackURL.length] = adObject.click[i] + DayPortVideo.appendRandom(adObject.click[i]);
    }
  }

  this.thirdPartyAdParameters.video.videoURL = adObject.wmvhigh;

  var numBanners = this.thirdPartyAdParameters.banners.length;
  //document.getElementById("debugTA").value += "\n numBanners="+numBanners;
  for (var i=0; i < numBanners; i++)
  {
    // Add the ad ID to the callout URL
    this.thirdPartyAdParameters.banners[i].calloutURL = this.thirdPartyAdParameters.banners[i].calloutURL.replace("[adID]", adObject.adid);
    //document.getElementById("debugTA").value += "\n DayPortWMVVideo.thirdPartyAdParameters.banners["+i+"].calloutURL="+this.thirdPartyAdParameters.banners[i].calloutURL;

    // Set the callout method to use
    this.thirdPartyAdParameters.banners[i].calloutMethod = "javascript";
  }


  // Set banner ad(s)
  for (var i=0; i < numBanners; i++)
  {
    var elementRef = this.thirdPartyAdParameters.banners[i].elementRef;

    this.setAd(this.elements["bannerAd_"+elementRef].containerObject, null, null, null, null, this.elements["bannerAd_"+elementRef].width, this.elements["bannerAd_"+elementRef].height, null, this.thirdPartyAdParameters.banners[i].calloutURL, this.thirdPartyAdParameters.banners[i].calloutMethod);

    //document.getElementById("debugTA").value += "\n DayPortWMVVideo.thirdPartyAdParameters.banners["+i+"].impressionTrackURL="+this.thirdPartyAdParameters.banners[i].impressionTrackURL;
    if (this.thirdPartyAdParameters.banners[i].impressionTrackURL != null)
    {
      // Track banner via impression tracking URL
      this.elements["bannerAd_"+elementRef].impressionTrackImageObject.src = this.thirdPartyAdParameters.banners[i].impressionTrackURL;
    }
  }

  // Need to handle changing the adState property
  // Set the source to a video advertisement if one returned in response data, or look for a queued article

  this.processingAdPackages = false;

  // See if ad-package settings changes have been queued
  if ((this.queuedAdPackageArray != null) && (this.queuedBannerAdElementArray != null))
  {
    this.setAdPackages(this.queuedAdPackageArray, this.queuedBannerAdElementArray);
  }

  //document.getElementById("debugTA").value += "\n DayPortWMVVideo.thirdPartyAdParameters.video.videoURL="+this.thirdPartyAdParameters.video.videoURL;
  if ((typeof this.thirdPartyAdParameters.video.videoURL != "undefined") && (this.thirdPartyAdParameters.video.videoURL != null) && (this.thirdPartyAdParameters.video.videoURL != ""))
  {
    this.setSource("advertisement", null, null, this.thirdPartyAdParameters.video.clickURL, this.thirdPartyAdParameters.video.impressionTrackURL, this.thirdPartyAdParameters.video.externalImpressionTrackURL, this.thirdPartyAdParameters.video.completionTrackURL, this.thirdPartyAdParameters.video.externalCompletionTrackURL, this.thirdPartyAdParameters.video.videoURL);

    if (this.adInsertionChangeInterval != null)
    {
      // Track insertion of video advertisement
      this.adInsertionCount_track();
    }
  }
  else
  {
    //document.getElementById("debugTA").value += "\n Invalid video advertisement from a third-party ad request detected. (DayPortWMVVideo.thirdPartyAdParameters.video.videoURL="+this.thirdPartyAdParameters.video.videoURL+").";

    if (this.metadataState == "loading")
    {
      // Let callback for DayPortWMVVideo.retrieveMetadata method (DayPortWMVVideo.retrieveMetadataCB method) handle continuing on
      this.adState = "inactive";
    }
    else
    {
      this.adState = "inactive";

      if (this.articleID != null)
      {
        // Raise OnEndOfAd event
        this.OnEndOfAd();

        //document.getElementById("debugTA").value += "\n No advertisement to play, triggering play of queued article (ID of "+this.articleID+").";
        if(this.contentDomain != this.domain && typeof this.contentDomain != "undefined") 
        	var tmpArticleID = this.articleID+"@"+this.contentDomain;
        else
         var tmpArticleID = this.articleID;

        this.setSource("article", tmpArticleID);
      }
      else
      {
        if (this.currPlayState != 0)
        {
          this.stop();
        }
        else
        {
          // Raise OnStopped event
          this.OnStopped();
        }

        // Raise OnEndOfAd event
        this.OnEndOfAd();
      }
    }
  }

  // Reset thirdPartyAdParameters property
  this.thirdPartyAdParameters = null;
};

DayPortWMVVideo.prototype.requirementsCheck = function()
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.requirementsCheck() called.";
  
  var supported = false;
  var requirementsMet = true;
  
  // Check OS
  //document.getElementById("debugTA").value += "\n DayPortVideo.system.osPlatform="+DayPortVideo.system.osPlatform;
  switch (DayPortVideo.system.osPlatform)
  {
    case "Windows":
      // Supported OS for this format.
      // Check browser
      //document.getElementById("debugTA").value += "\n DayPortVideo.system.browser="+DayPortVideo.system.browser;
      switch (DayPortVideo.system.browser)
      {
        case "Internet Explorer":
          // Supported browser for this format.
          supported = true;
          break;
          
        case "Firefox":
        case "Mozilla":
          // See if third-party ActiveX plugin is installed
          if (navigator.plugins && navigator.plugins.length)
          {
            var activeXPluginObj = navigator.plugins["Mozilla ActiveX control and plugin support"];
            //document.getElementById("debugTA").value += "\n activeXPluginObj="+activeXPluginObj;
            if (activeXPluginObj)
            {
              // Supported browser for this format.
              supported = true;
            }
            else
            {
              // Unsupported browser for this format.
              requirementsMet = false;
            }
          }
          else
          {
            // Unsupported browser for this format.
            requirementsMet = false;
          }
          break;

        case "Netscape":
          if ((parseFloat(DayPortVideo.system.browserVersion, 10) >= 7.1) && (parseFloat(DayPortVideo.system.browserVersion, 10) < 8))
          {
            // Supported browser for this format.
          }
          else
          {
            // Unsupported browser for this format.
            requirementsMet = false;
          }
          break;


        case "Opera":
        case "Konqueror":
        case "Safari":
        case "AOL":
        default:
          // Unsupported browser for this format.
          requirementsMet = false;
      }
      break;

    case "Mac":
    default:
      // Unsupported OS for this format.
      requirementsMet = false;
  }
  
  if (!supported)
  {
    this.scriptControlSupported = false;
    // Raise OnScriptControlUnsupported event
    if ((DayPortVideo.system.osPlatform == "Mac") && (DayPortVideo.system.browser == "Internet Explorer"))
    {
      setTimeout("DayPortVideo.objectArray[" + eval(this.objectArrayIndex) + "].video.OnScriptControlUnsupported();", 100);
    }
    else
    {
      var target = this;
      setTimeout(function()
      {
        target.OnScriptControlUnsupported();
      }, 10);
    }
  }


  // Check for installation and version of Windows Media Player

  return requirementsMet;
};

// Retrieve metadata for an article.
DayPortWMVVideo.prototype.retrieveMetadata = function()
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.retrieveMetadata() called.";
  //document.getElementById("debugTA").value += "\n this.contentDomain="+this.contentDomain;
  //document.getElementById("debugTA").value += "\n this.articleID="+this.articleID;
  
  this.metadataState = "loading";
  
  if(this.contentDomain == "") this.contentDomain = this.domain;
  
  // Clear metadata object properties
  this.metadata = new Object();
  // Define formatsAvailable property as an array
  this.metadata.formatsAvailable = new Array();

  //this.mdRetrieverObject.src = "http://" + this.domain + "/nw/article/view/" + this.articleID + "/?tf=DayPortPlayerArticleMetadata.tpl&UserDef=true&mt=1";
  
  if ((DayPortVideo.system.osPlatform == "Mac") && (DayPortVideo.system.browser == "Internet Explorer"))
  {
    setTimeout("DayPortVideo.objectArray[" + eval(this.objectArrayIndex) + "].video.mdRetrieverObject.innerHTML = '_<scr' + 'ipt language=\"JavaScript\" type=\"text/javascript\" src=\"http://" + this.domain + "/nw/article/view/" + this.articleID + "/?tf=DayPortPlayerArticleMetadata.tpl&UserDef=true&mt=1\" defer></scr' + 'ipt>';", 100);
  }
  else if ((DayPortVideo.system.osPlatform == "Mac") && (DayPortVideo.system.browser == "Safari"))
  {
    this.mdRetrieverObject.innerHTML = "";
    var scrObj = document.createElement("script");
    scrObj.id = this.videoID + "_metadataRetrieverJS";
    scrObj.defer = true;
    scrObj.src = "http://" + this.contentDomain + "/nw/article/view/" + this.articleID + "/?tf=DayPortPlayerArticleMetadata.tpl&UserDef=true&mt=1";
    var target = this;
    setTimeout(function()
    {
      target.mdRetrieverObject.appendChild(scrObj);
    }, 10);
  }
  else
  {
    this.mdRetrieverObject.innerHTML = '_<scr' + 'ipt id="' + this.videoID + '_metadataRetrieverJS" language="JavaScript" type="text/javascript" defer></scr' + 'ipt>';
    var target = this;
    //document.getElementById("debugTA").value += "\n requestURL=http://" + this.contentDomain + "/nw/article/view/" + this.articleID + "/?tf=DayPortPlayerArticleMetadata.tpl&UserDef=true&mt=1";
    setTimeout(function()
    {
      document.getElementById(target.videoID+"_metadataRetrieverJS").src = "http://" + target.contentDomain + "/nw/article/view/" + target.articleID + "/?tf=DayPortPlayerArticleMetadata.tpl&UserDef=true&mt=1";
    }, 10);
  }
};

// Callback for DayPortWMVVideo.retrieveMetadata method.
DayPortWMVVideo.prototype.retrieveMetadataCB = function(metadataObj)
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.retrieveMetadataCB() called.";
  //document.getElementById("debugTA").value += "\n metadataObj="+metadataObj;

  /*
  var tmpStr = "";
  for (var prop in metadataObj)
  {
    tmpStr += "\n  " + prop + "=" + metadataObj[prop];

    for (var prop2 in metadataObj[prop])
    {
      tmpStr += "\n   " + prop2 + "=" + metadataObj[prop][prop2];

      for (var prop3 in metadataObj[prop][prop2])
      {
        tmpStr += "\n    " + prop3 + "=" + metadataObj[prop][prop2][prop3];
      }
    }
  }
  document.getElementById("debugTA").value += tmpStr;
  */

  this.mdRetrieverObject.innerHTML = "";

  if (metadataObj == null)
  {
    // Article content is currently unavailable.
    this.metadataState = "loaded";
    // Raise OnMetadataRetrieved event
    this.OnMetadataRetrieved();
    return;
  }

  this.metadata.body = metadataObj.body;
  this.metadata.duration = metadataObj.duration;
  var numFormats = metadataObj.formatsAvailable.length;
  for (var i=0; i < numFormats; i++)
  {
    this.metadata.formatsAvailable[i] = {
                                          bitrateID: metadataObj.formatsAvailable[i].bitrateID,
                                          formatID: metadataObj.formatsAvailable[i].formatID,
                                          url: metadataObj.formatsAvailable[i].url
                                        };
  }
  this.metadata.hasVideo = metadataObj.hasVideo;
  this.metadata.id = metadataObj.id;
  this.metadata.isLive = metadataObj.isLive;
  this.metadata.intro = metadataObj.intro;
  this.metadata.introHTML = metadataObj.introHTML;
  this.metadata.name = metadataObj.name;
  this.metadata.previewImage = metadataObj.previewImage;
  this.metadata.userDef1 = metadataObj.userDef1;
  this.metadata.userDef2 = metadataObj.userDef2;
  this.metadata.userDef3 = metadataObj.userDef3;
  this.metadata.userDef4 = metadataObj.userDef4;
  this.metadata.userDef5 = metadataObj.userDef5;
  this.metadata.userDef6 = metadataObj.userDef6;
  this.metadata.userDef7 = metadataObj.userDef7;
  this.metadata.userDef8 = metadataObj.userDef8;
  this.metadata.userDef9 = metadataObj.userDef9;
  this.metadata.userDef10 = metadataObj.userDef10;
  this.metadata.userDef11 = metadataObj.userDef11;
  this.metadata.userDef12 = metadataObj.userDef12;
  this.metadata.userDef13 = metadataObj.userDef13;
  this.metadata.userDef14 = metadataObj.userDef14;
  this.metadata.userDef15 = metadataObj.userDef15;
  this.metadata.userDef16 = metadataObj.userDef16;
  this.metadata.userDef17 = metadataObj.userDef17;
  this.metadata.userDef18 = metadataObj.userDef18;
  this.metadata.userDef19 = metadataObj.userDef19;
  this.metadata.userDef20 = metadataObj.userDef20;
  
  this.metadata.domain = this.contentDomain;

  /*
  for (var prop in metadataObj)
  {
    //this.metadata.formatsAvailable[i] = metadataObj.formatsAvailable[i];
    if (prop == "formatsAvailable")
    {
      var numFormats = metadataObj.formatsAvailable.length;
      for (var i=0; i < numFormats; i++)
      {
        this.metadata[prop][i] = new Object();
        for (var faProp in metadataObj[prop])
        {
          this.metadata[prop][i][faProp] = metadataObj[prop][i][faProp];
        }
      }
    }
    else
    {
      this.metadata[prop] = metadataObj[prop];
    }
  }
  */
  //document.getElementById("debugTA").value += "\n this.metadata.isLive="+this.metadata.isLive;
  if(this.metadata.isLive == "true")
  {
  	this.isLive = true;
  }else{
  	this.isLive = false;
  }

  this.metadataState = "loaded";
  // Raise OnMetadataRetrieved event
  this.OnMetadataRetrieved();

  //document.getElementById("debugTA").value += "\n this.adState =" + this.adState;

  if (this.scriptControlSupported && (this.adState != "loading") && (this.adState != "playing"))
  {
	// Set the source
	this.stop();

	this.clickURL = null;
	this.impressionTrackURL = null;
	this.externalImpressionTrackURL = null;
	this.completionTrackURL = null;
	this.externalCompletionTrackURL = null;

	//document.getElementById("debugTA").value += "\n this.contentDomain="+this.contentDomain;
	this.videoObject.Open("http://" + this.contentDomain + "/viewer/content/special.php?Art_ID=" + this.articleID + "&Format_ID=2&BitRate_ID=8&Contract_ID=&Obj_ID=&NoAds=true");
	// Raise OnTransitioning event
	this.OnTransitioning();

	this.startUpdateStatus();
  }
  else if (!this.scriptControlSupported)
  {
    
	if(!this.isLive && !this.requirmentsMet)
	{
		DayPortVideo.objectArray[this.objectArrayIndex].changeFormat(4);
		return;
	}
	// Generate the embedded video object
	this.videoObject = this.generateTag(this.videoID, this.width, this.height);

	// Raise OnTransitioning event
	this.OnTransitioning();
  }
};

DayPortWMVVideo.prototype.seek = function(seconds)
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.seek() called.";
  
  if (!this.scriptControlSupported)
  {
    return false;
  }
  
  if ((this.adState == "loading") || (this.adState == "playing"))
  {
    // Disallow seeking during ad playback
    return false;
  }

  var durationseconds = this.getDuration();
  //document.getElementById("debugTA").value += "\n seconds="+seconds+", durationseconds="+durationseconds;

  if (durationseconds == null)
  {
    if (seconds == 0)
    {
      if ((this.videoObject.MarkerCount >= 1) && (this.videoObject.GetMarkerName(1) == "Begin"))
      {
        // Adjust for Begin marker
        seconds += this.videoObject.GetMarkerTime(1);
      }

      //document.getElementById("debugTA").value += "\n Seeking to "+seconds;
      try
      {
        this.videoObject.CurrentPosition = seconds;
        if (this.currPlayState != 2)
        {
          this.getPosition();
        }

        return true;
      }
      catch(errorObject)
      {
        //document.getElementById("debugTA").value += "\n Unable to seek to Seconds ("+seconds+"). Duration was null.";
        this.stop();

        return false;
      }
    }
    else
    {
      //document.getElementById("debugTA").value += "\n Duration was not set yet, and Seconds ("+seconds+") was greater than zero.";
      this.stop();

      return false;
    }
  }

  if ((seconds == 0) || (seconds < (durationseconds - 0.001)) || (this.currPlayState != 2))
  {
    if ((this.videoObject.MarkerCount >= 1) && (this.videoObject.GetMarkerName(1) == "Begin"))
    {
      // Adjust for Begin marker
      seconds += this.videoObject.GetMarkerTime(1);
    }

    //document.getElementById("debugTA").value += "\n Seeking to "+seconds;
    try
    {
      this.videoObject.CurrentPosition = seconds;
      if (this.currPlayState != 2)
      {
        this.getPosition();
      }

      return true;
    }
    catch(errorObject)
    {
      //document.getElementById("debugTA").value += "\n Unable to seek to Seconds ("+seconds+"). Duration was ("+durationseconds+" - 0.001 = "+(durationseconds - 0.001)+").";
      this.stop();

      return false;
    }
  }
  else
  {
    //document.getElementById("debugTA").value += "\n Seconds ("+seconds+") was not less than Duration ("+durationseconds+" - 0.001 = "+(durationseconds - 0.001)+").";
    var beginPos = 0;
    if ((this.videoObject.MarkerCount >= 1) && (this.videoObject.GetMarkerName(1) == "Begin"))
    {
      // Adjust for Begin marker
      beginPos = this.videoObject.GetMarkerTime(1);
    }

    //document.getElementById("debugTA").value += "\n Seeking to "+((durationseconds + beginPos) - 0.1)+" seconds";
    try
    {
      this.videoObject.CurrentPosition = ((durationseconds + beginPos) - 0.1);
      if (this.currPlayState != 2)
      {
        this.getPosition();
      }

      return true;
    }
    catch(errorObject)
    {
      //document.getElementById("debugTA").value += "\n Unable to seek to Seconds ("+((durationseconds + beginPos) - 0.1)+"). Duration was ("+durationseconds+" - 0.001 = "+(durationseconds - 0.001)+").";
      this.stop();

      return false;
    }
  }
};

DayPortWMVVideo.prototype.setAd = function(adObj, conDefID, objID, conID, track, width, height, typeID, calloutURL, calloutMethod)
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.setAd() called.";

  if (typeID == 4)
  {
    this.setSource("advertisement", objID, conID, null, null, null, null, null, null);
    return true;
  }

  if (adObj == null)
  {
    // Ad object not registered
    //document.getElementById("debugTA").value += "\n Ad object not registered.";
    return false;
  }

  //document.getElementById("debugTA").value += "\n calloutURL="+calloutURL;
  if ((typeof calloutURL == "undefined") || (calloutURL == null))
  {
    //document.getElementById("debugTA").value += "\n Calling out a banner advertisement from the DayPort system.";

    var conTrack = "-1";
    if (track)
    {
      conTrack = "";
    }

    var rndm = DayPortVideo.genRandom();
    //adObj.innerHTML = '<iframe id="'+adObj.id+'_adcallout_' + rndm + '" onload="" src="http://' + this.domain + '/DayPortVideo_adcallout/?conDefID='+conDefID+'&objID='+objID+'&conID='+conID+'&conTrack='+conTrack+'&width='+width+'&height='+height+'&rndm='+rndm+'" style="width:'+width+'px; height:'+height+'px;" frameborder="0" scrolling="no"></iframe>';
    // Create Iframe with blank source first, then set it to avoid possible IE bug that can occur (previous Iframe source used despite new source specified).
    adObj.innerHTML = '<iframe id="'+adObj.id+'_adcallout_' + rndm + '" onload="" src="" style="width:'+width+'px; height:'+height+'px;" frameborder="0" scrolling="no"></iframe>';
    //document.getElementById("debugTA").value += "\n adObj.innerHTML="+adObj.innerHTML;
    document.getElementById(adObj.id+"_adcallout_"+rndm).src = 'http://' + this.domain + '/DayPortVideo_adcallout/?conDefID='+conDefID+'&objID='+objID+'&conID='+conID+'&conTrack='+conTrack+'&width='+width+'&height='+height+'&rndm='+rndm;
    //document.getElementById("debugTA").value += "\n adObj.innerHTML="+adObj.innerHTML;
  }
  else
  {
    //document.getElementById("debugTA").value += "\n Calling out a banner advertisement from a third-party system.";

    //document.getElementById("debugTA").value += "\n calloutMethod="+calloutMethod;
    // Force calloutMethod parameter to lower case if passed in as a string.
    if (typeof(calloutMethod) == "string")
    {
      calloutMethod = calloutMethod.toLowerCase();
    }

    switch (calloutMethod)
    {
      case "html":
        var rndm = DayPortVideo.genRandom();
        // Create Iframe with blank source first, then set it to avoid possible IE bug that can occur (previous Iframe source used despite new source specified).
        adObj.innerHTML = '<iframe id="'+adObj.id+'_adcallout_' + rndm + '" onload="" src="" style="width:'+width+'px; height:'+height+'px;" frameborder="0" scrolling="no"></iframe>';
        //document.getElementById("debugTA").value += "\n adObj.innerHTML="+adObj.innerHTML;
        document.getElementById(adObj.id+"_adcallout_"+rndm).src = calloutURL;
        //document.getElementById("debugTA").value += "\n adObj.innerHTML="+adObj.innerHTML;
        break;

      case "javascript":
      default:
        var rndm = DayPortVideo.genRandom();
        // Create Iframe with blank source first, then set it to avoid possible IE bug that can occur (previous Iframe source used despite new source specified).
        adObj.innerHTML = '<iframe id="'+adObj.id+'_adcallout_' + rndm + '" onload="" src="" style="width:'+width+'px; height:'+height+'px;" frameborder="0" scrolling="no"></iframe>';
        //document.getElementById("debugTA").value += "\n adObj.innerHTML="+adObj.innerHTML;
        document.getElementById(adObj.id+"_adcallout_"+rndm).src = "http://" + this.domain + "/DayPortVideo_adcallout/?calloutURL=" + escape(calloutURL) + "&width=" + width + "&height=" + height + "&rndm=" + rndm;
        //document.getElementById("debugTA").value += "\n adObj.innerHTML="+adObj.innerHTML;
    }
  }

  return true;
};

DayPortWMVVideo.prototype.setAdInsertionChangeInterval = function(numAds)
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.setAdInsertionChangeInterval() called.";
  //document.getElementById("debugTA").value += "\n numAds="+numAds;

  if (numAds == null)
  {
    // Disable adInsertionChangeInterval
    this.adInsertionChangeInterval = null;

    return true;
  }

  if (isNaN(parseInt(numAds, 10)))
  {
    // Invalid numAds parameter so just return.
    return false;
  }

  // Force numAds parameter to a number and a valid range (i.e., integer greater than 0).
  numAds = Math.max(parseInt(numAds, 10), 1);

  //document.getElementById("debugTA").value += "\n Setting adInsertionChangeInterval to "+numAds+" ad(s).";
  this.adInsertionChangeInterval = numAds;
  
  return true;
};

DayPortWMVVideo.prototype.setAdInsertionFrequency = function(numVideos)
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.setAdInsertionFrequency() called.";
  //document.getElementById("debugTA").value += "\n numVideos="+numVideos;

  if (numVideos == null)
  {
    // Disable adInsertionFrequency
    this.adInsertionFrequency = null;

    return true;
  }

  if (isNaN(parseInt(numVideos, 10)))
  {
    // Invalid numVideos parameter so just return.
    return false;
  }

  // Force numVideos parameter to a number and a valid range (i.e., integer greater than 0).
  numVideos = Math.max(parseInt(numVideos, 10), 1);

  //document.getElementById("debugTA").value += "\n Setting adInsertionFrequency to "+numVideos+" video(s).";
  this.adInsertionFrequency = numVideos;
  
  return true;
};

DayPortWMVVideo.prototype.setAdInsertionFrequencyChange = function(numVideos)
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.setAdInsertionFrequencyChange() called.";
  //document.getElementById("debugTA").value += "\n numVideos="+numVideos;

  if (numVideos == null)
  {
    // Disable adInsertionFrequencyChange
    this.adInsertionFrequencyChange = null;

    return true;
  }

  if (isNaN(parseInt(numVideos, 10)))
  {
    // Invalid numVideos parameter so just return.
    return false;
  }

  // Force numVideos parameter to a number and a valid range (i.e., integer greater than 0).
  numVideos = Math.max(parseInt(numVideos, 10), 1);

  //document.getElementById("debugTA").value += "\n Setting adInsertionFrequencyChange to "+numVideos+" video(s).";
  this.adInsertionFrequencyChange = numVideos;
  
  return true;
};

DayPortWMVVideo.prototype.setAdInsertionFrequencyMax = function(numVideos)
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.setAdInsertionFrequencyMax() called.";
  //document.getElementById("debugTA").value += "\n numVideos="+numVideos;

  if (numVideos == null)
  {
    // Disable adInsertionFrequencyMax (i.e., no maximum limit)
    this.adInsertionFrequencyMax = null;

    return true;
  }

  if (isNaN(parseInt(numVideos, 10)))
  {
    // Invalid numVideos parameter so just return.
    return false;
  }

  // Force numVideos parameter to a number and a valid range (i.e., integer greater than 0).
  numVideos = Math.max(parseInt(numVideos, 10), 1);

  //document.getElementById("debugTA").value += "\n Setting adInsertionFrequencyMax to "+numVideos+" video(s).";
  this.adInsertionFrequencyMax = numVideos;
  
  return true;
};

DayPortWMVVideo.prototype.setAdInsertionThreshold = function(numSeconds)
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.setAdInsertionThreshold() called.";
  //document.getElementById("debugTA").value += "\n numSeconds="+numSeconds;

  if (numSeconds == null)
  {
    // Disable adInsertionThreshold
    this.adInsertionThreshold = null;

    return true;
  }

  if (isNaN(parseInt(numSeconds, 10)))
  {
    // Invalid numSeconds parameter so just return.
    return false;
  }

  // Force numSeconds parameter to a number and a valid range (i.e., integer greater than 0).
  numSeconds = Math.max(parseInt(numSeconds, 10), 1);

  //document.getElementById("debugTA").value += "\n Setting adInsertionThreshold to "+numSeconds+" second(s).";
  this.adInsertionThreshold = numSeconds;
  
  return true;
};

DayPortWMVVideo.prototype.setAdInsertionThresholdChange = function(numSeconds)
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.setAdInsertionThresholdChange() called.";
  //document.getElementById("debugTA").value += "\n numSeconds="+numSeconds;

  if (numSeconds == null)
  {
    // Disable adInsertionThresholdChange
    this.adInsertionThresholdChange = null;

    return true;
  }

  if (isNaN(parseInt(numSeconds, 10)))
  {
    // Invalid numSeconds parameter so just return.
    return false;
  }

  // Force numSeconds parameter to a number and a valid range (i.e., integer greater than 0).
  numSeconds = Math.max(parseInt(numSeconds, 10), 1);

  //document.getElementById("debugTA").value += "\n Setting adInsertionThresholdChange to "+numSeconds+" second(s).";
  this.adInsertionThresholdChange = numSeconds;
  
  return true;
};

DayPortWMVVideo.prototype.setAdInsertionThresholdMax = function(numSeconds)
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.setAdInsertionThresholdMax() called.";
  //document.getElementById("debugTA").value += "\n numSeconds="+numSeconds;

  if (numSeconds == null)
  {
    // Disable adInsertionThresholdMax (i.e., no maximum limit)
    this.adInsertionThresholdMax = null;

    return true;
  }

  if (isNaN(parseInt(numSeconds, 10)))
  {
    // Invalid numSeconds parameter so just return.
    return false;
  }

  // Force numSeconds parameter to a number and a valid range (i.e., integer greater than 0).
  numSeconds = Math.max(parseInt(numSeconds, 10), 1);

  //document.getElementById("debugTA").value += "\n Setting adInsertionThresholdMax to "+numSeconds+" second(s).";
  this.adInsertionThresholdMax = numSeconds;
  
  return true;
};

DayPortWMVVideo.prototype.setAdPackages = function(adPackageArray, bannerAdElementArray)
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.setAdPackages() called.";
  //document.getElementById("debugTA").value += "\n adPackageArray="+adPackageArray+", bannerAdElementArray="+bannerAdElementArray;

  // See if ad-package settings are actively in use
  //document.getElementById("debugTA").value += "\n DayPortWMVVideo.processingAdPackages="+this.processingAdPackages;
  if (this.processingAdPackages)
  {
    // Queue changing the ad-package settings
    if (adPackageArray == null)
    {
      adPackageArray = new Array();
    }

    if (bannerAdElementArray == null)
    {
      bannerAdElementArray = new Array();
    }

    this.queuedAdPackageArray = adPackageArray;
    this.queuedBannerAdElementArray = bannerAdElementArray;
    return true;
  }

  // Reset queuedAdPackageArray and queuedBannerAdElementArray properties
  this.queuedAdPackageArray = null;
  this.queuedBannerAdElementArray = null;

  var tmpAutoAdInsertion = this.autoAdInsertion;
  var tmpAdPackageArray = new Array();
  var tmpBannerAdElementArray = new Array();

  if ((adPackageArray != "") && (adPackageArray != null) && (typeof adPackageArray != "undefined"))
  {
    var numPackages = adPackageArray.length;
    //document.getElementById("debugTA").value += "\n numPackages="+numPackages;
    for (var i=0; i < numPackages; i++)
    {
      tmpAdPackageArray[i] = new Object();
      tmpAdPackageArray[i].conDefID = adPackageArray[i].conDefID;
      tmpAdPackageArray[i].objects = new Array();
      var numObjects = adPackageArray[i].objects.length;
      for (var oi=0; oi < numObjects; oi++)
      {
        tmpAdPackageArray[i].objects[oi] = new Object();
        tmpAdPackageArray[i].objects[oi].objectID = adPackageArray[i].objects[oi].objectID;
        tmpAdPackageArray[i].objects[oi].adType = adPackageArray[i].objects[oi].adType;
        tmpAdPackageArray[i].objects[oi].track = adPackageArray[i].objects[oi].track;
        tmpAdPackageArray[i].objects[oi].elementRef = null;
      }
    }

    if ((bannerAdElementArray != "") && (bannerAdElementArray != null) && (typeof bannerAdElementArray != "undefined"))
    {
      var numElements = bannerAdElementArray.length;
      //document.getElementById("debugTA").value += "\n numElements="+numElements;
      for (var i=0; i < numElements; i++)
      {
        tmpBannerAdElementArray[i] = bannerAdElementArray[i];
      }
    }
  }

  // See if need to temporarily disable automatic ad insertion
  if (this.autoAdInsertion)
  {
    this.setAutoAdInsertion(false);
  }

  // Unregister any previously registered banner-ad elements
  for (var elementObj in this.elements)
  {
    if (this.elements[elementObj].idStr == "bannerad")
    {
      // Remove the impressionTrackImageObject
      document.getElementById(this.videoID+"_trackImageContainer").removeChild(this.elements[elementObj].impressionTrackImageObject);
      this.elements[elementObj].impressionTrackImageObject = null;

      // Delete the element from the array
      delete this.elements[elementObj];
    }
  }

  // Change ad-package settings
  this.adPackageArray = tmpAdPackageArray;

  this.adArray = new Array();
  var adRequesterStr = "";
  var numPackages = this.adPackageArray.length;
  for (var i=0; i < numPackages; i++)
  {
    adRequesterStr +=  '<span id="' + this.videoID + '_adRequester_' + (i + 1) + '" style="position:absolute; left:0px; top:0px; width:1px; height:1px; visibility:hidden; display:none;"></span>';

    this.adArray["ConDef_"+this.adPackageArray[i].conDefID] = {
                                                                adRequestRef:(i + 1),
                                                                adRequestState:"uninitialized"
                                                              };
  }
  document.getElementById(this.videoID+"_adRequesterContainer").innerHTML = adRequesterStr;

  // Register any banner-ad elements that were passed in
  var numElements = tmpBannerAdElementArray.length;
  //document.getElementById("debugTA").value += "\n numElements="+numElements;
  for (var i=0; i < numElements; i++)
  {
    this.registerElement("bannerad", tmpBannerAdElementArray[i]);
  }

  // See if need to re-enable automatic ad insertion
  if (tmpAutoAdInsertion)
  {
    this.setAutoAdInsertion(true);
  }

  return true;
};

DayPortWMVVideo.prototype.setAutoAdInsertion = function(enabled)
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.setAutoAdInsertion() called.";
  //document.getElementById("debugTA").value += "\n enabled="+enabled;

  if (enabled && (this.adPackageArray.length > 0))
  {
    this.autoAdInsertion = true;

    if (!this.intervalStopped && (this.adState == "inactive"))
    {
      this.adState = "tracking";
    }
  }
  else
  {
    this.autoAdInsertion = false;

    if (this.adState == "tracking")
    {
      this.adState = "inactive";
    }
  }
};

DayPortWMVVideo.prototype.setDomain = function(domain)
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.setDomain() called.";

  if ((domain != "") && (domain != null) && (typeof domain != "undefined"))
  {
    this.domain = domain;

    return true;
  }
  else
  {
    return false;
  }
};

DayPortWMVVideo.prototype.setSize = function(width, height)
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.setSize() called.";
  
  if (!this.scriptControlSupported)
  {
    return;
  }
  
  if ((width == "") || (width == null) || (typeof width == "undefined"))
    width = this.getWidth();

  if ((height == "") || (height == null) || (typeof height == "undefined"))
    height = this.getHeight();

  this.width = width;
  this.height = height;

  // Set width and height of WMV object
  this.videoObject.width = width;
  this.videoObject.height = height;
};

DayPortWMVVideo.prototype.setSource = function(type)
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.setSource() called.";
  //document.getElementById("debugTA").value += "\n type="+type;

  var numArgs = arguments.length;

  // Force type parameter to lower case if passed in as a string.
  if (typeof(type) == "string")
  {
    type = type.toLowerCase();
  }

  switch (type)
  {
    case "advertisement":
      // Play an advertisement
      if (numArgs < 9)
      {
        //document.getElementById("debugTA").value += "\n Invalid number of arguments for source type of 'advertisement'. (arguments="+arguments+")";
        return false;
      }

      this.stop();

      // Handle click URL
      if (arguments[3] != "")
      {
        this.clickURL = arguments[3];
      }
      else
      {
        this.clickURL = null;
      }
      //document.getElementById("debugTA").value += "\n clickURL="+this.clickURL;

      // Handle impression tracking URL
      // For now, only set if playing an advertisement from a third-party system.
      if ((arguments[4] != "") && ((arguments[1] == null) && (arguments[2] == null)))
      {
        this.impressionTrackURL = arguments[4];
      }
      else
      {
        this.impressionTrackURL = null;
      }

      // Handle external impression tracking URL(s)
      if ((arguments[5] != null) && (arguments[5].length > 0))
      {
        this.externalImpressionTrackURL = arguments[5];
      }
      else
      {
        this.externalImpressionTrackURL = null;
      }

      // Handle completion tracking URL
      if (arguments[6] != "")
      {
        this.completionTrackURL = arguments[6];
      }
      else
      {
        this.completionTrackURL = null;
      }

      // Handle external completion tracking URL(s)
      if ((arguments[7] != null) && (arguments[7].length > 0))
      {
        this.externalCompletionTrackURL = arguments[7];
      }
      else
      {
        this.externalCompletionTrackURL = null;
      }

      if ((arguments[1] != null) && (arguments[2] != null))
      {
        //document.getElementById("debugTA").value += "\n Playing an advertisement from the DayPort system. (arguments[1]="+arguments[1]+", arguments[2]="+arguments[2]+")";
        this.videoObject.Open("http://" + this.domain + "/viewer/content/special.php?Art_ID=&Format_ID=2&BitRate_ID=8&Contract_ID=" + arguments[2] + "&Obj_ID=" + arguments[1]);
      }
      else
      {
        //document.getElementById("debugTA").value += "\n Playing an advertisement from a third-party system. (arguments[8]="+arguments[8]+")";
        this.videoObject.Open(arguments[8]);
      }
      this.adState = "playing";
      break;

    case "article":
      // Play an article
      if (numArgs < 2)
      {
        //document.getElementById("debugTA").value += "\n Invalid number of arguments for source type of 'article'. (arguments="+arguments+")";
        return false;
      }
      
      //find alternate domain
      var articleTempID = String(arguments[1]);
      var atSign = articleTempID.indexOf("@");
      if(atSign != -1)
      {
			
			//document.getElementById("debugTA").value += "\n atSign="+atSign;

			var temp_article_split = articleTempID.split("@");
			if(temp_article_split[1] != "" && typeof temp_article_split[1] != "undefined")
			{
				this.contentDomain = temp_article_split[1];
				arguments[1] = temp_article_split[0];
			}else{
				this.contentDomain = this.domain;
			}
		}else{
			this.contentDomain = this.domain;
		}

      //document.getElementById("debugTA").value += "\n DayPortCPEWMVVideo.scriptControlSupported="+this.scriptControlSupported;
      if (this.scriptControlSupported)
      {
	      if (this.autoAdInsertion)
	      {
				switch (this.adState)
				{
				  case "queued":
					 this.stop();
					 // See if metadata is already set
					 if (this.metadata.id != arguments[1])
					 {
						// Changing article
						this.articleID = arguments[1];

						// Retrieve article metadata
						this.retrieveMetadata();
					 }
					 this.changeAds();
					 return false;
					 break;

				  case "loading":
				  case "playing":
					 // See if metadata is already set
					 if (this.metadata.id != arguments[1])
					 {
						// Changing article
						this.articleID = arguments[1];

						// Retrieve article metadata
						this.retrieveMetadata();
					 }
					 return false;
					 break;
				}
	      }

	      this.stop();

	      // See if metadata is already set
	      if (this.metadata.id != arguments[1] || this.metadata.domain != this.contentDomain)
	      {
				// Changing article
				this.articleID = arguments[1];
				

				// Retrieve article metadata before actually setting the source
				this.retrieveMetadata();

				// Raise OnTransitioning event
				this.OnTransitioning();

				return true;
			}
			this.contentDomain = this.metadata.domain;
			this.clickURL = null;
			this.impressionTrackURL = null;
			this.externalImpressionTrackURL = null;
			this.completionTrackURL = null;
			this.externalCompletionTrackURL = null;

			//document.getElementById("debugTA").value += "\n Playing article ID of "+arguments[1]+" in domain "+this.contentDomain;
			this.videoObject.Open("http://" + this.contentDomain + "/viewer/content/special.php?Art_ID=" + arguments[1] + "&Format_ID=2&BitRate_ID=8&Contract_ID=&Obj_ID=&NoAds=true");
     	}else{
	

	      
			// See if metadata is already set
			if (this.metadata.id != arguments[1] || this.metadata.domain != this.contentDomain)
			{
			  // Changing article
			  this.articleID = arguments[1];

			  // Retrieve article metadata before actually setting the source
			  this.retrieveMetadata();

			  // Raise OnTransitioning event
			  this.OnTransitioning();

			  return true;
			}

			if(!this.isLive && !this.requirmentsMet)
			{
				DayPortVideo.objectArray[this.objectArrayIndex].changeFormat(4);
				return false;
			}

			// Generate the embedded video object
			this.videoObject = this.generateTag(this.videoID, this.width, this.height);

			// Raise OnTransitioning event
			this.OnTransitioning();

			return true;
		}
		break;

		default:
			// Invalid source type
			//document.getElementById("debugTA").value += "\n Invalid source type. (type="+type+")";
			return false;
	}

  // Raise OnTransitioning event
  this.OnTransitioning();

  this.startUpdateStatus();

  return true;
};

DayPortWMVVideo.prototype.setVolume = function(volumePercent)
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.setVolume() called.";
  //document.getElementById("debugTA").value += "\n volumePercent="+volumePercent;
  
  if (!this.scriptControlSupported)
  {
    return false;
  }
  
  if ((typeof volumePercent == "undefined") || isNaN(parseInt(volumePercent, 10)))
  {
    // Invalid volumePercent parameter so just return.
    return false;
  }

  // Force volumePercent parameter to a number and a valid range (i.e., 0-100).
  volumePercent = parseInt(volumePercent, 10);
  volumePercent = Math.min(volumePercent, 100);
  volumePercent = Math.max(volumePercent, 0);

  //document.getElementById("debugTA").value += "\n Setting volume level to "+volumePercent+"%.";
  var maxVol = 0;
  var minVol = -4300;
  var newVol = minVol + ((maxVol - minVol) * (volumePercent / 100));
  this.videoObject.Volume = newVol;
  this.volumeLevel = volumePercent;

  return true;
};

DayPortWMVVideo.prototype.startUpdateStatus = function()
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.startUpdateStatus() called.";
  
  if (!this.scriptControlSupported)
  {
    // Disable the status update
    return false;
  }
  
  // If timer already started just return.
  if (!this.intervalStopped)
  {
    return false;
  }

  this.intervalStopped = false;
  if (this.autoAdInsertion && (this.adState == "inactive"))
  {
    this.adState = "tracking";
  }
  var target = this;
  this.intervalID = window.setInterval(function()
  {
    target.updateStatus();
  }, this.interval);
};

DayPortWMVVideo.prototype.stop = function()
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.stop() called.";
  
  if (!this.scriptControlSupported)
  {
    	this.videoObject = this.generateTag(this.videoID, this.width, this.height, true);
    	
    	// Raise OnStopped event
    	this.OnStopped();
  }else{
  
  	this.videoObject.Stop();
  }
};

DayPortWMVVideo.prototype.stopUpdateStatus = function()
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.stopUpdateStatus() called.";

  this.intervalStopped = true;
  var timer = this;
  window.clearInterval(timer.intervalID);
  this.intervalID = -1;

  if (this.autoAdInsertion && (this.adState == "tracking"))
  {
    this.adState = "inactive";
  }
};

DayPortWMVVideo.prototype.toString = function()
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.toString() called.";

  return "[object DayPortWMVVideo]";
};

DayPortWMVVideo.prototype.unregisterEventListener = function(objEvent, listenerFunc)
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.unregisterEventListener() called.";

  if (typeof this.events[objEvent] == "undefined")
  {
    // This event cannot be registered for
    return false;
  }

  if (typeof this.events[objEvent][listenerFunc] == "undefined")
  {
    // This listener function was not registered for this event
    return true;
  }

  delete this.events[objEvent][listenerFunc];

  return true;
};

DayPortWMVVideo.prototype.updateStatus = function()
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.updateStatus() called.";
  
  if (!this.scriptControlSupported)
  {
    return;
  }
  
  // Update Status
  this.getPosition();

  if (this.autoAdInsertion && (this.adInsertionThreshold != null))
  {
    // Track elapsed time of video playback
    this.elapsedPlayback_track(this.videoObject.CurrentPosition);
  }

  /*
  // Manual PlayState check
  var tmpPlayState = this.videoObject.PlayState;
  if (tmpPlayState != this.currPlayState)
  {
    // Manually detected PlayState change.
    //document.getElementById("debugTA").value += "\n Manually detected PlayState change."
    this.OnPlayStateChange(this.currPlayState, tmpPlayState);
  }

  // Manual Buffering check
  var tmpBufferingProgress = this.videoObject.BufferingProgress;
  if (!this.wasBuffering && (tmpBufferingProgress > 0) && (tmpBufferingProgress < 100))
  {
    // Manually detected start of buffering.
    //document.getElementById("debugTA").value += "\n Manually detected start of buffering."
    this.OnBuffering(true);
  }
  else if (this.wasBuffering && (tmpBufferingProgress == 100))
  {
    // Manually detected stop of buffering.
    //document.getElementById("debugTA").value += "\n Manually detected stop of buffering."
    this.OnBuffering(false);
  }
  */
};
/******************** End of DayPortWMVVideo Class ********************/