var theCharacterTimeout = 50;
var theStoryTimeout     = 2000;
var theWidgetOne        = " ";
var theWidgetTwo        = "";
var theWidgetLast		="...";
var theWidgetNone       = "";
var theLeadString       = "&nbsp;";

var theSummaries = new Array();
var theSiteLinks = new Array();
var theNewsDate = new Array();
var theItemCount = 4;

function OpenNews(param_id){
	window.location="/NewsDetails.aspx?nID="+param_id;
}

// Ticker startup
function startTicker()
{
	// Define run time values
	theCurrentStory  = -1;
	theCurrentLength = 0;
	theBuf = "";
	// Locate base objects
	if (document.getElementById) {	
		theAnchorObject = 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()
{
	theItemCount = theSummaries.length;
	var myTimeout;  
	// Go for the next story data block
	if(theCurrentLength == 0)
	{
		theCurrentStory++;
		theCurrentStory      = theCurrentStory % theItemCount;
		theStorySummary      = theSummaries[theCurrentStory].replace(/&quot;/g,'"');		
		theTargetLink        = theSiteLinks[theCurrentStory];
		document.getElementById("tickerNewsDate").innerHTML = theNewsDate[theCurrentStory];
		theAnchorObject.href = theTargetLink;
		//theAnchorObject.target="_blank";
		thePrefix 	     = theLeadString ;
	}
	
	//fill our buffer with the next four chars
	theBuf = theStorySummary.substring(theCurrentLength,theCurrentLength + 4)

	//if the contents of theBuf = '<b>x' or </b> then we want to write 3 or 4 chars at once
	if (theBuf.substring(0,3) == "<b>") {
		theCurrentLength = theCurrentLength + 3;
	}
	else if (theBuf.substring(0,4) == "</b>") {	
	theCurrentLength = theCurrentLength + 4;
	}
	else {
		// Stuff the current ticker text into the anchor
		theAnchorObject.innerHTML = thePrefix + theStorySummary.substring(0,theCurrentLength) + whatWidget();
		// Modify the length for the substring and define the timer
		if((theCurrentLength != theStorySummary.length)&&(theCurrentLength<=36))
		{
			theCurrentLength++;
			myTimeout = theCharacterTimeout;
		}
		else
		{
			theCurrentLength = 0;
			myTimeout = theStoryTimeout;
		}
	}
	
	// Call up the next cycle of the ticker
	setTimeout("runTheTicker()", myTimeout);
}

// Widget generator
function whatWidget()
{
	if(theCurrentLength == theStorySummary.length)
	{
		return theWidgetNone;
	}
	if(theCurrentLength == 37)
	{
		return theWidgetLast;
	}
	
	if((theCurrentLength % 2) == 1)
	{
		return theWidgetOne;
	}
	else
	{
		return theWidgetTwo;
	}
}