// JavaScript Document: ticker.js

function startTicker()
{
	// Define run time values
	currentStory     = -1;
	currentLength    = 0;
	
	// Locate base objects
	if (document.getElementById) {	
		anchorObject     = document.getElementById("tickerAnchor");
		runTheTicker();   	
	}
	else {
		document.write("<style>.ticki{display:none;}.ticko{border:0px; padding:0px;}</style>");
		return true;
	}
}

// Ticker main run loop
function runTheTicker()
{
	var myTimeout;  

	// Go for the next story data block
	if(currentLength == 0)
	{
		currentStory++;
		currentStory      = currentStory % itemCount;
		storySummary      = summaries[currentStory].replace(/&quot;/g,'"');		
		targetLink        = siteLinks[currentStory];
		anchorObject.href = targetLink;
		prefix			  = "<span class=\"tickls\">" + leadString + "</span>";
	}
	
	// Stuff the current ticker text into the anchor
	anchorObject.innerHTML = prefix + storySummary.substring(0, currentLength) + whatWidget();
	
	// Modify the length for the substring and define the timer
	if ((currentLength != storySummary.length) && (currentLength < 82))
	{
		currentLength++;
		myTimeout = charTimeout;
	}
	else
	{
		if (currentLength < storySummary.length) { anchorObject.innerHTML = prefix + storySummary.substring(0, currentLength) + "..."; }
		currentLength = 0;
		myTimeout = storyTimeout;
	}
	
	// Call up the next cycle of the ticker
	setTimeout("runTheTicker()", myTimeout);
}

// Widget generator
function whatWidget()
{
	if(currentLength == storySummary.length)
	{
		return widgetNo;
	}

	if((currentLength % 2) == 1)
	{
		return widgetOne;
	}
	else
	{
		return widgetTwo;
	}
}
