// -----------------------------------------------------------
// Default Top Story Script: This script controls the content
// that goes on the top right column of a News Releases page
//                 By: Eduardo Carneiro
//                News@Cisco May 02, 2006
// -----------------------------------------------------------

var relatedContentObj = new Object();
var TSId = new Array();
var TSPath = 'http://newsroom.cisco.com/images/homepage/topstory2/';
var target = '_self'; // Default target used for Read More

function topStorySyndication () {
  //default values
  this.dateFormat = null;
  this.showTopStory = topStoryArea;
}

// Get the ids in the object. This provides us with both a total count and a variable to manipulate the object
function getTSId () {
  if (TSId.length == 0) { // Extra precaution not to append to the TSId array if it was already populated
    for (i in relatedContentObj) {
      TSId.push(i);
    }
  }
  
  return TSId;
}

// Split Title, SubTitle and Thumb URL that were separated by !? and add the two first values of the obj also to a single array
// that will be manipulated by the calling functions
function getValues (index) {
  var ids;

// Only call getIds once otherwise it will keep on adding up to the TSId array
  if (index == null) {
    var ids = getTSId();
    index = 0;
  } else { 
    ids = TSId;
  }
  
  var splitInfo = relatedContentObj[ids[index]][2].split('||');
  splitInfo.push(relatedContentObj[ids[index]][1]);
  
  return splitInfo;
}

function setAction (path) {
  var action = 'Read More';
  var findFeedroom = /flash\/evp/i;
  var findWebcast = /on24\.com/i;
  var findWebcast2 = /gaia\.unit\.net/i;
  var findWebcast3 = /WebCastId=/i; // use array here if any more are added
  
  if (findFeedroom.test(path)) {
    action = 'Watch Video';
    target = '_blank';
  }
  else if (findWebcast.test(path) || findWebcast2.test(path) || findWebcast3.test(path)) {
    action = 'Watch Webcast';
    target = '_blank';
  }
  
  return action;
}

function getURL (img) {
  var parts = img.split('_');
  parts[2] = parts[2].substring(0,6);
  return TSPath+'ts_60x60_'+parts[2]+'.jpg';
}

function topStoryArea (pos) {
  if (pos == null) {
    pos = 0;
  }

  var intro = '<div class="content-region-right-header"> <h6 class="alt-1">TOP STORY</h6> <div class="item"> <div class="spotlight-nowrap-60">';
  var values = getValues();

  var action = setAction(values[3]);
  var url = getURL(values[0]);
  
// Now finish populating the video area
  var thumb = '<img id="tsThumb" src="'+url+'" alt="'+values[2]+'" width="60" height="60" border="0" />';
  var shortHL = '<h2>'+values[2]+'</h2>';
  var imgCaption = '<p class="topstory">'+values[1]+'</p>';
  var actionLink = '<div class="description-link"><a href="'+values[3]+'&amp;sid=rs_top_story_module" title="'+action+'" target="'+target+'" style="font-weight: bold">&gt; '+action+'</a></div><!-- description-link -->';
  var end = '</div><!-- spotlight-nowrap-60 --> <div class="spotlight-magic"></div> </div> <!-- item --></div> <!-- featVideo --></div> <!-- content-region-right-header -->';

  return intro + thumb + shortHL + imgCaption + actionLink + end;
}

