var theCharacterTimeout = 100;
var theStoryTimeout     = 5000;
var theStorySummary     = "";
var theWidgetOne        = "_";
var theWidgetTwo        = "-";
var theWidgetNone       = "";
var theItemCount        = 0;
var headlines           = new Array();
var links               = new Array();
var theAnchorObject     = 0;
/* ------------------------------------------------------------------------- */

function initTicker()
{

	var ticker 	= document.getElementById("newsticker");
	var uls      	= ticker.getElementsByTagName("ul");
	var c		= uls[0].childNodes;
	var list   	= new Array();
	var j      	= 0;

	for(var i=0; i<c.length; i++){
		if(c[i].tagName=="LI"){
			if(c[i].firstChild){
				list[j++]=c[i].firstChild;
			}
		}
	}

	j = 0;

	var text;

	for(var i=0; i<list.length; i++){
		if(list[i].text){
			text=list[i].text;
		} else {
			text=list[i].innerText;
		}
		if(text && list[i].href){
			headlines[j]=text;
			links[j]=list[j].href;
			j++;
		}
	}

	theAnchorObject 	= document.getElementById("ticker_text");
	theItemCount 		= links.length;
	theCurrentStory 	= (Math.round(theItemCount*Math.random())) - 1;
	theCurrentLength 	= 0;
	runTicker();
}

/* ------------------------------------------------------------------------- */

function runTicker() {
	var myTimeout;  

	/* Go for the next story data block */

	if(theCurrentLength == 0) {
		theCurrentStory++;
		theCurrentStory      = theCurrentStory % theItemCount;
		theStorySummary      = headlines[theCurrentStory];
		theTargetLink        = links[theCurrentStory];
		theAnchorObject.href = theTargetLink;
	}

	/* Stuff the current ticker text into the anchor */
	var theText = theStorySummary.substring(0,theCurrentLength) + whatWidget();
	theAnchorObject.firstChild.nodeValue = theText;

	/* Modify the length for the substring and define the timer */

	if(theCurrentLength != theStorySummary.length) {
		theCurrentLength++;
		myTimeout = theCharacterTimeout;
	}
	else {
		theCurrentLength = 0;
		myTimeout = theStoryTimeout;
	}

	/* Call up the next cycle of the ticker */

	setTimeout("runTicker()", myTimeout);
}

/* ------------------------------------------------------------------------- */
/* Widget generator */

function whatWidget()
{
	if(theCurrentLength == theStorySummary.length) {
		return theWidgetNone;
	}

	if((theCurrentLength % 2) == 1) {
		return theWidgetOne;
	}
	else {
		return theWidgetTwo;
	}
}

/* ------------------------------------------------------------------------- */

