var activeElement = null;
var activeButton = null;
var currentButton = null;
var currentImage = null;
var hideTimer = null;

function menuOn(buttonId, imageName) {
	if (currentButton != null && currentButton != buttonId) {
		document.getElementById(buttonId).src = 'images/menu/' + imageName + '_on.gif';
	}
}

function menuOff(buttonId, imageName) {
	if (currentButton != null && currentButton != buttonId) {
		document.getElementById(buttonId).src = 'images/menu/' + imageName + '_off.gif';
	}
}

function setCurrentMenu(buttonId, imageName) {
	if (imageName != null && imageName != '') {
		document.getElementById(buttonId).src = 'images/menu/' + imageName + '_on.gif';
	}
	currentButton = buttonId;
	currentImage = imageName;
}

function showMenu(id, buttonId) {
	cancelHide();
	var el = document.getElementById(id);
	var button = document.getElementById(buttonId);
	if(activeElement != null) {
		document.getElementById(activeElement).style.visibility = "hidden";
		if (activeButton != currentButton) {
			document.getElementById(activeButton).src = "images/menu/" + activeButton + "_off.gif";
		}
	}
	el.style.visibility = "visible";
	button.src = "images/menu/" + buttonId + "_on.gif";
	activeElement = id;
	activeButton = buttonId;
}

function hideMenu(id) {
	hideTimer = setTimeout("clearMenu()", 100);
}

function clearMenu() {
	if(hideTimer != null) {
		if(activeElement != null) {
		    document.getElementById(activeElement).style.visibility = "hidden";
			if (activeButton != currentButton) {
				document.getElementById(activeButton).src = "images/menu/" + activeButton + "_off.gif";
			}
		}
	}
}

function cancelHide() {
	clearTimeout(hideTimer);
	hideTimer = null;
}

