var list
var tickerObj;
var hex = 255;

function fadeText()
{
	if(tickerObj)
	{
		if(hex<255)
		{
			hex+=5; 
			tickerObj.style.color="rgb("+hex+","+hex+","+hex+")";
			setTimeout("fadeText()", fadeSpeed); 
		}
		else
		{
			hex=255;
		}	
	}
}

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(0);
}
function run(count)
{
	hex=0;
	fadeText();
	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("fadeOutText(" + count+ ")", interval*1000);
}
function reportError(error)
{
	alert("The script could not run because you have errors:\n\n" + error);
	return false;
}

function fadeOutText(count)
{
	if(tickerObj)
	{
		if(hex>0)
		{
			hex-=5; // increase color darkness
			tickerObj.style.color="rgb("+hex+","+hex+","+hex+")";
			setTimeout("fadeOutText(" + count+ ")", fadeSpeed); 
		}
		else
		{
			hex=0;
			window.setTimeout("run(" + count+ ")", 0);
		}	
	}
}

