/******************** DayPortVideo Class ********************/
function DayPortVideo(containerHndl, domain, imageDomain, format, videoID, width, height, adPackageArray)
{
  //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);
      break;

    case 4:
    case "FLV":
      this.video = new DayPortFLVVideo(this.objectArrayIndex, containerHndl, domain, imageDomain, videoID, width, height, adPackageArray);
      break;

    default:
      this.video = null;
      // Remove reference to DayPortVideo object in global array.
      this.objectArrayIndex = null;
      DayPortVideo.objectArray.length--;
  }
}

DayPortVideo.adArray = new Array();

// 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 appended onto URL's to help prevent cached content from being returned.
// The returned string is in the format of CURRENTTIMEINMS_RANDOMNUMBER
DayPortVideo.genRandom = function()
{
  //document.getElementById("debugTA").value += "\nDayPortVideo.genRandom() called.";

  var CurrTime = new Date();
  var rtnVal = CurrTime.getTime() + "_" + Math.random();

  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)
{
  //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;

  // 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);
      //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")
            {
              tmpParameters[param] = tmpElements[objElementR][param];
            }
          }

          this.video.registerElement(tmpElements[objElementR].idStr, tmpParameters);
        }
      }
      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);
      //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")
            {
              tmpParameters[param] = tmpElements[objElementR][param];
            }
          }

          this.video.registerElement(tmpElements[objElementR].idStr, tmpParameters);
        }
      }
      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.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]);
    }
  }
};

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)
{
  //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.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 ((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.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.pageLoadedReceipt = false;

  if(!this.requirementsCheck())
  {
    //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.interval = 1000;
    this.intervalStopped = true;
    this.clickURL = null;
    this.trackURL = null;
    this.trackURL_external = 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 + '/htm/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 + '/htm/DayPortFlashBroker.swf?v=012306&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;

  // 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 + '/htm/DayPortFlashPlayer.swf?v=032106&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 + '/htm/DayPortFlashPlayer.swf?v=032106&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>' +
                  '<img id="' + id + '_extTrackImage" src="" width="1" height="1" border="0" style="position:static; left:0px; top:0px; visibility:hidden; display:none;" />' +
                  '<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 + '_extTrackImage\\").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>' +
                  '<img id="' + id + '_extTrackImage" src="" width="1" height="1" border="0" style="position:absolute; left:0px; top:0px; visibility:hidden; display:none;" />' +
                  '<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;

  var tmpAdState = this.adState;

  this.stopUpdateStatus();

  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);

  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 trackURL_external="+this.trackURL_external;
  if (this.trackURL_external != null)
  {
    // Track video via external tracking URL
    if (this.trackURL_external.toString().indexOf("?") == -1)
    {
      document.getElementById(this.videoID+"_extTrackImage").src = this.trackURL_external + "?rndm=" + DayPortVideo.genRandom();
    }
    else
    {
      document.getElementById(this.videoID+"_extTrackImage").src = this.trackURL_external + "&rndm=" + DayPortVideo.genRandom();
    }
    this.trackURL_external = 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 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;

      // 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(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)
    {
      // 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.trackURL, this.queuedVideoAdParameters.trackURL_external);

        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
                /*
                this.setSource("advertisement", adObj.contractItems[i].objID, adObj.contractID, adObj.contractItems[i].clickURL, adObj.contractItems[i].trackURL, adObj.contractItems[i].trackURL_external);

                if (this.adInsertionChangeInterval != null)
                {
                  // Track insertion of video advertisement
                  this.adInsertionCount_track();
                }
                */
                // Queue setting the source to the advertisement video
                this.queuedVideoAdParameters = {
                  objID:adObj.contractItems[i].objID,
                  contractID:adObj.contractID,
                  clickURL:adObj.contractItems[i].clickURL,
                  trackURL:adObj.contractItems[i].trackURL,
                  trackURL_external:adObj.contractItems[i].trackURL_external
                };
                //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;
                  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)
  {
    // 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.trackURL, this.queuedVideoAdParameters.trackURL_external);

      if (this.adInsertionChangeInterval != null)
      {
        // Track insertion of video advertisement
        this.adInsertionCount_track();
      }

      // Reset queuedVideoAdParameters property
      this.queuedVideoAdParameters = 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";

  // 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=DayPortVideo_articleMetadata.tpl&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=DayPortVideo_articleMetadata.tpl&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.domain + "/nw/article/view/" + this.articleID + "/?tf=DayPortVideo_articleMetadata.tpl&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.domain + "/nw/article/view/" + target.articleID + "/?tf=DayPortVideo_articleMetadata.tpl&mt=1";
    }, 10);
  }
};

// Callback for DayPortFLVVideo.retrieveMetadata method.
DayPortFLVVideo.prototype.retrieveMetadataCB = function(metadataObj)
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.retrieveMetadataCB() called.";

  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.name = metadataObj.name;
  this.metadata.previewImage = metadataObj.previewImage;

  /*
  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];
    }
  }
  */

  this.metadataState = "loaded";
  // Raise OnMetadataRetrieved event
  this.OnMetadataRetrieved();

  if ((this.adState != "loading") && (this.adState != "playing"))
  {
    // Set the source
    this.stop();

    this.clickURL = null;
    this.trackURL = null;
    this.trackURL_external = null;

    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)
{
  //document.getElementById("debugTA").value += "\nDayPortFLVVideo.setAd() called.";

  if (typeID == 4)
  {
    this.setSource("advertisement", objID, conID);
    return true;
  }

  if (adObj == null)
  {
    // Ad object not registered
    //document.getElementById("debugTA").value += "\n Ad object not registered.";
    return false;
  }

  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;

  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")
    {
      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 < 6)
      {
        //document.getElementById("debugTA").value += "\n Invalid number of arguments for source type of 'advertisement'. (arguments="+arguments+")";
        return false;
      }

      this.stop();

      if (arguments[3] != "")
      {
        this.clickURL = arguments[3];
      }
      else
      {
        this.clickURL = null;
      }
      //document.getElementById("debugTA").value += "\n clickURL="+this.clickURL;

      if (arguments[4] != "")
      {
        this.trackURL = arguments[4];
      }
      else
      {
        this.trackURL = null;
      }

      if (arguments[5] != "")
      {
        this.trackURL_external = arguments[5];
      }
      else
      {
        this.trackURL_external = null;
      }

      try
      {
        this.videoObject.SetVariable("videoCommand", "SetSource|advertisement,"+escape(arguments[1])+","+escape(arguments[2])+","+escape(this.clickURL));
      }
      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));
      }
      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;
      }

      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])
      {
        // Changing article
        this.articleID = arguments[1];

        // Retrieve article metadata before actually setting the source
        this.retrieveMetadata();

        // Raise OnTransitioning event
        this.OnTransitioning();

        return true;
      }

      this.clickURL = null;
      this.trackURL = null;
      this.trackURL_external = null;

      //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)
{
  //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.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.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["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)

  if(!this.requirementsCheck())
  {
    //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
  {
    this.mdRetrieverObject = null;
    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.interval = 500;
    this.intervalID = -1;
    this.intervalStopped = true;
    this.clickURL = null;
    this.trackURL = null;
    this.trackURL_external = 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;

  // 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.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)
{
  //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;

  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">' +
                  '<param name="FileName" VALUE="">' +
                  '<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="1">' +
                  '<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 src=""' +
                  '                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 + '_embed" 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>' +
                  '<img id="' + id + '_extTrackImage" src="" width="1" height="1" border="0" style="position:absolute; left:0px; top:0px; visibility:hidden; display:none;" />' +
                  '<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");

  return document.getElementById(id);
};

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.";

  //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.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 (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;

  var tmpAdState = this.adState;

  this.stopUpdateStatus();

  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+").";
        var tmpArtID = this.articleID;
        var target = this;
        setTimeout(function()
        {
          target.setSource("article", tmpArtID);
        }, 100);
      }
    }
  }

  // Dispatch event to registered listeners
  this.dispatchEvent("EndOfStream", tmpAdState);

  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 trackURL_external="+this.trackURL_external;
  if (this.trackURL_external != null)
  {
    // Track video via external tracking URL
    if (this.trackURL_external.toString().indexOf("?") == -1)
    {
      document.getElementById(this.videoID+"_extTrackImage").src = this.trackURL_external + "?rndm=" + DayPortVideo.genRandom();
    }
    else
    {
      document.getElementById(this.videoID+"_extTrackImage").src = this.trackURL_external + "&rndm=" + DayPortVideo.genRandom();
    }
    this.trackURL_external = null;
  }

  this.startUpdateStatus();

  // 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.";

  this.videoObject.Pause();
};

DayPortWMVVideo.prototype.play = function()
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.play() called.";

  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;

      // 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();
  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(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)
    {
      // 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.trackURL, this.queuedVideoAdParameters.trackURL_external);

        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
                /*
                this.setSource("advertisement", adObj.contractItems[i].objID, adObj.contractID, adObj.contractItems[i].clickURL, adObj.contractItems[i].trackURL, adObj.contractItems[i].trackURL_external);

                if (this.adInsertionChangeInterval != null)
                {
                  // Track insertion of video advertisement
                  this.adInsertionCount_track();
                }
                */
                // Queue setting the source to the advertisement video
                this.queuedVideoAdParameters = {
                  objID:adObj.contractItems[i].objID,
                  contractID:adObj.contractID,
                  clickURL:adObj.contractItems[i].clickURL,
                  trackURL:adObj.contractItems[i].trackURL,
                  trackURL_external:adObj.contractItems[i].trackURL_external
                };
                //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;
                  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)
  {
    // 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.trackURL, this.queuedVideoAdParameters.trackURL_external);

      if (this.adInsertionChangeInterval != null)
      {
        // Track insertion of video advertisement
        this.adInsertionCount_track();
      }

      // Reset queuedVideoAdParameters property
      this.queuedVideoAdParameters = null;
    }
  }
};

DayPortWMVVideo.prototype.requirementsCheck = function()
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.requirementsCheck() called.";

  // Check OS
  switch (DayPortVideo.system.osPlatform)
  {
    case "Windows":
      // Supported OS for this format.
      // Check browser
      switch (DayPortVideo.system.browser)
      {
        case "Internet Explorer":
          // Supported browser for this format.
          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.
            return false;
          }
          break;

        case "Firefox":
        case "Mozilla":
        case "Opera":
        case "Konqueror":
        case "Safari":
        case "AOL":
        default:
          // Unsupported browser for this format.
          return false;
      }
      break;

    case "Mac":
    default:
      // Unsupported OS for this format.
      return false;
  }

  // Check for installation and version of Windows Media Player

  return true;
};

// Retrieve metadata for an article.
DayPortWMVVideo.prototype.retrieveMetadata = function()
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.retrieveMetadata() called.";

  this.metadataState = "loading";

  // 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=DayPortVideo_articleMetadata.tpl&mt=1";

  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.domain + "/nw/article/view/" + target.articleID + "/?tf=DayPortVideo_articleMetadata.tpl&mt=1";
  }, 10);
};

// Callback for DayPortWMVVideo.retrieveMetadata method.
DayPortWMVVideo.prototype.retrieveMetadataCB = function(metadataObj)
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.retrieveMetadataCB() called.";

  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.name = metadataObj.name;
  this.metadata.previewImage = metadataObj.previewImage;

  /*
  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];
    }
  }
  */

  this.metadataState = "loaded";
  // Raise OnMetadataRetrieved event
  this.OnMetadataRetrieved();

  if ((this.adState != "loading") && (this.adState != "playing"))
  {
    // Set the source
    this.stop();

    this.clickURL = null;
    this.trackURL = null;
    this.trackURL_external = null;

    this.videoObject.Open("http://" + this.domain + "/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();
  }
};

DayPortWMVVideo.prototype.seek = function(seconds)
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.seek() called.";

  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)
{
  //document.getElementById("debugTA").value += "\nDayPortWMVVideo.setAd() called.";

  if (typeID == 4)
  {
    this.setSource("advertisement", objID, conID);
    return true;
  }

  if (adObj == null)
  {
    // Ad object not registered
    //document.getElementById("debugTA").value += "\n Ad object not registered.";
    return false;
  }

  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;

  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")
    {
      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 ((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 < 6)
      {
        //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 tracking URL
      if (arguments[4] != "")
      {
        this.trackURL = arguments[4];
      }
      else
      {
        this.trackURL = null;
      }

      // Handle external tracking URL
      if (arguments[5] != "")
      {
        this.trackURL_external = arguments[5];
      }
      else
      {
        this.trackURL_external = null;
      }

      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]);
      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;
      }

      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])
      {
        // Changing article
        this.articleID = arguments[1];

        // Retrieve article metadata before actually setting the source
        this.retrieveMetadata();

        // Raise OnTransitioning event
        this.OnTransitioning();

        return true;
      }

      this.clickURL = null;
      this.trackURL = null;
      this.trackURL_external = null;

      //document.getElementById("debugTA").value += "\n Playing article ID of "+arguments[1]+".";
      this.videoObject.Open("http://" + this.domain + "/viewer/content/special.php?Art_ID=" + arguments[1] + "&Format_ID=2&BitRate_ID=8&Contract_ID=&Obj_ID=&NoAds=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 ((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 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.";

  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.";

  // 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 ********************/