/* Fading Menus
   By Tommy Cavalli */

var fadeMenus = {
	attClass : 'pheader',	// ClassName for header of fading menus.
	timeout : 20,		// Speed of fade in/out (1=fastest)
	initHeight : 0,
	init : function()
	{
		// Check if browser supports needed functions
		if ( !document.getElementById || !document.getElementsByTagName )
			return;

		var i;
		var allDivs = document.getElementsByTagName("div");
		var amntDivs = allDivs.length;
		for(i=0; i<amntDivs; i++)
		{
			if(allDivs[i].className==this.attClass)
			{
				var dID=allDivs[i].id;		// Get ID of this DIV
				var subDiv=document.getElementById(dID.toString()+'c'); // look for elements with the same ID appended with a "c"
				if(subDiv) // If there is one, set everything up
				{
					subDiv.style.opacity='0';
					subDiv.style.filter="alpha(opacity:0)";
					subDiv.style.display='none';
					allDivs[i].onclick=this.toggle;
					allDivs[i].style.backgroundImage="url(imgs/adown.jpg)";
					allDivs[i].style.backgroundPosition="top left";
				}
			}
		}
		this.initHeight=parseInt(document.getElementById("subMain").clientHeight);
		fixHeights();
	},
	toggle : function()
	{
		var myID = this.id;
		var subDiv=document.getElementById(myID.toString()+'c');
		if(subDiv)
		{
			if(subDiv.style.opacity=='0')
			{
				this.style.backgroundImage="url(imgs/aup.jpg)";
				this.style.backgroundPosition="top left";
				subDiv.style.display='block';
				fixHeights();
				fadeMenus.fade(subDiv, 10);
			}
			else
			{
				fadeMenus.fade(subDiv, -90);
				this.style.backgroundImage="url(imgs/adown.jpg)";
				this.style.backgroundPosition="top left";
			}
		}
		return false;
	},
	fade : function(obj, opac)
	{
		var newOpac=parseInt(opac);
		if(newOpac<100 && newOpac!=0)
		{
			obj.style.opacity='.'+Math.abs(newOpac);
			obj.style.filter="alpha(opacity:"+Math.abs(newOpac)+")";
			newOpac+=10;
			setTimeout("fadeMenus.fade(document.getElementById('"+obj.id+"'),'"+newOpac+"')",this.timeout);
		}
		else
		{
			newOpac=(newOpac==0 ? 0 : 1);
			obj.style.opacity=newOpac;
			obj.style.filter="alpha(opacity:"+(100*newOpac)+")";
			if(newOpac==0)
			{
				obj.style.display='none';
				fixHeights();
			}
		}
	}
};

function fixHeights() // Because floating elements in firefox do not resize their container elements
{			// IE does, but letting this run in IE too looks good, so no need to check.
	var ls=document.getElementById("leftSide");
	var sm=document.getElementById("subMain");
	var li=document.getElementById("lastItem");
	if(ls && sm)
	{
		var lsH=parseInt(ls.clientHeight) + 12; // Add 12 to compensate for padding
		var newHeight=(fadeMenus.initHeight>lsH ? fadeMenus.initHeight : lsH);
		if(li)
		{
			var spacer=document.getElementById("spacer");
			if(spacer)
			{
				if(navigator.appName == "Microsoft Internet Explorer")
					spacer.style.height=parseInt(lsH)+parseInt(sm.offsetTop)-parseInt(spacer.offsetTop)-48+'px';
				else
					spacer.style.height=parseInt(lsH)+parseInt(sm.offsetTop)-parseInt(spacer.offsetTop)-4+'px';
			}
			var liH=parseInt(li.offsetTop)+parseInt(li.clientHeight)+12-parseInt(sm.offsetTop);
			if(liH>newHeight)
				newHeight=liH;
		}
		sm.style.height=newHeight+'px';
	}
}

// window.onload=function() { fadeMenus.init(); }

function FMloader()
{
	fadeMenus.init();
}
addEvent(window,'load',FMloader);
