/*

By Patrik Larsson
ICA Ltd.
patrik@ica.com.mt

Use if you feel like

*/

var layerOut = 0;
var layerIn = 0;

function slideMenu(which)
{
	if(layerIn!=0 && layerIn!=which)
	{
		layerOut=layerIn;	
	}
	layerIn = which;
	//alert(innerDiv.clientHeight);
}

function doSlide(which,isIn)
{
	var holderDiv = document.getElementById("holder" + which);
	var innerDiv = document.getElementById("inner" + which);
	
	var hHeight=holderDiv.clientHeight;
	var iHeight=innerDiv.clientHeight;
	
	var step;
	
	
	var smoothSteps = 25;
	var step=smoothSteps;

	if(hHeight<smoothSteps)
	{
		step=hHeight+1;
	}
	else if(hHeight>iHeight-smoothSteps)
	{
		step=(iHeight-hHeight)+1;
	}

	//step=Math.round(iHeight/10)

	var change = isIn ? step : -step;
	

	if(hHeight<=iHeight)
	{
		var newHeight=hHeight+change;
		if(newHeight<0)
		{
			newHeight=0;
			layerOut=0;
		}
		if(newHeight>=iHeight)
		{
			newHeight=iHeight;	
		}
		holderDiv.style.height=newHeight;
	}
	
	//document.getElementById("log").value = "Moving: " + which + "\nIn/Out: " + isIn + "\nnewHeight: " + newHeight + "\nchange: " + change + "\nlayerIn: " + layerIn + "\nlayerOut: " + layerOut;
}

function animateMenu()
{
	if(layerOut!=0)
	{
		doSlide(layerOut,false);	
	}
	else if(layerIn>0)
	{
		doSlide(layerIn,true);	
	}
	setTimeout("animateMenu()",30);	
}
