/************************************************************************/
/***  Stacked Menu Code		 					***/
/***  Version beta 1, last updated 1/8/08              			***/
/***  For more code like this, please visit http://cloudmill.net	***/
/************************************************************************/


var SM_MaxHeight = [[60, 420]];		// menu height, content height
var SM_ShrinkTimer = [];
var SM_Open = [[0,0]];		//array... where x=menu number, y=0/1 where 0=menu, 1=contents ... values 0,1
var SM_cOpen;			//array of 0/1
var SM_SelectedNum;
var SM_IdPrefix = "m";
var SM_ContentsIdPrefix = "cm";
var SM_TimeVar = 18;
var SM_HideMenus = 0;		//0/1 = false/true

function SelectStack (MyNum, MyHideMenus) {
	
	//alert(document.getElementById(mid).style.height);

	var MymID = SM_IdPrefix + MyNum;
	var MycID = SM_ContentsIdPrefix + MyNum;
	var HideMenus;
	
	if (SM_HideMenus == 1 || MyHideMenus == 1) HideMenus = 1;
	
	
	SM_SelectedNum = MyNum;				// mark this one as selected
	
	// toggle contents
	
	if (SM_Open[MyNum-1][1] == 0) {			// if contents are closed then OPEN
	
		StartExpand(SM_ContentsIdPrefix, MyNum, SM_TimeVar, SM_MaxHeight[MyNum-1][1], 1);
		
		if (HideMenus) {	
			for (var i=1; i <= SM_Open.length; i++)				// hide all other menus
			{
				if (i != MyNum && SM_Open[i-1][0] == 1) {
						StartShrink(SM_IdPrefix, i, SM_TimeVar, SM_MaxHeight[i-1][0], 0);
				}
			}
		}
		for (var i=1; i <= SM_Open.length; i++)				// hide all other contents
		{
			if (i != MyNum && SM_Open[i-1][1] == 1)
					StartShrink(SM_ContentsIdPrefix, i, SM_TimeVar, SM_MaxHeight[i-1][1], 0);
		}
			
	} else {
	
		StartShrink(SM_ContentsIdPrefix, MyNum, SM_TimeVar, SM_MaxHeight[MyNum-1][1], 1);	// CLOSE

		for (var i=1; i <= SM_Open.length; i++)		// make sure to show all menus
		{
			if (SM_Open[i-1][0]==0) {
				StartExpand(SM_IdPrefix, i, SM_TimeVar, SM_MaxHeight[i-1][0], 1);
			}
		}
	}
	
}


function StartExpand (MyPrefix, MyN, Time, MaxHeight, DoFade) {

	var MyId = MyPrefix + MyN;
	document.getElementById(MyId).style.display = "block";
	doShrink(MyPrefix, MyN, Time, MaxHeight, DoFade, 1, 0);
}

function StartShrink (MyPrefix, MyN, Time, MaxHeight, DoFade) {

	doShrink(MyPrefix, MyN, Time, MaxHeight, DoFade, -1, 100);
}


function doShrink (MyPrefix, MyNum, Time, MaxHeight, DoFade, Direction, Percent) {

	var MyId = MyPrefix + MyNum;
	var MyObj = document.getElementById(MyId);
	var MyType;
	if (MyPrefix == SM_IdPrefix) MyType = 0;
	else MyType = 1;

	Percent = Percent + (Direction * 5);
	Time = Time * 0.5;
	
	MyObj.style.height = MaxHeight * (Percent/100) +"px";
	if (DoFade==1) Opacity(MyObj, (Percent/100));

	if(Percent <= 0 && Direction == -1) {
		
		SM_Open[MyNum-1][MyType] = 0; //marked closed
;
		
		MyObj.style.display = "none";
		
	} else if(Percent >= 100 && Direction == 1) {
		
		SM_Open[MyNum-1][MyType] = 1; //marked open


	} else {
		var fn = "doShrink('"+ MyPrefix +"',"+ MyNum +","+ Time +","+ MaxHeight +","+ DoFade +","+ Direction +","+ Percent+")";
		SM_ShrinkTimer[MyNum-1] = setTimeout(fn, Time);
	}

}




/***~~~~ Generic Functions ~~~~~***/


function Opacity (TheObj, Op) {
	TheObj.style.opacity = Op;					//standard
	TheObj.style.filter = 'alpha(opacity=' + Op * 100 + ')';	//IE
}


