var currentArticle = "";
var currentPreviewImage = "";
var initialArticles = new Array();  // Contains any article ID's passed in from the URL
var initialCategory = null;  // Contains a category ID if one was passed in from the URL
var playerSize = "small";
var _nrtrackingcode="";
var NRcall="";
var nrplayertype = "bbp";

function _nnrstreaming(_scmedia,_sccontainer,_sctitle,_scdestination,_scplayertype)
{
	
	var ScRandom = Math.ceil(Math.random()*1000000000);

	_nrtrackingcode = 'http://server-us.imrworldwide.com/cgi-bin/m?ci=us-versus';
        _nrtrackingcode += '&cg=' + _scplayertype;  //bbp - broadbandplayer  , pbr - bulls and rodedo player, nhl-hockey player;
	//_nrtrackingcode += '&cg=' + _scmedia;
	//_nrtrackingcode += '&si=' + escape(_sccontainer);  At this point the url is non-specific and will be identified by Nielsen;
	_nrtrackingcode += '&tl=dav0-' + escape(_sctitle); 
	_nrtrackingcode += '&cc=1&rnd='+ ScRandom;
	//NRcall = document.createElement('img');
	//NRcall.setAttribute('src',_nrtrackingcode);
	NRcall = new Image();
	NRcall.src = _nrtrackingcode;
	//alert(_nrtrackingcode);
}

function convertFromSec(timeSeconds, maxStrLength, dropHours)
{
  //document.getElementById("debugTA").value += "\nconvertFromSec() called.";
  //document.getElementById("debugTA").value += "\n timeSeconds="+timeSeconds;

  timeSeconds = parseInt(timeSeconds, 10);
  if (isNaN(timeSeconds))
  {
    timeSeconds = 0;
  }

  maxStrLength = parseInt(maxStrLength, 10);
  switch (maxStrLength)
  {
    case 8:
    case 10:
    case 11:
    case 12:
      // Valid maxStrLength parameter
      break;

    default:
      // Invalid maxStrLength parameter so set to default value
      maxStrLength = 12;
  }

  var tsHours = "00";
  var tsMinutes = "00";
  var tsSeconds = "00";
  var tsMilliSeconds;

  if (timeSeconds > 59)
  {
    tsMinutes = timeSeconds / 60;
    tsMinutes = tsMinutes.toString();
    if (tsMinutes.indexOf(".") != -1)
    {
      tsMinutes = Math.floor(tsMinutes);
      //tsSeconds = timeSeconds - (tsMinutes * 60);
      var tmpSecArr = timeSeconds.toString().split(".");
      tsSeconds = tmpSecArr[0] - (tsMinutes * 60);
      if (tmpSecArr.length == 2)
      {
        tsSeconds = zeroPad(tsSeconds) + "." + tmpSecArr[1];
      }
    }

    if (tsMinutes > 59)
    {
      tsHours = tsMinutes / 60;
      tsHours = tsHours.toString();
      if (tsHours.indexOf(".") != -1)
      {
        tsHours = Math.floor(tsHours);
        tsMinutes -= (tsHours * 60);
      }
      else
      {
        tsMinutes = "00";
      }
    }
  }
  else
  {
    tsSeconds = timeSeconds;
  }


  //document.getElementById("debugTA").value += "\n tsSeconds="+tsSeconds;
  var tsSecArr = tsSeconds.toString().split(".");
  tsSeconds = tsSecArr[0];
  if (tsSecArr.length == 2)
  {
    tsMilliSeconds = tsSecArr[1];
    if (tsMilliSeconds.length > 3)
    {
      tsMilliSeconds = tsMilliSeconds.slice(0, 3);
    }
    else
    {
      while (tsMilliSeconds.length < 3)
      {
        tsMilliSeconds += "0";
      }
    }
  }
  else
  {
    tsMilliSeconds = "000";
  }

  var timeStr = zeroPad(tsHours) + ":" + zeroPad(tsMinutes) + ":" + zeroPad(tsSeconds) + "." + tsMilliSeconds;
  //document.getElementById("debugTA").value += "\n timeStr="+timeStr;

  var startIndex = 0;
  if (dropHours && (timeStr.slice(0, 3) == "00:"))
  {
    startIndex = 3;
  }

  return timeStr.slice(startIndex, maxStrLength);
}

function getURLVar(varName)
{
  //document.getElementById("debugTA").value += "\ngetURLVar() called.";

  // Strip off the URL parameters
  var url_params = window.location.search.substr(1);

  var retn = "";
  if (url_params != "")
  {
    var url_param_array = url_params.split("&");
    var url_param_count = url_param_array.length;
    var temp;

    for (var count = 0; count < url_param_count; count++)
    {
      temp = url_param_array[count].split("=");
      if (temp[0] == varName)
        retn = temp[1];
    }
  }

  return retn;
}

var pageLoaded = false;
function OnLoadList()
{
  //document.getElementById("debugTA").value += "\nOnLoadList() called.";

  pageLoaded = true;

  var currentArticle = null;

  // Check for content to load
  //document.getElementById("debugTA").value += "\n initialArticles.articles.length="+ initialArticles.articles.length+", AutoPlayArticles.articles.length="+AutoPlayArticles.articles.length;
  if (initialArticles.length > 0)
  {
    currentArticle = initialArticles.shift();
  }
  else if (AutoPlayArticles.articles.length > 0)
  {
    currentArticle = AutoPlayArticles.articles[0];
  }
  
  //document.getElementById("debugTA").value += "\n currentArticle="+currentArticle;
  if (currentArticle != null)
  {
    //document.getElementById("debugTA").value += "\n Auto-playing article ID of "+currentArticle+".";
    if (typeof articleListObj.artIDArr["ID_"+currentArticle] != "undefined")
    {
      articleListObj.jump(articleListObj.artIDArr["ID_"+currentArticle], false);
    }
    else
    {
      // Play selected article
      dpVidObj.video.setSource("article", currentArticle);
    }
  }
}
// Register for window.onload event
DayPortVideo.registerEventListener(window, "load", window.OnLoadList);

function player_activateInitialCategory(catID)
{
  //document.getElementById("debugTA").value += "\nplayer_activateInitialCategory() called.";
  //document.getElementById("debugTA").value += "\n catID="+catID;

  // Activate current category image
  var active_imageSrc_mouseout = "";
  var active_imageSrc_mouseover = "";

  switch (catID)
  {
    case 458:
      // This Month On OLN
      active_imageSrc_mouseout = "http://versusimg.cdn.dayport.com/img/player/thismonth_o.gif";
      active_imageSrc_mouseover = "http://versusimg.cdn.dayport.com/img/player/thismonth_o.gif";
      break;

    case 457:
      // NHL
      active_imageSrc_mouseout = "http://versusimg.cdn.dayport.com/img/player/nhl_o.gif";
      active_imageSrc_mouseover = "http://versusimg.cdn.dayport.com/img/player/nhl_o.gif";
      break;

    case 566:
      // TDF
      active_imageSrc_mouseout = "http://versusimg.cdn.dayport.com/img/player/tdf_o.gif";
      active_imageSrc_mouseover = "http://versusimg.cdn.dayport.com/img/player/tdf_o.gif";
      break;

    case 456:
      // Action Sports
      active_imageSrc_mouseout = "http://versusimg.cdn.dayport.com/img/player/sports_o.gif";
      active_imageSrc_mouseover = "http://versusimg.cdn.dayport.com/img/player/sports_o.gif";
      break;

    case 455:
      // Field Sports
      active_imageSrc_mouseout = "http://versusimg.cdn.dayport.com/img/player/hunting_o.gif";
      active_imageSrc_mouseover = "http://versusimg.cdn.dayport.com/img/player/hunting_o.gif";
      break;

    case 454:
      // Bulls & Rodeo
      active_imageSrc_mouseout = "http://versusimg.cdn.dayport.com/img/player/bulls_o.gif";
      active_imageSrc_mouseover = "http://versusimg.cdn.dayport.com/img/player/bulls_o.gif";
      break;

    case 453:
      // OLN Series
      active_imageSrc_mouseout = "http://versusimg.cdn.dayport.com/img/player/series_o.gif";
      active_imageSrc_mouseover = "http://versusimg.cdn.dayport.com/img/player/series_o.gif";
      break;
  }
  //document.getElementById("debugTA").value += "\n active_imageSrc_mouseout="+active_imageSrc_mouseout+", active_imageSrc_mouseover="+active_imageSrc_mouseover;

  // Activate category image
  var active_cat_imageObj = document.getElementById("category_"+catID+"_image");
  active_cat_imageObj.src = active_imageSrc_mouseout;
  var active_cat_linkObj = document.getElementById("category_"+catID+"_link");
  active_cat_linkObj.onmouseover = function()
  {
    active_cat_imageObj.src = active_imageSrc_mouseover;
  };
  active_cat_linkObj.onmouseout = function()
  {
    active_cat_imageObj.src = active_imageSrc_mouseout;
  };
}

function player_articleSearch_submit()
{
  //document.getElementById("debugTA").value += "\nplayer_articleSearch_submit() called.";

  var searchText = document.getElementById("articleSearch_form").SearchText.value;
  if (searchText == "")
  {
    alert("The search text cannot be blank.");
    return false;
  }

  // Hide articleListPane
  document.getElementById("articleListPane").style.visibility = "hidden";
  document.getElementById("articleListPane").style.display = "none";

  // Show articleSearchPane
  document.getElementById("articleSearchPane").style.visibility = "visible";
  document.getElementById("articleSearchPane").style.display = "block";

  articleSearchObj.searchText = searchText;
  articleSearchObj.retrieveData(0);
}

function player_changeCategory(catID)
{
  //document.getElementById("debugTA").value += "\nplayer_changeCategory() called.";
  //document.getElementById("debugTA").value += "\n catID="+catID;
  // Update category images
  //document.getElementById("debugTA").value += "\n articleListObj.id="+articleListObj.id;
  if (articleListObj.id != -1)
  {
    // Deactivate previously active category image
    var unactive_imageSrc_mouseout = "";
    var unactive_imageSrc_mouseover = "";

    switch (articleListObj.id)
    {
      case 458:
        // This Month On OLN
        unactive_imageSrc_mouseout = "http://versusimg.cdn.dayport.com/img/player/thismonth_w.gif";
        unactive_imageSrc_mouseover = "http://versusimg.cdn.dayport.com/img/player/thismonth_o.gif";
        break;

      case 457:
        // NHL
        unactive_imageSrc_mouseout = "http://versusimg.cdn.dayport.com/img/player/nhl_w.gif";
        unactive_imageSrc_mouseover = "http://versusimg.cdn.dayport.com/img/player/nhl_o.gif";
        break;

      case 566:
        // TDF
        unactive_imageSrc_mouseout = "http://versusimg.cdn.dayport.com/img/player/tdf_w.gif";
        unactive_imageSrc_mouseover = "http://versusimg.cdn.dayport.com/img/player/tdf_o.gif";
        break;

      case 456:
        // Action Sports
        unactive_imageSrc_mouseout = "http://versusimg.cdn.dayport.com/img/player/sports_w.gif";
        unactive_imageSrc_mouseover = "http://versusimg.cdn.dayport.com/img/player/sports_o.gif";
        break;

      case 455:
        // Field Sports
        unactive_imageSrc_mouseout = "http://versusimg.cdn.dayport.com/img/player/hunting_w.gif";
        unactive_imageSrc_mouseover = "http://versusimg.cdn.dayport.com/img/player/hunting_o.gif";
        break;

      case 454:
        // Bulls & Rodeo
        unactive_imageSrc_mouseout = "http://versusimg.cdn.dayport.com/img/player/bulls_w.gif";
        unactive_imageSrc_mouseover = "http://versusimg.cdn.dayport.com/img/player/bulls_o.gif";
        break;

      case 453:
        // OLN Series
        unactive_imageSrc_mouseout = "http://versusimg.cdn.dayport.com/img/player/series_w.gif";
        unactive_imageSrc_mouseover = "http://versusimg.cdn.dayport.com/img/player/series_o.gif";
        break;
    }
    //document.getElementById("debugTA").value += "\n unactive_imageSrc_mouseout="+unactive_imageSrc_mouseout+", unactive_imageSrc_mouseover="+unactive_imageSrc_mouseover;

    // Deactivate category image
    var unactive_cat_imageObj = document.getElementById("category_"+articleListObj.id+"_image");
    unactive_cat_imageObj.src = unactive_imageSrc_mouseout;
    var unactive_cat_linkObj = document.getElementById("category_"+articleListObj.id+"_link");
    unactive_cat_linkObj.onmouseover = function()
    {
      unactive_cat_imageObj.src = unactive_imageSrc_mouseover;
    };
    unactive_cat_linkObj.onmouseout = function()
    {
      unactive_cat_imageObj.src = unactive_imageSrc_mouseout;
    };
  }

  // Activate current category image
  var active_imageSrc_mouseout = "";
  var active_imageSrc_mouseover = "";

  switch (catID)
  {
    case 458:
      // This Month On OLN
      active_imageSrc_mouseout = "http://versusimg.cdn.dayport.com/img/player/thismonth_o.gif";
      active_imageSrc_mouseover = "http://versusimg.cdn.dayport.com/img/player/thismonth_o.gif";
      break;

    case 457:
      // NHL
      active_imageSrc_mouseout = "http://versusimg.cdn.dayport.com/img/player/nhl_o.gif";
      active_imageSrc_mouseover = "http://versusimg.cdn.dayport.com/img/player/nhl_o.gif";
      break;

    case 566:
      // TDF
      active_imageSrc_mouseout = "http://versusimg.cdn.dayport.com/img/player/tdf_o.gif";
      active_imageSrc_mouseover = "http://versusimg.cdn.dayport.com/img/player/tdf_o.gif";
      break;

    case 456:
      // Action Sports
      active_imageSrc_mouseout = "http://versusimg.cdn.dayport.com/img/player/sports_o.gif";
      active_imageSrc_mouseover = "http://versusimg.cdn.dayport.com/img/player/sports_o.gif";
      break;

    case 455:
      // Field Sports
      active_imageSrc_mouseout = "http://versusimg.cdn.dayport.com/img/player/hunting_o.gif";
      active_imageSrc_mouseover = "http://versusimg.cdn.dayport.com/img/player/hunting_o.gif";
      break;

    case 454:
      // Bulls & Rodeo
      active_imageSrc_mouseout = "http://versusimg.cdn.dayport.com/img/player/bulls_o.gif";
      active_imageSrc_mouseover = "http://versusimg.cdn.dayport.com/img/player/bulls_o.gif";
      break;

    case 453:
      // OLN Series
      active_imageSrc_mouseout = "http://versusimg.cdn.dayport.com/img/player/series_o.gif";
      active_imageSrc_mouseover = "http://versusimg.cdn.dayport.com/img/player/series_o.gif";
      break;
  }
  //document.getElementById("debugTA").value += "\n active_imageSrc_mouseout="+active_imageSrc_mouseout+", active_imageSrc_mouseover="+active_imageSrc_mouseover;

  // Activate category image
  var active_cat_imageObj = document.getElementById("category_"+catID+"_image");
  active_cat_imageObj.src = active_imageSrc_mouseout;
  var active_cat_linkObj = document.getElementById("category_"+catID+"_link");
  active_cat_linkObj.onmouseover = function()
  {
    active_cat_imageObj.src = active_imageSrc_mouseover;
  };
  active_cat_linkObj.onmouseout = function()
  {
    active_cat_imageObj.src = active_imageSrc_mouseout;
  };

  // Hide articleSearchPane
  document.getElementById("articleSearchPane").style.visibility = "hidden";
  document.getElementById("articleSearchPane").style.display = "none";

  // Show articleListPane
  document.getElementById("articleListPane").style.visibility = "visible";
  document.getElementById("articleListPane").style.display = "block";

  var previousCategoryID = articleListObj.id;
  // Change category for ArticleList class object
  articleListObj.changeCategory(catID);

  // Retrieve playlist of articles to autoplay from current category
  AutoPlayArticles.changeCategory(catID);

  // See if category has changed
  //document.getElementById("debugTA").value += "\n previousCategoryID="+previousCategoryID;
  if (catID != previousCategoryID)
  {
    // Change ad settings for DayPortVideo class object
    if (typeof player_categoryAdSettings["CATEGORYID_"+catID] != "undefined")
    {
      var categoryAdSettingsObj = player_categoryAdSettings["CATEGORYID_"+catID];
    }
    else
    {
      var categoryAdSettingsObj = player_categoryAdSettings["CATEGORYID_"+player_defaultCategory];
    }

    // Set ad package settings
    dpVidObj.video.setAdPackages(categoryAdSettingsObj.adPackageArray, [{containerObject:document.getElementById("ad1"), width:728, height:90, conDefID:categoryAdSettingsObj.bannerAd.conDefID, objectID:categoryAdSettingsObj.bannerAd.objectID}]);
    // Set ad insertion settings
    dpVidObj.video.setAdInsertionFrequency(categoryAdSettingsObj.adInsertionFrequency);
    // Queue an advertisement for insertion
    dpVidObj.video.queueAd(true);
  }
}

function player_changeSize(sizeStr)
{
  //document.getElementById("debugTA").value += "\nplayer_changeSize() called.";
  //document.getElementById("debugTA").value += "\n sizeStr="+sizeStr;

  var searchInputObj = document.getElementById("search");
  var logosPanelObj = document.getElementById("headerLogos");
  var imgViewObj = document.getElementById("imgView");

  var imgLogoSmallObj = document.getElementById("imgLogoSmall");
  var imgThePlayerSmallObj = document.getElementById("imgThePlayerSmall");
  var imgLogoLargeObj = document.getElementById("imgLogoLarge");
  var imgThePlayerLargeObj = document.getElementById("imgThePlayerLarge");

  var videoPanelObj = document.getElementById("videoPanel");
  var videoAreaObj = document.getElementById("videoArea");
  var videoPreviewImageObj = document.getElementById("videoPreviewImage");
  var videoPreviewImage_imageObj = document.getElementById("videoPreviewImage_image");
  var preLoadAdObj = document.getElementById("preLoadAd");
  var bufferAdObj = document.getElementById("bufferAd");
  var controlsAreaObj = document.getElementById("controlsArea");
  var playerChangeObj = document.getElementById("playerChange");
  var adTileObj = document.getElementById("adTile");
  
  var sidePanelObj = document.getElementById("sidePanel");

  switch (sizeStr)
  {
    case "large":
      playerSize = "large";

      // Hide the Search Input
      searchInputObj.style.visibility = "hidden";
      searchInputObj.style.display = "none";

      // Hide the Header logos for NHL, Field Sports, ... Panel
      logosPanelObj.style.visibility = "hidden";
      logosPanelObj.style.display = "none";

      // Hide Side Panel
      sidePanelObj.style.visibility = "hidden";
      sidePanelObj.style.display = "none";

      // Position Video Panel
      videoPanelObj.style.top = "77px";
      videoPanelObj.style.left = "156px";
      videoPanelObj.style.width = "596px";
      videoPanelObj.style.height = "484px";  //474px;
      videoPanelObj.style.background = "#000 url(/images/player/large_gradient.gif) repeat-y"; 

      // Resize video and controls
      videoAreaObj.style.width = "576px";
      videoAreaObj.style.height = "432px";
      videoAreaObj.style.clip = "rect(0,576,432,0)";
      dpVidObj.video.setSize(576, 432);

      videoPreviewImageObj.style.width = "576px";
      videoPreviewImageObj.style.height = "432px";
      videoPreviewImageObj.style.top = "-432px";
      preLoadAdObj.style.width = "576px";
      preLoadAdObj.style.height = "432px";
      preLoadAdObj.style.top = "-864px";
      bufferAdObj.style.width = "576px";
      bufferAdObj.style.height = "432px";
      bufferAdObj.style.top = "-1296px";

      if (currentPreviewImage != "")
      {
        videoPreviewImage_imageObj.width = "576";
        videoPreviewImage_imageObj.height = "432";
      }

      controlsAreaObj.style.top = "442px";
      controlsAreaObj.style.width = "576px";
      
      //Hide the View Small Logo and Player images;
      imgLogoSmallObj.style.visibility = "hidden";
      imgLogoSmallObj.style.display = "none";
      imgLogoLargeObj.style.visibility = "hidden";
      imgLogoLargeObj.style.display = "none";
      imgThePlayerSmallObj.style.visibility = "hidden";
      imgThePlayerSmallObj.style.display = "none";
      imgThePlayerLargeObj.style.visibility = "visible";
      imgThePlayerLargeObj.style.display = "block";
      //imgVideoGalleryObj.style.top = "19px";
      adTileObj.style.top = "496px"; //Move down 6 to add in the title name;
       
      // Update view image and link in the controls
      imgViewObj.src = "http://versusimg.cdn.dayport.com/img/player/viewsmaller.png";
      imgViewObj.width = 87;
      player_filterImage(imgViewObj);
      playerChangeObj.onclick = function()
      {
        player_changeSize("small");
        return false;
      };
      playerChangeObj.title = "View Smaller";
      break;

    case "small":
      playerSize = "small";

      // Position Video Panel
      videoPanelObj.style.top = "126px";
      videoPanelObj.style.left = "23px";
      videoPanelObj.style.width = "500px";
      videoPanelObj.style.height = "422px";

      // Resize video and controls
      videoAreaObj.style.width = "480px";
      videoAreaObj.style.height = "360px";
      videoAreaObj.style.clip = "rect(0,480,360,0)";
      dpVidObj.video.setSize(480, 360);

      videoPreviewImageObj.style.width = "480px";
      videoPreviewImageObj.style.height = "360px";
      videoPreviewImageObj.style.top = "-360px";
      preLoadAdObj.style.width = "480px";
      preLoadAdObj.style.height = "360px";
      preLoadAdObj.style.top = "-720px";
      bufferAdObj.style.width = "480px";
      bufferAdObj.style.height = "360px";
      bufferAdObj.style.top = "-1080px";

      if (currentPreviewImage != "")
      {
        videoPreviewImage_imageObj.width = "480";
        videoPreviewImage_imageObj.height = "360";
      }

      controlsAreaObj.style.top = "370px";
      controlsAreaObj.style.width = "480px";

      //Hide the View Small Logo and Player images;
      imgLogoSmallObj.style.visibility = "hidden";
      imgLogoSmallObj.style.display = "none";
      imgLogoLargeObj.style.visibility = "hidden";
      imgLogoLargeObj.style.display = "none";
      imgThePlayerSmallObj.style.visibility = "visible";
      imgThePlayerSmallObj.style.display = "block";
      imgThePlayerLargeObj.style.visibility = "hidden";
      imgThePlayerLargeObj.style.display = "none";
      //imgVideoGalleryObj.style.top = "102px";
      adTileObj.style.top = "488px"; 

      // Update view image and link in the controls
      imgViewObj.src = "http://versusimg.cdn.dayport.com/img/player/viewlarger.png";
      imgViewObj.width = 79;
      player_filterImage(imgViewObj);
	  playerChangeObj.onclick = function()
      {
        player_changeSize("large");
        return false;
      };
      playerChangeObj.title = "View Larger";

      // Show the Search Input
      searchInputObj.style.visibility = "visible";
      searchInputObj.style.display = "block";

      // Show the Header logos for NHL, Field Sports, ... Panel
      logosPanelObj.style.visibility = "visible";
      logosPanelObj.style.display = "block";

      // Show Side Panel
      sidePanelObj.style.visibility = "visible";
      sidePanelObj.style.display = "block";
      //sidePanelObj.style.background = "#000 url(/images/player/esurance-erin.jpg) no-repeat";
      break;

    default:
      return false;
  }

  return true;
}

function player_email(artID)
{
  //document.getElementById("debugTA").value += "\nplayer_email() called.";
  //document.getElementById("debugTA").value += "\n artID="+artID;

  //document.getElementById("debugTA").value += "\n articleListObj.id="+articleListObj.id;
  var articleEmailPaneObj = document.getElementById("articleEmailPane");
  var videoEmailObj = document.getElementById("videoEmail");

  // Set videoEmail contents to e-mail form
  videoEmailObj.innerHTML = '<iframe id="" src="http://www.olntv.com/broadband_player_email_form/?artID=' + artID + '&catID=' + articleListObj.id + '&playerID=1" onload="" style="width:379px; height:289px;" frameborder="0" scrolling="no" marginwidth="0" marginheight="0" align="left" hspace="0" vspace="0"><p>Iframes not supported.</p></iframe>';

  // Show articleEmailPane
  articleEmailPaneObj.style.visibility = "visible";
  articleEmailPaneObj.style.display = "block";
}

function player_email_close()
{
  //document.getElementById("debugTA").value += "\nplayer_email_close() called.";

  var articleEmailPaneObj = document.getElementById("articleEmailPane");
  var videoEmailObj = document.getElementById("videoEmail");

  // Hide articleEmailPane
  articleEmailPaneObj.style.visibility = "hidden";
  articleEmailPaneObj.style.display = "none";

  // Clear videoEmail contents
  videoEmailObj.innerHTML = "";
}

var spacerImage = "http://versusimg.cdn.dayport.com/images/spacer.gif";
var htcCapable = /MSIE ((5\.5)|[6])/.test(navigator.userAgent) && navigator.platform == "Win32";
function player_filterImage(imgObj)
{
  //document.getElementById("debugTA").value += "\nplayer_filterImage() called.";
  //document.getElementById("debugTA").value += "\n imgObj="+imgObj;

  var orignalImage = imgObj.src;
  imgObj.style.visibility = "hidden";
  if (/\.png$/.test(orignalImage))
  {
    if (htcCapable)
    {
      imgObj.src = spacerImage;
      imgObj.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=" + orignalImage + ",sizingMethod='scale')";
    }
  }
  imgObj.style.visibility = "visible";
}

function player_hidePreviewImage()
{
  //document.getElementById("debugTA").value += "\nplayer_hidePreviewImage() called.";

  dpVidObj.video.videoObject.style.visibility = "visible";
  document.getElementById("videoPreviewImage").style.visibility = "hidden";

  return true;
}

var displayFSmsg = true;
function player_listener_BeforeFullScreen()
{
  //document.getElementById("debugTA").value += "\nplayer_listener_BeforeFullScreen() called.";

  if (displayFSmsg)
  {
    alert("Press the 'Esc' key to exit Full-Screen mode.");
    displayFSmsg = false;
  }
}

function player_listener_Buffering(buffStart)
{
  //document.getElementById("debugTA").value += "\nplayer_listener_Buffering() called.";
  //document.getElementById("debugTA").value += "\n buffStart="+buffStart;

  if (buffStart)
  {
    //document.getElementById("statusMessage").innerHTML = "Buffering...";
    //player_showVideoStateAd("buffer");

  }
  else
  {
    //document.getElementById("statusMessage").innerHTML = "Playing...";
    player_hideVideoStateAds();

  }
}

function player_listener_DurationUpdated(duration)
{
  //document.getElementById("debugTA").value += "\nplayer_listener_DurationUpdated() called.";
  //document.getElementById("debugTA").value += "\n duration="+duration;

  document.getElementById("videoDuration").innerHTML = convertFromSec(duration, 8, true);
  
  var videoFormat = "wmp";
  var videoName = unescape(dpVidObj.video.metadata.name);
  if ((dpVidObj.video.adState == "loading") || (dpVidObj.video.adState == "playing"))
  {
  	videoName = dpVidObj.video.currentVideoAdParameters.contractID;
  }
  
  if(dpVidObj.video.format != "WMV")
  {
  	videoFormat = "flash";
  }
  
  _nnrstreaming(videoFormat,'http://www.netratings.com/index.html',videoName,'',nrplayertype);

}

function player_listener_EndOfAd()
{
  //document.getElementById("debugTA").value += "\nplayer_listener_EndOfAd() called.";
  document.getElementById("videoCaption").innerHTML = unescape(dpVidObj.video.metadata.name);
}

function player_listener_EndOfStream(adState)
{
  //document.getElementById("debugTA").value += "\nplayer_listener_EndOfStream() called.";
  //document.getElementById("debugTA").value += "\n adState="+adState;

  //document.getElementById("statusMessage").innerHTML = "Stopped";
  //player_showVideoStateAd("postview");
  player_showPreviewImage();

  // See if should play an article from AutoPlayArticles.articles list
  if ((adState != "loading") && (adState != "playing") && ((initialArticles.length > 0) || (AutoPlayArticles.articles.length > 0)))
  {
    if (initialArticles.length > 0)
    {
      var currentArticle = initialArticles.shift();
    }
    else
    {
      // See if AutoPlayArticles.articles pointer should be moved
      if (AutoPlayArticles.articles[AutoPlayArticles.articlesPointer] == dpVidObj.video.articleID)
      {
        if (AutoPlayArticles.articlesPointer >= (AutoPlayArticles.articles.length - 1))
        {
          // Reset AutoPlayArticles.articles pointer
          AutoPlayArticles.articlesPointer = 0;
        }
        else
        {
          // Increment AutoPlayArticles.articles pointer
          AutoPlayArticles.articlesPointer++;
        }
      }
      //document.getElementById("debugTA").value += "\n AutoPlayArticles.articlesPointer="+AutoPlayArticles.articlesPointer;

      var currentArticle = AutoPlayArticles.articles[AutoPlayArticles.articlesPointer];
    }

    //document.getElementById("debugTA").value += "\n Auto-playing article ID of "+currentArticle;
    if (typeof articleListObj.artIDArr["ID_"+currentArticle] != "undefined")
    {
      articleListObj.jump(articleListObj.artIDArr["ID_"+currentArticle], false);
    }
    else
    {
      // Play article from initialArticles or AutoPlayArticles.articles list
      dpVidObj.video.setSource("article", currentArticle);
    }
  }
}

function player_listener_MetadataRetrieved()
{
  //document.getElementById("debugTA").value += "\nplayer_listener_MetadataRetrieved() called.";

  // Update the preview image
  player_setPreviewImage(unescape(dpVidObj.video.metadata.previewImage));

  if ((dpVidObj.video.adState == "loading") || (dpVidObj.video.adState == "playing"))
  {
    //document.getElementById("videoCaption").innerHTML = "NOW PLAYING: Advertisement COMING UP: " + unescape(dpVidObj.video.metadata.name);
  }
  else
  {
    document.getElementById("videoCaption").innerHTML = unescape(dpVidObj.video.metadata.name);
  }

}

function player_listener_PlayStateChange(prevPlayState, currPlayState)
{
  //document.getElementById("debugTA").value += "\nplayer_listener_PlayStateChange() called.";
  //document.getElementById("debugTA").value += "\n prevPlayState="+prevPlayState+", currPlayState="+currPlayState;

  // Handle PlayState change
  switch (currPlayState)
  {
    case 0:
      // Playback is stopped.
      //document.getElementById("statusMessage").innerHTML = "Stopped";
      player_showPreviewImage();
      //player_showVideoStateAd("postview");
      break;

    case 1:
      // Playback is paused.
      //document.getElementById("statusMessage").innerHTML = "Paused";
      break;

    case 2:
      // Stream is playing.
      //document.getElementById("statusMessage").innerHTML = "Playing...";
      player_hidePreviewImage();
      player_hideVideoStateAds();
      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:
  }
}

function player_listener_PositionUpdated(currentPosition)
{
  //document.getElementById("debugTA").value += "\nplayer_listener_PositionUpdated() called.";
  //document.getElementById("debugTA").value += "\n currentPosition="+currentPosition;

  document.getElementById("videoPosition").innerHTML = convertFromSec(currentPosition, 8, true);

  // Update the progress bar based on percentage
  var duration = dpVidObj.video.getDuration();
  if ((duration != null) && (currentPosition > 0))
  {
    document.getElementById("progress").style.width = ((currentPosition / duration) * 101) + "%";
  }
  else
  {
    document.getElementById("progress").style.width = "0px";
  }
  //document.getElementById("progress").style.height = "2px";
}

function player_listener_Transitioning()
{
  //document.getElementById("debugTA").value += "\nplayer_listener_Transitioning() called.";

  player_hidePreviewImage();
  player_showVideoStateAd("preload");

}

function player_mute()
{
  //document.getElementById("debugTA").value += "\nplayer_mute() called.";

  if (!pageLoaded)
  {
    //alert("Please allow the page to finish loading.");
    return false;
  }

  if (dpVidObj.video.articleID == null)
  {
    // No article ID set (i.e., no video loaded) so just return
    return false;
  }

  dpVidObj.video.mute();
}


function player_pause()
{
  //document.getElementById("debugTA").value += "\nplayer_pause() called.";

  if (!pageLoaded)
  {
    //alert("Please allow the page to finish loading.");
    return false;
  }

  if (dpVidObj.video.articleID == null)
  {
    // No article ID set (i.e., no video loaded) so just return
    return false;
  }

  dpVidObj.video.pause();
}

function player_play()
{
  //document.getElementById("debugTA").value += "\nplayer_play() called.";

  if (!pageLoaded)
  {
    //alert("Please allow the page to finish loading.");
    return false;
  }

  if (dpVidObj.video.articleID == null)
  {
    if (currentArticle != "")
    {
      // No article ID set (i.e., no video loaded) so set source to most current article
      dpVidObj.video.setSource("article", currentArticle);

      return true;
    }
    else
    {
      // No article ID set (i.e., no video loaded) so just return
      return false;
    }
  }

  dpVidObj.video.play();

  return true;
}

function player_playPause()
{
  //document.getElementById("debugTA").value += "\nplayer_playPause() called.";

  if (!pageLoaded)
  {
    //alert("Please allow the page to finish loading.");
    return false;
  }

  if (dpVidObj.video.articleID == null)
  {
    if (currentArticle != "")
    {
      // No article ID set (i.e., no video loaded) so set source to most current article
      dpVidObj.video.setSource("article", currentArticle);

      return true;
    }
    else
    {
      // No article ID set (i.e., no video loaded) so just return
      return false;
    }
  }

  dpVidObj.video.play();

  return true;
}

function player_setPreviewImage(imgSource)
{
  //document.getElementById("debugTA").value += "\nplayer_setPreviewImage() called.";
  //document.getElementById("debugTA").value += "\n imgSource="+imgSource;

  if ((imgSource == "") && (player_defaultPreviewImg != null))
  {
    imgSource = player_defaultPreviewImg;
  }

  if (imgSource != "")
  {
    switch (playerSize)
    {
      case "large":
        document.getElementById("videoPreviewImage").innerHTML = '<img id="videoPreviewImage_image" name="videoPreviewImage_image" src="' + imgSource + '" width="576" height="432" border="0" />';
        break;

      case "small":
        document.getElementById("videoPreviewImage").innerHTML = '<img id="videoPreviewImage_image" name="videoPreviewImage_image" src="' + imgSource + '" width="480" height="360" border="0" />';
        break;

      default:
        return false;
    }
  }
  else
  {
    document.getElementById("videoPreviewImage").innerHTML = "";
  }

  currentPreviewImage = imgSource;

  return true;
}

function player_setSource(artID)
{
  //document.getElementById("debugTA").value += "\nplayer_setSource() called.";
  //document.getElementById("debugTA").value += "\n artID="+artID;

  if (!pageLoaded)
  {
    //alert("Please allow the page to finish loading.");
    return false;
  }

  if ((artID == "") || (typeof artID == "undefined"))
  {
    // Invalid article ID so just return
    return false;
  }

  dpVidObj.video.setSource("article", artID);
}
function player_showVideoStateAd(adStr)
{
  //document.getElementById("debugTA").value += "\nplayer_showVideoStateAd() called.";
  //document.getElementById("debugTA").value += "\n adStr="+adStr;

  // Force adStr parameter to lower case if passed in as a string.
  if (typeof(adStr) == "string")
  {
    adStr = adStr.toLowerCase();
  }

  switch (adStr)
  {
    case "buffer":
     //document.getElementById("bufferAd").style.visibility = "hidden";
     //dpVidObj.video.videoObject.style.visibility = "visible";
     // document.getElementById("preLoadAd").style.visibility = "hidden";
     // document.getElementById("postViewAd").style.visibility = "hidden";
      break;

    case "postview":
     // document.getElementById("postViewAd").style.visibility = "hidden";
     // dpVidObj.video.videoObject.style.visibility = "visible";
      //document.getElementById("preLoadAd").style.visibility = "hidden";
     // document.getElementById("bufferAd").style.visibility = "hidden";
      break;

    case "preload":
      document.getElementById("preLoadAd").style.visibility = "visible";
      dpVidObj.video.videoObject.style.visibility = "hidden";
      //document.getElementById("bufferAd").style.visibility = "hidden";
      //document.getElementById("postViewAd").style.visibility = "hidden";
      break;

    default:
      return false;
      break;
  }

  return true;
}

function player_hideVideoStateAds()
{
  //document.getElementById("debugTA").value += "\nplayer_hideVideoStateAds() called.";

  dpVidObj.video.videoObject.style.visibility = "visible";
  document.getElementById("preLoadAd").style.visibility = "hidden";
  //document.getElementById("bufferAd").style.visibility = "hidden";
  //document.getElementById("postViewAd").style.visibility = "hidden";

  return true;
}

function player_showPreviewImage()
{
  //document.getElementById("debugTA").value += "\nplayer_showPreviewImage() called.";

  document.getElementById("videoPreviewImage").style.visibility = "visible";
  dpVidObj.video.videoObject.style.visibility = "hidden";

  return true;
}

function player_stop()
{
  //document.getElementById("debugTA").value += "\nplayer_stop() called.";

  if (!pageLoaded)
  {
    //alert("Please allow the page to finish loading.");
    return false;
  }

  if (dpVidObj.video.articleID == null)
  {
    // No article ID set (i.e., no video loaded) so just return
    return false;
  }

  if ((dpVidObj.video.adState == "loading") || (dpVidObj.video.adState == "playing"))
  {
    return false;
  }

  dpVidObj.video.stop();
}

function player_truncateString(stringParam, maxLength)
{
  //document.getElementById("debugTA").value += "\nplayer_truncateString() called.";
  //document.getElementById("debugTA").value += "\n stringParam="+stringParam+", maxLength="+maxLength;

  // Force parameters to valid format
  stringParam = stringParam.toString();
  maxLength = parseInt(maxLength, 10);

  if (!isNaN(maxLength) && (stringParam.length > maxLength))
  {
    // Truncate the string
    stringParam = stringParam.substring(0, maxLength);
    // Remove the last word to ensure that we didn't truncate in the middle of a word
    stringParam = stringParam.replace(/\w+$/, "");
    // Add ellipses to the end
    stringParam += "...";
  }

  return stringParam;
}

function zeroPad(numVal)
{
  var numStr = numVal.toString();
  if (numStr.length == 1)
  {
    numStr = "0" + numStr;
  }

  return numStr;
}