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;
}

var interval = 16; // interval in seconds
var fadeSpeed = 55; // fade speed, the lower the speed the faster the fade.  40 is normal.

// Dale's Random Text Box //
var links = new Array();

links[0] = '<a href="http://beta.ldn.flavorpill.net/" target="_blank">Flavorpill</a> (cutting-edge and mainstream arts &amp; culture)';
links[1] = '<a href="http://www.dailycandy.com/" target="_blank">Daily Candy</a> (daily insider scoop on what&#39;s new)';
links[2] = '<a href="http://www.urbanjunkies.com/" target="_blank">Urban Junkies</a> (the edgier daily insider scoop on what&#39;s new)';
links[3] = '<a href="http://www.timeout.com/london/" target="_blank">Time Out: London</a> (wide range of activities around town)';
links[4] = '<a href="http://www.tfl.gov.uk/tube/" target="_blank">The Tube</a> (updates on tube and bus service)';
links[5] = '<a href="http://newsvote.bbc.co.uk/email/news" target="_blank">BBC News</a> (does exactly what it says on the tin)';
links[6] = '<a href="http://www.dwslondon.co.uk/" target="_blank">DWS</a> (sample sales for men &amp; women)';
links[7] = '<a href="http://www.billiondollarbabes.co.uk/html/events.html" target="_blank">Billion Dollar Babes</a> (sample sales & fashion events)';
links[8] = '<a href="http://news.hereisthecity.com" target="_blank">Here Is The City</a> (news &amp; gossip for the financial world)';

function gofirst() {
	var linknumber = Math.floor(Math.random() * links.length);
	thediv.innerHTML = links[linknumber];
	gotext();
}

function gotext() {	
	window.setInterval("randomiser()", 2500);
}

function randomiser() {
	var linknumber = Math.floor(Math.random() * links.length);
	thediv.innerHTML = links[linknumber];
}