var list; // global list variable cache
var tickerObj; // global tickerObj cache
var hex = 255;
var interval = 3; // interval in seconds
var fadeSpeed = 40; // fade speed, the lower the speed the faster the fade.  40 is normal.


function fadeText(divId)
{
	if(tickerObj)
	{
		if(hex>0)
		{
			hex-=5; // increase color darkness
			tickerObj.style.color="rgb("+hex+","+hex+","+hex+")";
			setTimeout("fadeText('" + divId + "')", fadeSpeed); 
		}
		else
			hex=255; //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);
	
	var prevItem = count - 1;
	if (prevItem < 0)
	{
	    prevItem = list.length - 1;
	}
	var curItem = count;
	var nextItem = count + 1;
	if (nextItem == list.length)
	{
	    nextItem = 0;
	}
	
	// hide previous one.
	if (prevItem >= 0 && list[prevItem].style != null)
	{
	    list[prevItem].style.display = "none";
	}
	
	// show current item
	if (list[curItem].style != null)
	{
	    list[curItem].style.display = "block";
	}
	
	// show next item 
	if (list[nextItem].style != null)
	{
	    list[nextItem].style.display = "block";
	}
	
	// if only 1 item, then only show current item
	
	
	
	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;
}

// Javascript originally by Patrick Griffiths and Dan Webb.
// http://htmldog.com/articles/suckerfish/dropdowns/
sfHover = function() {
	var sfEls = document.getElementById("navbarPWG").getElementsByTagName("li");
	var sfElsUls = document.getElementById("navbarPWG").getElementsByTagName("li").getElementsByTagName("ul");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" hover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" hover\\b"), "");
		}
	}
	for (var t=0; i<sfElsUls.length; t++) {
		sfEls[t].onmouseover=function() {
			this.className+=" hover";
		}
		sfEls[t].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" hover\\b"), "");
		}
	}
}


