//MAIN TICKER FUNCTIONS
//SET PREFERENCE VARIABLES
var theCharacterTimeout = 50;
var theStoryTimeout     = 5000;
var theWidgetOne        = "_";
var theWidgetTwo        = "-";
var theWidgetNone       = "";
var theLeadString       = "NEWS:&nbsp;";

var theSummaries = new Array();
var theSiteLinks = new Array();

var theItemCount = 1;

// Ticker stories
theSummaries[0] = "See Amaze's comments on exit interviews in the Guardian.";
theSiteLinks[0] = "http://jobsadvice.guardian.co.uk/officehours/story/0,,1402017,00.html";

theSummaries[1] = "2 text.";
theSiteLinks[1] = "#";

theSummaries[2] = "3 text.";
theSiteLinks[2] = "#";

theSummaries[3] = "4 text.";
theSiteLinks[3] = "#";

// Ticker startup function
function startTicker() {
	// Define run time values
	theCurrentStory     = -1;
	theCurrentLength    = 0;
	// Locate base objects
	if (document.getElementById) {
			//Write the anchor text for the ticker
			document.getElementById("Tickr").innerHTML = '<a id="tickerAnchor" href="#" title="Visit this news story"></a>';
		    theAnchorObject = document.getElementById("tickerAnchor");
			runTheTicker();
		 } else {
            return true;
	}
}

// Ticker main run loop function
function runTheTicker() {
	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];
		theAnchorObject.href = theTargetLink;
		thePrefix            = "<strong>" + theLeadString + "</strong>";
	}
	// 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++;
		myTimeout = theCharacterTimeout;
	} else {
		theCurrentLength = 0;
		myTimeout = theStoryTimeout;
	}
	// Call up the next cycle of the ticker
	setTimeout("runTheTicker()", myTimeout);
}

// Widget generator function
function whatWidget() {
	if(theCurrentLength == theStorySummary.length) {
		return theWidgetNone;
	}

	if((theCurrentLength % 2) == 1) {
		return theWidgetOne;
	} else {
		return theWidgetTwo;
	}
}
