/******************** AutoPlayArticles Class ********************/
var AutoPlayArticles = new Object();

AutoPlayArticles.articles = new Array();
AutoPlayArticles.articlesPointer = null;
AutoPlayArticles.id = null;
AutoPlayArticles.limit = null;
AutoPlayArticles.offset = null;
AutoPlayArticles.retrieverObject = null;
AutoPlayArticles.status = "initializing";  // Possible values: "initializing", "loading", "loaded"

AutoPlayArticles.changeCategory = function(id)
{
  //document.getElementById("debugTA").value += "\nAutoPlayArticles.changeCategory() called.";
  //document.getElementById("debugTA").value += "\n id="+id;

  AutoPlayArticles.id = id;

  AutoPlayArticles.retrieveData();
};

AutoPlayArticles.dataRetrieved = function()
{
  //document.getElementById("debugTA").value += "\nAutoPlayArticles.dataRetrieved() called.";

  if (AutoPlayArticles.articles.length > 0)
  {
    AutoPlayArticles.articlesPointer = 0;
  }

  AutoPlayArticles.status = "loaded";

  if (pageLoaded && (typeof dpVidObj != "undefined") && (dpVidObj.video.articleID == null) && (AutoPlayArticles.articles.length > 0))
  {
    //document.getElementById("debugTA").value += "\n Auto-playing article ID of "+AutoPlayArticles.articles[0]+".";
    // Play selected article
    dpVidObj.video.setSource("article", AutoPlayArticles.articles[0]);
  }
};

AutoPlayArticles.resetData = function()
{
  //document.getElementById("debugTA").value += "\nAutoPlayArticles.resetData() called.";

  AutoPlayArticles.articles.length = 0;
  AutoPlayArticles.articlesPointer = null;
};

AutoPlayArticles.retrieveData = function()
{
  //document.getElementById("debugTA").value += "\nAutoPlayArticles.retrieveData() called.";

  AutoPlayArticles.status = "loading";
  AutoPlayArticles.retrieverObject.innerHTML = "";
  //AutoPlayArticles.resetData();

  if ((navigator.userAgent.toLowerCase().indexOf("mac") != -1) && (navigator.appVersion.toLowerCase().indexOf("msie") != -1))
  {
    // IE on Mac
    setTimeout("AutoPlayArticles.retrieverObject.innerHTML = '_<scr' + 'ipt id=\"autoPlayArticles_retrieverJS\" language=\"JavaScript\" type=\"text/javascript\" src=\"http://www.olntv.com/nw/article/archive/" + AutoPlayArticles.id + "/?tf=broadband_player_autoPlayArticles.tpl&Limit=" + AutoPlayArticles.limit + "&Offset=" + AutoPlayArticles.offset + "&UserDef=true&mt=1\" defer></scr' + 'ipt>';", 100);
  }
  else if ((navigator.userAgent.toLowerCase().indexOf("mac") != -1) && (navigator.userAgent.toLowerCase().indexOf("safari") != -1))
  {
    // Safari on Mac
    var scrObj = document.createElement("script");
    scrObj.id = "autoPlayArticles_retrieverJS";
    scrObj.defer = true;
    scrObj.src = "http://www.olntv.com/nw/article/archive/" + AutoPlayArticles.id + "/?tf=broadband_player_autoPlayArticles.tpl&Limit=" + AutoPlayArticles.limit + "&Offset=" + AutoPlayArticles.offset + "&UserDef=true&mt=1";
    AutoPlayArticles.retrieverObject.appendChild(scrObj);
  }
  else
  {
    AutoPlayArticles.retrieverObject.innerHTML = '_<scr' + 'ipt id="autoPlayArticles_retrieverJS" language="JavaScript" type="text/javascript" defer></scr' + 'ipt>';
    setTimeout(function()
    {
      document.getElementById("autoPlayArticles_retrieverJS").src = "http://www.olntv.com/nw/article/archive/" + AutoPlayArticles.id + "/?tf=broadband_player_autoPlayArticles.tpl&Limit=" + AutoPlayArticles.limit + "&Offset=" + AutoPlayArticles.offset + "&UserDef=true&mt=1";
    }, 10);
  }
};

AutoPlayArticles.setObject = function(id, limit, offset, retrieverObj)
{
  //document.getElementById("debugTA").value += "\nAutoPlayArticles.setObject() called.";

  AutoPlayArticles.id = id;
  AutoPlayArticles.limit = limit;
  AutoPlayArticles.offset = offset;
  AutoPlayArticles.retrieverObject = retrieverObj;

  if (AutoPlayArticles.status == "initializing")
  {
    AutoPlayArticles.retrieveData();
  }
};

AutoPlayArticles.toString = function()
{
  //document.getElementById("debugTA").value += "\nAutoPlayArticles.toString() called.";

  return "[object AutoPlayArticles]";
};
/******************** End of AutoPlayArticles Class ********************/