var interval = 5; // interval in seconds
var fadeSpeed = 40; // fade speed, the lower the speed the faster the fade.  40 is normal.


var list; // global list variable cache
var tickerObj; // global tickerObj cache
var hex1_start = 167;
var hex2_start = 25;
var hex3_start = 48;
var hex1_stop = 255;
var hex2_stop = 255;
var hex3_stop = 255;
var hex1_curr = hex1_start;
var hex2_curr = hex2_start;
var hex3_curr = hex3_start;

function fadeText(divId)
{
  var fade_step = 5;
	if(tickerObj)
	{
		if(hex1_curr < hex1_stop || hex2_curr < hex2_stop || hex3_curr < hex3_stop)
		{
			if (hex1_curr < hex1_stop) hex1_curr = hex1_curr+fade_step; // increase color darkness
			if (hex2_curr < hex2_stop) hex2_curr = hex2_curr+fade_step; // increase color darkness
			if (hex3_curr < hex3_stop) hex3_curr = hex3_curr+fade_step; // increase color darkness
			tickerObj.style.color="rgb("+hex1_curr+","+hex2_curr+","+hex3_curr+")";
			setTimeout("fadeText('" + divId + "')", fadeSpeed); 
		}
		else {
			hex1_curr=hex1_start; //reset hex value
			hex2_curr=hex2_start; //reset hex value
			hex3_curr=hex3_start; //reset hex value
		}
	}
}

function initialiseList(divId)
{
	tickerObj = document.getElementById(divId);
	if(!tickerObj)
		reportError("Could not find a div element with id \"" + divId + "\"");
	
	list = tickerObj.childNodes;
	if(list.length <= 0)
		reportError("The div element \"" + divId + "\" does not have any children");
		
	for (var i=0; i<list.length; i++)
	{
		var node = list[i];
		if (node.nodeType == 3 && !/\S/.test(node.nodeValue)) 
	        		tickerObj.removeChild(node);

	}
	run(divId, 0);
}
function run(divId, count)
{
	fadeText(divId);
	list[count].style.display = "block";
	if(count > 0)
		list[count-1].style.display = "none";
	else
		list[list.length-1].style.display = "none";
	
	count++;
	if(count == list.length)
		count = 0;
		
	window.setTimeout("run('" + divId + "', " + count+ ")", interval*1000);
}
function reportError(error)
{
	alert("The script could not run because you have errors:\n\n" + error);
	return false;
}
