var storySummaries = new Array();
var storyLinks = new Array();

var storyCount = 3;
var myDate = new Date();

/*
storySummaries[0] = 	"<b>Heading <i>for</i> Story 1</b><br>"
  +"&nbsp;&#149; This is the text for <b>story</b> 1.<br>"
  +"&nbsp;&#149; This is the more text for story 1.<br>"
  +"&nbsp;&#149; This is the even more text for story 1.<br>"
  +"&nbsp;&#149; This is the yet more text for story 1.<br>"
  ;
storyLinks[0] = "story1.htm";
*/

// storySummaries[0] =  myDate.toLocaleString() + " server status";
// storyLinks[0] = "";

storySummaries[0] = "Click here for current eSnipe <span style=\"color:red\">server status</span>";
storyLinks[0] = "ServerStatus/";

storySummaries[1] = "CNET: <span style=\"color:red\">\"By far, the best sniping service\"</span>";
storyLinks[1] = "http://reviews.cnet.com/4520-10165_7-5664889-2.html";

storySummaries[2] = "eSnipe called <span style=\"color:red\">\"industry standard\"</span> service";
storyLinks[2] = "http://query.nytimes.com/gst/abstract.html?res=F40E15FD3C5A0C768CDDA00894DA404482";

//storySummaries[2] = "Super tutorial: <span style=\"color:black\">How to Use Bid Groups</span>";
//storyLinks[2] = "eSnipeHelp/bg/index.html";

storySummaries[3] = "Scientific study says: <span style=\"color:red\">It pays to Snipe!</span>";
storyLinks[3] = "http://www.usatoday.com/tech/science/columnist/vergano/2006-06-25-ebay-physics_x.htm";

//storySummaries[4] = "Your password is <i>terrible!</i> <span style=\"color:gray\">(Find out why)</span>";
//storyLinks[4] = "";

//
// **** ticker
//


var characterTimeout = 80;
var storyTimeout = 5000;
var cursor =  "_";
var storyNumber;
var currentLength;
var anchorObject;

// Ticker startup
function initializeTicker()
{
storyNumber = -1;
currentLength = 0;
anchorObject = document.getElementById("anchor");

if (anchorObject != null)
{
  if (storyCount > 0)
  {
     runTicker();
  };
};
}

// Ticker main run loop
function runTicker()
{
var myTimeout;
	
	 // Go for the next story data block
	if (currentLength == 0)
	{
		storyNumber++;
		storyNumber = storyNumber % storyCount;
		currentStorySummary = storySummaries[storyNumber];
		targetLink = storyLinks[storyNumber];
		anchorObject.href = targetLink;
	}
	
	if (currentStorySummary.charAt(currentLength) == "<")
	{
		if ((newIndex = currentStorySummary.indexOf(">", currentLength)) != -1)
		{
			currentLength = newIndex;
		};
	}

	if (currentStorySummary.charAt(currentLength) == "&")
	{
		if ((newIndex = currentStorySummary.indexOf(";", currentLength)) != -1)
		{
			currentLength = newIndex;
		};
	}

	anchorObject.innerHTML = currentStorySummary.substring(0, currentLength) + drawCursor();

	 // Modify the length for the substring and define the timer
	if(currentLength != currentStorySummary.length)
	{
		currentLength++;
		myTimeout = characterTimeout;
	}
	else
	{
		currentLength = 0;
		myTimeout = storyTimeout;
	};
	
	// Call up the next cycle of the ticker
	setTimeout("runTicker()", myTimeout);
}

function drawCursor()
{
	if(currentLength == currentStorySummary.length)
	{
		return "";
	}
	else
	{
		return cursor;
	}
}
