var pics = new Array();
var index = new Array();

var step = 3;
var speed = 40;
var refresh_rate = 6000;
var zindex = 50;

function next_tag(tag)
{
	if (document.getElementById(tag+"_"+(index[tag] + 1)))
	{
		return (index[tag] + 1);
	}
	else
	{
		return 0;
	}
}

function rotate(tag, opac, delay)
{
	if (index[tag] == null)
	{
		// Start fresh
		index[tag] = 0;
		
		var base = document.getElementById(tag+"_"+index[tag]);
		var float = document.getElementById(tag+"_"+next_tag(tag));
	
		base.style.zIndex = index[tag];
		base.style.filter = "alpha(opacity=100)";
		base.style.opacity = "1.0";
	
		float.style.zIndex = (index[tag] + 1);
		float.style.filter = "alpha(opacity=0)";
		float.style.opacity = "0.0";
		setTimeout("rotate('"+tag+"', "+(opac + step)+")", (delay ? (refresh_rate / 2) : refresh_rate));
	}
	else
	{
		var base = document.getElementById(tag+"_"+index[tag]);
		var float = document.getElementById(tag+"_"+next_tag(tag));
	
		base.style.filter = "alpha(opacity="+(100-opac)+")";
		base.style.opacity = ((100-opac) / 100);
	
		float.style.filter = "alpha(opacity="+opac+")";
		float.style.opacity = (opac / 100);
		
		if (opac < 100)
		{
			setTimeout("rotate('"+tag+"', "+(opac + step)+")", speed);
		}
		else
		{
			next_pic(tag);
		}
	}
}

function next_pic(tag)
{
	var base = document.getElementById(tag+"_"+index[tag]);
	base.style.filter = "alpha(opacity=0)";
	base.style.opacity = "0.0";
	
	index[tag] = next_tag(tag);
	var base = document.getElementById(tag+"_"+index[tag]);
	var float = document.getElementById(tag+"_"+next_tag(tag));
	
	base.style.zIndex = index[tag];
	base.style.filter = "alpha(opacity=100)";
	base.style.opacity = "1.0";

	float.style.zIndex = (index[tag] + 1);
	float.style.filter = "alpha(opacity=0)";
	float.style.opacity = "0.0";
	setTimeout("rotate('"+tag+"', 0)", refresh_rate);
}

function start_new_rotate(tag, new_pic)
{
	var float = document.getElementById(tag+"_2");
	
	float.style.filter = "alpha(opacity=0)";
	float.style.opacity = "0.0";
	float.innerHTML = "<img src='" + new_pic + "' border='0' />";
	
	setTimeout("rotate('"+tag+"', 0)", refresh_rate);
}
