var theMenu;
var theMenuButton;
var theMenuParent;
var nextMenu;
var currentMenu;

function menu_clicked(a) {
	var menuButton = a;
	var menuParent = a.parentNode.parentNode;
	
	d = menuParent.getElementsByTagName('DIV');
	for (i = 0; i < d.length; i++) {
		if (d[i].className == 'menu') {
			menu = d[i];
			break;
		}
	}
	
	if (menu) {
		if (currentMenu) {
			theMenu = currentMenu;
			currentMenu = null;
		}

		if (theMenu) {
			if (theMenu != menu) {
				nextMenu = menu;
			}
			close_menu(theMenu);
		} else {
			open_menu(menu);
		}
		return false;
	} else {
		return true;
	}
}

var animatingMenu;
var targetHeight;
var animator;

function open_menu(menu) {
	menu.parentNode.className = 'opening';
	menuItems = menu.getElementsByTagName('LI');
	animatingMenu = menu;
	targetHeight = menuItems.length * 18 + 7;
	//menu.style.height = menuHeight + 'px';
	menu.style.height = '0px';
	animator = setInterval('slide_open()', 10);
}

function slide_open() {
	if (animatingMenu) {
		h = parseInt(animatingMenu.style.height) + 20;
		if (h >= targetHeight) {
			clearInterval(animator);
			animatingMenu.style.height = 'auto';
			animatingMenu.parentNode.className = 'open';
			theMenu = animatingMenu;
		} else {
			animatingMenu.style.height = h + 'px';
		}
	}
}

function close_menu(menu) {
	menu.parentNode.className = 'opening';
	menuItems = menu.getElementsByTagName('LI');
	animatingMenu = menu;
	targetHeight = menuItems.length * 18 + 7;
	menu.style.height = targetHeight + 'px';
	animator = setInterval('slide_closed()', 10);
}

function slide_closed() {
	if (animatingMenu) {
		h = parseInt(animatingMenu.style.height) - 20;
		if (h <= 0) {
			clearInterval(animator);
			animatingMenu.style.height = 'auto';
			animatingMenu.parentNode.className = 'closed';
			if (nextMenu) {
				open_menu(nextMenu);
				nextMenu = null;
			}
			theMenu = null;
		} else {
			animatingMenu.style.height = h + 'px';
		}
	}
}
