var list; // global list variable cache
var tickerObj; // global tickerObj cache
var hex = 255;

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);
	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;
}


function mapClick () {

var objSelect = document.getElementById('aid');

switch ( objSelect.options[objSelect.selectedIndex].value ) {

 case '5329' : window.location.href='si.cmsx?itemID=1390&mapLon=-0.594&mapLat=52.304&mapZoom=4'; break

 case '4481' : window.location.href='si.cmsx?itemID=1390&mapLon=-0.270&mapLat=52.226&mapZoom=4'; break

 case '1825' : window.location.href='si.cmsx?itemID=1390&mapLon=-0.389&mapLat=52.296&mapZoom=4'; break

 case '6906' : window.location.href='si.cmsx?itemID=1390&mapLon=-0.539&mapLat=52.396&mapZoom=4'; break

 case '9574' : window.location.href='si.cmsx?itemID=1390&mapLon=-0.245&mapLat=52.572&mapZoom=4'; break

 case '1824' : window.location.href='si.cmsx?itemID=1390&mapLon=-0.186&mapLat=52.331&mapZoom=4'; break

 case '1826' : window.location.href='si.cmsx?itemID=1390&mapLon=-0.073&mapLat=52.323&mapZoom=4'; break

 default : window.location.href='si.cmsx?itemID=1390';

 }

}


function playSoundbite ( strUrl ) {

var mp3name = strUrl.substring ( strUrl.lastIndexOf('/')+1, strUrl.length );

mp3name = mp3name.substring ( 0, strUrl.indexOf('.')-2 );

if(!getCookie(mp3name)) {

 document.write ( '<embed src="http://www.bellsystems.co.uk/public/audio/peterlane/' + mp3name +'.mp3" width="10" height="10" autostart="true" name="audiomarketing" enablejavascript="true" hidden="true"/>' );

 setCookie ( mp3name, 'y' );

 }

}

function setCookie(cookiename, cookievalue, days) { 

if (!days) days = 1; // default to 1 day if empty 

var expdate = new Date(); 
expdate.setTime(expdate.getTime() + days*24*60*60*1000); 

document.cookie = cookiename + "=" + escape(cookievalue) + "; expires=" + expdate.toGMTString(); 

} 


function getCookie (name) {

var dc = document.cookie;
var cname = name + "=";
var clen = dc.length;
var cbegin = 0;

while (cbegin < clen) { 
var vbegin = cbegin + cname.length;

if (dc.substring(cbegin, vbegin) == cname) { 
var vend = dc.indexOf (";", vbegin);
if (vend == -1) vend = clen;

return unescape(dc.substring(vbegin, vend));
}

cbegin = dc.indexOf(" ", cbegin) + 1;

if (cbegin== 0) break;
}
return null;
}



