var mh_ns4 = false;
var mh_ns5plus = false;
var mh_ie = false;
if (document.layers)
	mh_ns4 = true;
else if ((parseInt(navigator.appVersion) >= 5) && (navigator.appName=="Netscape"))
	mh_ns5plus = true;
else if (document.all)
	mh_ie = true;

var mh_timeoutId = 0;

var mh_menu_displayed = new Array ();
var mh_menu_toBeCleared = new Array ();
var mh_item_displayed = new Array ();
var mh_item_toBeCleared = new Array ();

function mh_display_item (itemId) {
	mh_items[itemId][1] = true;
	if (mh_ie) {
		document.all["mh_item" + itemId].className = mh_items[itemId][3];
		document.all["mh_item" + itemId].style.backgroundImage = "url(" + mh_items[itemId][5] + ")";
	}
	else if (mh_ns5plus) {
		document.getElementById("mh_item" + itemId).className = mh_items[itemId][3];
		document.getElementById("mh_item" + itemId).style.backgroundImage = "url(" + mh_items[itemId][5] + ")";
	}
	else if (mh_ns4) {
		document.layers["mh_item" + itemId].className = mh_items[itemId][3];
		document.layers["mh_item" + itemId].backgroundImage = "url(" + mh_items[itemId][5] + ")";
	}
}

function mh_hide_item (itemId) {
	if (mh_ie) {
		document.all["mh_item" + itemId].className = mh_items[itemId][2];
		document.all["mh_item" + itemId].style.backgroundImage = "url(" + mh_items[itemId][4] + ")";
	}
	else if (mh_ns5plus) {
		document.getElementById("mh_item" + itemId).className = mh_items[itemId][2];
		document.getElementById("mh_item" + itemId).style.backgroundImage = "url(" + mh_items[itemId][4] + ")";
	}
	else if (mh_ns4) {
		document.layers["mh_item" + itemId].className = mh_items[itemId][2];
		document.layers["mh_item" + itemId].backgroundImage = "url(" + mh_items[itemId][4] + ")";
	}
}

function mh_display_menu (itemId) {
	menuId = mh_items[itemId][0];
	if ((mh_menus[menuId][1] != false) || (mh_menus[menuId][2] != false)) {
		for (count = 0; count < mh_item_displayed.length; count++) {
			mh_items[mh_item_displayed[count]][1] = false;
			mh_item_toBeCleared[mh_item_toBeCleared.length] = mh_item_displayed[count];
		}
		for (count = 0; count < mh_menu_displayed.length; count++) {
			mh_menus[mh_menu_displayed[count]][1] = false;
			mh_menu_toBeCleared[mh_menu_toBeCleared.length] = mh_menu_displayed[count];
		}
		mh_menu_displayed.length = 0;
		mh_item_displayed.length = 0;
		mh_menus[menuId][1] = true;
		mh_menu_displayed[mh_menu_displayed.length] = menuId;
		temp = mh_menus[menuId][0];
		while (temp != -1) {
			mh_display_item (temp);
			mh_item_displayed[mh_item_displayed.length] = temp;
			temp = mh_items[temp][0];
			mh_menus[temp][1] = true;
			mh_menu_displayed[mh_menu_displayed.length] = temp;
			temp = mh_menus[temp][0];
		}
		mh_display_item (itemId);
		mh_item_displayed[mh_item_displayed.length] = itemId;
		for (count = 0; count < mh_menus.length; count++){
			if (mh_menus[count][0] == itemId) {
				mh_draw_menu (count);
				mh_menu_displayed[mh_menu_displayed.length] = count;
			}
		}
		mh_clear_menus (false);
	}
}

function mh_draw_menu (menuId) {
	if (mh_menus[menuId][5] == true) {
		if (mh_ie) {
			document.all["mh_menu" + menuId].style.left = mh_get_x_position (menuId, document.all["mh_item" + mh_menus[menuId][0]]) + "px";
			document.all["mh_menu" + menuId].style.top = mh_get_y_position (menuId, document.all["mh_item" + mh_menus[menuId][0]]) + "px";
			document.all["mh_menu" + menuId].style.zIndex = 10;
			if ((mh_useTransitions) && (typeof (document.all["mh_menu" + menuId].filters[0]) != "undefined") && (mh_menus[menuId][1] == false) && (mh_menus[menuId][2] == false))
				document.all["mh_menu" + menuId].filters[0].apply ();
			document.all["mh_menu" + menuId].style.visibility = "visible";
			document.all["mh_menu" + menuId].style.display = "block";
			if ((mh_useTransitions) && (typeof (document.all["mh_menu" + menuId].filters[0]) != "undefined") && (mh_menus[menuId][1] == false) && (mh_menus[menuId][2] == false))
				document.all["mh_menu" + menuId].filters[0].play ();
		}
		else if (mh_ns5plus) {
			document.getElementById("mh_menu" + menuId).style.left = mh_get_x_position (menuId, document.getElementById("mh_item" + mh_menus[menuId][0])) + "px";
			document.getElementById("mh_menu" + menuId).style.top = mh_get_y_position (menuId, document.getElementById("mh_item" + mh_menus[menuId][0])) + "px";
			document.getElementById("mh_menu" + menuId).style.zIndex = 10;
			document.getElementById("mh_menu" + menuId).style.visibility = "visible";
			document.getElementById("mh_menu" + menuId).style.display = "block";
		}
		else if (mh_ns4) {
			document.layers["mh_menu" + menuId].left = mh_get_x_position (menuId, document.layers["mh_item" + mh_menus[menuId][0]]) + "px";
			document.layers["mh_menu" + menuId].top = mh_get_y_position (menuId, document.layers["mh_item" + mh_menus[menuId][0]]) + "px";
			document.layers["mh_menu" + menuId].zIndex = 10;
			document.layers["mh_menu" + menuId].visibility = "show";
			document.layers["mh_menu" + menuId].display = "block";
		}
		mh_menus[menuId][2] = true;
		mh_menus[menuId][1] = true;
		mh_hide_select_inputs ();
	}
}

function mh_highlight_menu (menuId) {
	if (mh_menus[menuId][1] == true) {
		if (mh_ie) {
			document.all["mh_menu" + menuId].className = mh_menus[menuId][7];
		}
		else if (mh_ns5plus) {
			document.getElementById("mh_menu" + menuId).className = mh_menus[menuId][7];
		}
		else if (mh_ns4) {
			document.layers["mh_menu" + menuId].className = mh_menus[menuId][7];
		}
	}
}

function mh_unhighlight_menu (menuId) {
	if (mh_ie) {
		document.all["mh_menu" + menuId].className = mh_menus[menuId][6];
	}
	else if (mh_ns5plus) {
		document.getElementById("mh_menu" + menuId).className = mh_menus[menuId][6];
	}
	else if (mh_ns4) {
		document.layers["mh_menu" + menuId].className = mh_menus[menuId][6];
	}
}

function mh_hide_menu (menuId) {
	if (mh_menus[menuId][4] == false) {
		if (mh_ie) {
			if ((mh_useTransitions) && (typeof (document.all["mh_menu" + menuId].filters[1]) != "undefined"))
				document.all["mh_menu" + menuId].filters[1].apply ();
			document.all["mh_menu" + menuId].style.zIndex = 8;
			document.all["mh_menu" + menuId].style.visibility = "hidden";
			if ((mh_useTransitions) && (typeof (document.all["mh_menu" + menuId].filters[1]) != "undefined"))
				document.all["mh_menu" + menuId].filters[1].play ();
		}
		else if (mh_ns5plus) {
			document.getElementById("mh_menu" + menuId).style.zIndex = 8;
			document.getElementById("mh_menu" + menuId).style.visibility = "hidden";
		}
		else if (mh_ns4) {
			document.layers["mh_menu" + menuId].zIndex = 8;
			document.layers["mh_menu" + menuId].visibility = "hide";
		}
		mh_menus[menuId][2] = false;
		mh_menus[menuId][3] = setTimeout ("mh_remove_menu (" + menuId + ")", mh_menuFaddeOutMS);
	}
}

function mh_remove_menu (menuId) {
	if ((mh_menus[menuId][4] == false) && (mh_menus[menuId][1] == false)) {
		if (mh_ie)
			document.all["mh_menu" + menuId].style.display = "none";
	}
}

function mh_get_x_position (menuId, item) {
	parentItemId = mh_menus[menuId][0];
	if (mh_items[parentItemId][10] != -1)
		return mh_items[parentItemId][10];
	xPos = item.offsetLeft;
	parentItem = item.offsetParent;
	while (parentItem != null) {
		xPos += parentItem.offsetLeft;
		parentItem = parentItem.offsetParent;
	}
	if (mh_items[parentItemId][6] == "right")
		xPos += item.offsetWidth + mh_items[parentItemId][8] - 1;
	else if (mh_items[parentItemId][6] == "left") {
		if (mh_ie)
			xPos -= document.all["mh_menu" + menuId].offsetWidth - mh_items[parentItemId][8] - 1;
		else if (mh_ns5plus)
			xPos -= document.getElementById("mh_menu" + menuId).offsetWidth - mh_items[parentItemId][8] - 1;
		else if (mh_ns4)
			xPos -= document.layers["mh_menu" + menuId].offsetWidth - mh_items[parentItemId][8] - 1;
	}
	else if (mh_items[parentItemId][6] == "same") {
		xPos += mh_items[parentItemId][8];
		if (mh_ns5plus)
			xPos -= 1;
	}
	return xPos;
}

function mh_get_y_position (menuId, item) {
	parentItemId = mh_menus[menuId][0];
	if (mh_items[parentItemId][11] != -1)
		return mh_items[parentItemId][11];
	yPos = item.offsetTop;
	parentItem = item.offsetParent;
	while (parentItem != null) {
		yPos += parentItem.offsetTop;
		parentItem = parentItem.offsetParent;
	}
	if (mh_items[parentItemId][7] == "below")
		yPos += item.offsetHeight + mh_items[parentItemId][9] - 1;
	else if (mh_items[parentItemId][7] == "above") {
		if (mh_ie) {
			document.all["mh_menu" + menuId].style.display = "block";
			yPos -= document.all["mh_menu" + menuId].offsetHeight - mh_items[parentItemId][9] - 1;
		}
		else if (mh_ns5plus)
			yPos -= document.getElementById("mh_menu" + menuId).offsetHeight - mh_items[parentItemId][9] - 1;
		else if (mh_ns4)
			yPos -= document.layers["mh_menu" + menuId].offsetHeight - mh_items[parentItemId][9] - 1;
	}
	else if (mh_items[parentItemId][7] == "same") {
		yPos += mh_items[parentItemId][9];
		if (mh_ns5plus)
			yPos -= 1;
	}
	return yPos;
}

function mh_set_menus_as_clear (menuId) {
	for (count = 0; count < mh_item_displayed.length; count++)
		mh_items[mh_item_displayed[count]][1] = false;
	for (count = 0; count < mh_menu_displayed.length; count++)
		mh_menus[mh_menu_displayed[count]][1] = false;
	clearTimeout (mh_timeoutId);
	mh_timeoutId = setTimeout ("mh_clear_menus (true)", 750);
}

function mh_clear_menus (clearVisible) {
	clearTimeout (mh_timeoutId);
	for (count = 0; count < mh_item_toBeCleared.length; count++) {
		count2 = mh_item_toBeCleared[count];
		if (mh_items[count2][1] == false)
			mh_hide_item (count2);
	}
	for (count = 0; count < mh_menu_toBeCleared.length; count++) {
		count2 = mh_menu_toBeCleared[count];
		if ((mh_menus[count2][4] == false) && (mh_menus[count2][1] == false) && (mh_menus[count2][2] == true))
			mh_hide_menu (count2);
	}
	if (clearVisible) {
		for (count = 0; count < mh_item_displayed.length; count++) {
			count2 = mh_item_displayed[count];
			if (mh_items[count2][1] == false)
				mh_hide_item (count2);
		}
		for (count = 0; count < mh_menu_displayed.length; count++) {
			count2 = mh_menu_displayed[count];
			if ((mh_menus[count2][4] == false) && (mh_menus[count2][1] == false) && (mh_menus[count2][2] == true)) {
				mh_hide_menu (count2);
			}
		}
		mh_show_select_inputs ();
	}
	mh_menu_toBeCleared.length = 0;
	mh_item_toBeCleared.length = 0;
}

function mh_show_select_inputs () {
	var elements = document.getElementsByTagName ("select");
	for (i = 0; i < elements.length; i++){
		elements[i].style.visibility = "visible";
	}
}

function mh_hide_select_inputs () {
	var elements = document.getElementsByTagName ("select");
	for (i = 0; i < elements.length; i++) {
		elements[i].style.visibility = "hidden";
	}
}

