var headlines = 0;
var amt = 5;
var spd = 50;
var hangtime = 9000;
var running = false;

function rotate(num) {
	var last = num - 1;
	if (last <= 0) last = headlines;
    if (num > headlines) num = 1;
	if (running) fade(last,num,0,1);
	else fade(last,num,100,1);
	running = true;
}

function fade(last,id,opac,up) {
	// If starting out, show cover layer
	if (up && !opac) {
	  if (document.all) document.all['cover'].style.display = 'block';
	  else if (document.getElementById) document.getElementById('cover').style.display = 'block';	
	}
	// If we've hit the top, set to go back down
	if (up && opac > 100) {
		// Hide old one
	  	if (document.all) document.all['headline'+last].style.display = 'none';
		else if (document.getElementById) document.getElementById('headline'+last).style.display = 'none';
		// Show the new one
		if (document.all) document.all['headline'+id].style.display = 'block';
		else if (document.getElementById) document.getElementById('headline'+id).style.display = 'block';
		setTimeout('fade('+last+','+id+',90,0)',spd);
		return;
	}
	
	// If we're done, rotate again in x seconds
	if (opac < 0) {	  
	  if (document.all) document.all['cover'].style.display = 'none';
	  else if (document.getElementById) document.getElementById('cover').style.display = 'none';	  
	  if (headlines > 1) setTimeout('rotate('+(id+1)+')',hangtime);
	  return;
	}
	
	// Set opacity of cover
    if (document.all) document.all['cover'].filters.alpha.opacity = opac;
	else if (document.getElementById) document.getElementById('cover').style.MozOpacity = opac/100;
	
	if (up) opac += amt;
	else opac -= amt;
	setTimeout('fade('+last+','+id+','+opac+','+up+')',spd);
}

function fade2(id,next,opac) {
    if (!up && opac == 100) {
		// Just Starting
		// Show this headline, and make cover re-appear in x seconds
		if (document.all) document.all['headline'+id].style.display = 'block';
		else if (document.getElementById) document.getElementById('headline'+id).style.display = 'block';
		setTimeout('fade('+id+',0,1)',hangtime);
	}
	if (up && opac >= 100) {
		// Just Ended
		if (document.all) document.all['headline'+id].style.display = 'none';
		else if (document.getElementById) document.getElementById('headline'+id).style.display = 'none';
		rotate((id+1));
		return;
	}
	// Too high, gotta quit
    if (up && opac > 100) return;
        
    // Set opacity
    if (document.all) document.all['cover'].filters.alpha.opacity = opac;
	else if (document.getElementById) document.getElementById('cover').style.MozOpacity = opac/100;
    

}
