window.onload = initTopStoryBox;

function focusTopStory(n)
{
	if(inittopstory == 1)
	{
		for(i=0;i<numTopStories;i++)
		{
			if(i == n)
			{
				topStoryTeasers[i].style.zIndex = '1';
				topStoryIntros[i].style.zIndex = '1';
				topStoryHeadlines[i].style.color = 'white';
				topStoryHeadlines[i].style.background = "url('/images/pcweek/bg-main-news-a.gif') left no-repeat";
			}
			else
			{
				topStoryTeasers[i].style.zIndex = '0';
				topStoryIntros[i].style.zIndex = '0';
				topStoryHeadlines[i].style.color = '#003399';
				topStoryHeadlines[i].style.background = "url('/images/pcweek/bg-main-news.gif') left no-repeat";
			}
		}
	}
}

function rotateTopStory()
{
	focusTopStory(currentTopStory);
	currentTopStory = (currentTopStory + 1) % numTopStories;
	topStoryTimer = setTimeout("rotateTopStory()", 4000);
}

function mouseoverTopStory(n)
{
	if(topStoryTimer)
	{
		clearTimeout(topStoryTimer);
	}
	focusTopStory(n-1);
}

function mouseoutTopStory(n)
{
	currentTopStory = n-1;
	if(topStoryTimer)
	{
		clearTimeout(topStoryTimer);
	}
	topStoryTimer = setTimeout("rotateTopStory()", 4000)
}

function initTopStoryBox()
{
	inittopstory=1;
	var topStoryBox = document.getElementById('top-stories');
	var topStoryContainer = topStoryBox.getElementsByTagName('ul');
	topStoryTeasers = topStoryBox.getElementsByTagName('img');
	topStoryIntros = topStoryBox.getElementsByTagName('p');
	topStoryHeadlines = topStoryContainer[0].getElementsByTagName('a');
	numTopStories = topStoryTeasers.length;
	currentTopStory = 0;
	rotateTopStory();
}
