// the fade array
// we store the id's that are busy fading in or out
// this way we can check if an id is fading in then we know we can't fade out yet
var fa = new Array();

function sFa(id)
{
	fa[id] = "in";
	// and we are not busy fading this id
	if( fa["busy_fading_"+id] != 1 )
	{
		fa["busy_fading_"+id] = 1;
		fd(0,id);
	}
}

function hFa(id)
{
	fa[id] = "out";
	// and we are not busy fading this id
    if( fa["busy_fading_"+id] != 1 )
	{
		fa["busy_fading_"+id] = 1;
		fd(0,id); // was fd(100,id) to make it fade in and out
	}
}

function fd(t,id)
{
	var amt = 0;

	// if we are fading out
	if( fa[id] == "out" )
	{
		t -= 2;
		if( t <= 0 )
		{
			t = 0;
			fa["busy_fading_"+id] = 0;
		}
		var amt = Math.abs(t);
	}
	// if we are fading in
	if( fa[id] == "in" )
	{
		t += 2;
		if( t >= 100 )
		{
			t = 100;
			fa["busy_fading_"+id] = 0;
		}
		var amt = Math.abs(t);
	}

	obj = document.getElementById(id);

	obj.style.filter = "alpha(opacity:"+amt+")";
	obj.style.KHTMLOpacity = amt/100;
	obj.style.MozOpacity = amt/100;
	obj.style.opacity = amt/100;
	
	// if opacity is 0 and we are fading out
	if( amt == 0 && fa[id] == "out" ) obj.style.display = 'none';
	// else if we are fading in and we are just beginning to show the object
	else if( amt > 0 && fa[id] == "in" && obj.style.display != 'block' ) obj.style.display = 'block';

	// now call this function again to fade it out (or in) even more
	if(amt != 0 && amt != 100)
	{
		setTimeout("fd("+t+",'"+id+"');",45);
		//document.getElementById('clock').innerHTML = "Fading " + fa[id] + " id: " + id + " at " + amt + "%";
	}
}
