var ticker = {};
document.write("<style type='text/css'>.tickerData { display: none; }</style>");

// Ticker startup
function startTicker() {
	ticker.theCharacterTimeout = 50;
	ticker.theStoryTimeout     = 5000;
	ticker.theWidgetOne        = "_";
	ticker.theWidgetTwo        = "-";
	ticker.theWidgetNone       = "";
	ticker.theLeadString       = "";
	ticker.theSummaries = new Array();
	ticker.theSiteLinks = new Array();
	ticker.theItemCount = 8;
		
	var wrapper  = document.getElementById("tickiData");
    var linkData = wrapper.getElementsByTagName("a");

	for( var i=0; i<linkData.length; i++) {
		ticker.theSummaries[i] = linkData[i].innerHTML;
		ticker.theSiteLinks[i] = linkData[i].href; 
	}
	
	// Define run time values
	ticker.theCurrentStory  = -1;
	ticker.theCurrentLength = 0;
	// Locate base objects
	ticker.theAnchorObject = document.getElementById("tickerAnchor");
	runTheTicker();   	
	 
}
// Ticker main run loop
function runTheTicker() {
	var myTimeout;  
	// Go for the next story data block
	if(ticker.theCurrentLength == 0) {
		ticker.theCurrentStory++;
		ticker.theCurrentStory       = ticker.theCurrentStory % ticker.theItemCount;
		ticker.theStorySummary       = ticker.theSummaries[ticker.theCurrentStory].replace(/&quot;/g,'"');		
		ticker.theTargetLink         = ticker.theSiteLinks[ticker.theCurrentStory];
		ticker.theAnchorObject.href  = ticker.theTargetLink;
		ticker.thePrefix 	     	 = "<span class=\"tickls\">" + ticker.theLeadString + "</span>";
	}
	// Stuff the current ticker text into the anchor
	ticker.theAnchorObject.innerHTML = ticker.thePrefix + ticker.theStorySummary.substring(0,ticker.theCurrentLength) + whatWidget();
	// Modify the length for the substring and define the timer
	if(ticker.theCurrentLength != ticker.theStorySummary.length) {
		ticker.theCurrentLength++;
		myTimeout = ticker.theCharacterTimeout;
	}
	else {
		ticker.theCurrentLength = 0;
		myTimeout = ticker.theStoryTimeout;
	}
	// Call up the next cycle of the ticker
	setTimeout("runTheTicker()", myTimeout);
}
// Widget generator
function whatWidget() {
	if(ticker.theCurrentLength == ticker.theStorySummary.length) 	{
		return ticker.theWidgetNone;
	}
	if((ticker.theCurrentLength % 2) == 1) {
		return ticker.theWidgetOne;
	}
	else {
		return ticker.theWidgetTwo;
	}
}		

glow.ready( function() { 
	if ( !document.getElementById ||
		 !document.getElementsByTagName ||
		 !document.getElementById("tickerAnchor") ||
		 !document.getElementById("tickiData")
	 ) return false;
	startTicker(); 
} );