// News Ticker
// +------------------------------------------------------------------------------------------------------------------------------+
// | 
// +------------------------------------------------------------------------------------------------------------------------------+
// | AUTHORS: 
// | Neil Champion (neil@cambridgenewmedia.co.uk)
// | Peter Fayle (webmaster@chu.cam.ac.uk)
// +------------------------------------------------------------------------------------------------------------------------------+
// | INSTRUCTIONS:
// +------------------------------------------------------------------------------------------------------------------------------+
// | COMMENTS:
// +------------------------------------------------------------------------------------------------------------------------------+
// | FILES REQUIRED FOR PROCESSING
// | Please read the instructions and comments for all included files
// | none
// +------------------------------------------------------------------------------------------------------------------------------+
// | VERSION HISTORY:
// | v 1.0     |     03.01.2004     |     Original version
// | v 1.1     |     26.07.2010     |     Variable onclick added    |     Peter Fayle
// +------------------------------------------------------------------------------------------------------------------------------+

//These variables can be overwritten on a case by case basis
var NewsTicker_CharacterTimeout = 50;
var NewsTicker_ArticleTimeout = 7000;
var NewsTicker_WidgetOne = "_";
var NewsTicker_WidgetTwo = "-";
var NewsTicker_WidgetNone = "";
var NewsTicker_LeadString = "";
var NewsTicker_ItemCount = 5;

//These variables should not require changing from one case to the next
var NewsTicker_CurrentStory = -1;
var NewsTicker_CurrentLength = 0;
var NewsTicker_AnchorObject = "";
var NewsTicker_StorySummary = "";
var NewsTicker_TargetLink = "";
var NewsTicker_Prefix = "";
var NewsTicker_ArticleTitle = new Array();
var NewsTicker_ArticleLink = new Array();



// Ticker startup
function startTicker() {
	// Define run time values
	NewsTicker_CurrentStory = -1;
	NewsTicker_CurrentLength = 0;
	// Locate base objects
	if (document.getElementById) {
		NewsTicker_AnchorObject = document.getElementById("NewsArticle");
		if (NewsTicker_AnchorObject) {runTheTicker();}
	}
}
// Ticker main run loop
function runTheTicker() {
	var myTimeout;
	// Go for the next story data block
	if(NewsTicker_CurrentLength == 0) {
		NewsTicker_CurrentStory++;
		NewsTicker_CurrentStory = NewsTicker_CurrentStory % NewsTicker_ItemCount;
		NewsTicker_StorySummary = NewsTicker_ArticleTitle[NewsTicker_CurrentStory].replace(/&quot;/g,'"');
		NewsTicker_TargetLink = NewsTicker_ArticleLink[NewsTicker_CurrentStory];
		NewsTicker_AnchorObject.href = NewsTicker_TargetLink;
		NewsTicker_AnchorObject.onclick = "_gaq.push(['_trackPageview','news-" + NewsTicker_TargetLink + "']);";
		NewsTicker_Prefix = NewsTicker_LeadString;
	}
	// Stuff the current ticker text into the anchor
	NewsTicker_AnchorObject.innerHTML = NewsTicker_Prefix + NewsTicker_StorySummary.substring(0,NewsTicker_CurrentLength) + whatWidget();
	// Modify the length for the substring and define the timer
	if(NewsTicker_CurrentLength != NewsTicker_StorySummary.length) {
		NewsTicker_CurrentLength++;
		myTimeout = NewsTicker_CharacterTimeout;
	}
	else {
		NewsTicker_CurrentLength = 0;
		myTimeout = NewsTicker_ArticleTimeout;
	}
	// Call up the next cycle of the ticker
	setTimeout("runTheTicker()", myTimeout);
}

// Widget generator
function whatWidget() {
	if(NewsTicker_CurrentLength == NewsTicker_StorySummary.length) {return NewsTicker_WidgetNone;}
	if((NewsTicker_CurrentLength % 2) == 1) {return NewsTicker_WidgetOne;}
	else {return NewsTicker_WidgetTwo;}
}

