// JavaScript Document
var last_expanded = ''; 

function showHide(cat) 
{ 
	var catObj = document.getElementById(cat); 

	if(catObj != undefined)
	{
		var status = catObj.className;
		
		if (status == 'hide') { 
			if (last_expanded != '') { 
				var last_obj = document.getElementById(last_expanded); 
				collapseMenu(last_obj);
			} 

			expandMenu(catObj);
			last_expanded = cat;
		} else { 
			collapseMenu(catObj);
		} 
	}
} 


function show(cat) 
{ 
	var catObj = document.getElementById(cat); 

	if(catObj != undefined)
	{
		var status = catObj.className;
		
		if (status == 'hide') 
		{ 
			if (last_expanded != '') 
			{ 
				var last_obj = document.getElementById(last_expanded); 
				collapseMenu(last_obj);
			} 

			expandMenu(catObj);
			last_expanded = cat;
		} 
	}
} 


function hide(cat) 
{ 
	var catObj = document.getElementById(cat); 

	if(catObj != undefined)
	{
	  collapseMenu(catObj);	
	}
} 

function expandMenu(cat) {
	var speed = 3;
	var fullHeight = 0;
	var links = cat.getElementsByTagName("li");

	for (var i = 0; i < links.length; i++)
	{
		fullHeight += links[i].offsetHeight;
	}
	var moveBy = Math.round(speed * links.length);
	
	var intId = setInterval(function() {
		var curHeight = cat.offsetHeight;
		var newHeight = curHeight + moveBy;

		if (newHeight < fullHeight)
			cat.style.height = newHeight + "px";
		else {
			clearInterval(intId);
			cat.style.height = "";
			cat.className = "show";
		}
	}, 30);
};

function collapseMenu(cat){
	var speed = 3;

	var minHeight = 0;
	var moveBy = Math.round(speed * cat.getElementsByTagName("li").length);

	var intId = setInterval(function() {
		var curHeight = cat.offsetHeight;
		var newHeight = curHeight - moveBy;
		if (newHeight > minHeight)
		{
			cat.style.height = newHeight + "px";
		}
		else {
			clearInterval(intId);
			cat.style.height = "";
			cat.className = "hide";
		}
	}, 30);
};
