var win;
var doc;
var links;
var numLinks;
var timerID = null;
var timerRunning = false;

// The odd structure of this function is due to constraints 
// of Javascript's threading model.  For setTimeout() to work
// correctly, ie. to actually pause before doing next link, the
// function must call itself as one of that function's arguments.
function scanLinks(index)
{
		
	if (index > 0)
	{
		links[index-1].style.background="#FFFFFF";
		if (index == (numLinks) )
		{ 
			index = 0;
		}
	}
	links[index].style.background="#FFFF10";
	index++;
//	if ( index = numLinks)
//		links[1].style.background="#00A5C6";
//	if (index <= numLinks)
//	{
		//index++;
		timerID = setTimeout("scanLinks('" + index + "')", 1000);
		timerRunning = true;
//	}
//	timerRunning = false;
//	clearTimeout(timerID);
}

function highlightLinks(_win) 
{
	win = _win;
	doc = win.document;
	links = doc.links;
	numLinks = links.length;
	if(timerRunning)
      clearTimeout(timerID)
   timerRunning = false;
   var index = 0;
	scanLinks(index);
  	var str = "There are " + numLinks + " links.";
  	var linkHref = document.createTextNode(str);
   var lineBreak = document.createElement("br");
	document.body.appendChild(lineBreak);
	document.body.appendChild(linkHref);
  	document.body.appendChild(lineBreak);
}