var current_selected_menu_id='-1';
var current_menu_mouse_over='-1';
var rollOutInProcess=false;
var rollInInProcess=false;
var intPrevOffsetHeight=-1;
var intRollInterval=7;
var intHeightStep=15;
var colOpeningMenus = new Object();
var colMenuHeights = new Object();



function intMenuHeight(id) {
	intHeight=0;
	objId=document.getElementById(id);
	
	for(i=0;i<objId.childNodes.length;i++) {
		objChild=objId.childNodes[i];		
		if (objChild.tagName) {
			if (objChild.tagName=="A") {
				intHeight=intHeight + 17;
			}
		}
	}
	
	colMenuHeights[id]=intHeight;
	
	return intHeight;
}

function showMenu(id,clicked) {
	if (!clicked) {
		if ((!rollOutInProcess) && (!rollInInProcess)) {
			if (id!=current_selected_menu_id) {
				current_menu_mouse_over=id;
				setTimeout("showMenuPhase2('"+id+"')",700);
			}
		}
	} else {
		current_menu_mouse_over=id;
		showMenuPhase2(id);
	}
}

function showMenuPhase2(id) {
	if (current_menu_mouse_over==id) {
		if (id!=current_selected_menu_id) {			
			showSubMenu(id);
			current_selected_menu_id=id;
		}
	}
}

function showSubMenu(id) {	
	rollOut(id);	
}

function rollOut(toRollOutDivId) {

	/*
	for (var id in colOpeningMenus) {
		if ((colOpeningMenus[id]==1) && (id!=toRollOutDivId)) {
			// stil waiting for a menu to close, come back later.				
			// setTimeout("rollOut('"+toRollOutDivId+"')",intRollInterval);
			// return;
		}
	}
	*/
	
	if (!rollOutInProcess)  {		
		try {
			objDivToRollOut=document.getElementById(toRollOutDivId);			
			// set properties on the to roll out div	
			objDivToRollOut.style.overflow="hidden";
			objDivToRollOut.style.height="0px";
			objDivToRollOut.style.display="block";			
			intHeight=0;
			colOpeningMenus[toRollOutDivId]=1;
			rollOutInProcess=true;
			setTimeout("rollOutPhase2('"+toRollOutDivId+"'," + intHeight + ")",intRollInterval);
		} catch(e) {
		}
	}
}

function rollOutPhase2(id,intHeight) {
	try {
		objDivToRollOut=document.getElementById(id);
		intHeight=intHeight+intHeightStep;
		
		if (colOpeningMenus.id) {
			intMaxHeight=colOpeningMenus[id];
		} else {
			intMaxHeight=intMenuHeight(id);
		}
		
		if (intHeight>intMaxHeight) intHeight=intMaxHeight;
		objDivToRollOut.style.height=intHeight + "px";
		
		if (intHeight<intMaxHeight) {
			setTimeout("rollOutPhase2('"+id+"'," + intHeight +")",intRollInterval);
		} else {
			rollOutInProcess=false;				
		}	
	} catch (e) {
		rollOutInProcess=false;		
	}
}



function rollInAll() {
	if (!rollOutInProcess)  {
		rollInInProces=false;
		for (var id in colOpeningMenus) {			
			if ((colOpeningMenus[id]==1) && (id!=current_selected_menu_id)) {							
				try {				
					objDivToRollIn=document.getElementById(id);
					if (objDivToRollIn.style.display=="block") {						
						intHeight=objDivToRollIn.offsetHeight;						
						intHeight=intHeight-intHeightStep;						
						if (intHeight<0) {
							// finished!
							intHeight=0;
							objDivToRollIn.style.display="none";
							colOpeningMenus[id]=0;							
						} else {
							// not finished
							rollInInProces=true;
						}
						objDivToRollIn.style.height=intHeight + "px";			
					}
				} catch(e) {			
				}			
			}
		}
	}
	setTimeout("rollInAll()",intRollInterval);	
}