

	function getOffsets (target) 
	{
		if (typeof target.offsetLeft == 'undefined') {
			target = target.parentNode;
		}
		var pageCoords = getPageCoords(target);

		var offsets = {
			offsetX: pageCoords.x,
			offsetY: pageCoords.y
		}
		return offsets;
	}

	function getPageCoords (element) {
	  var coords = {x : 0, y : 0};
	  while (element) {
		coords.x += element.offsetLeft;
		coords.y += element.offsetTop;
		element = element.offsetParent;
	  }
	  return coords;
	}

	var timeout_hide = new Array();
	var timeout_hide_val = 1 * 100; // 1 second
	var menu_hide_selects = true;
	var last_catID = -1;

	function ShowSub(catID, selected, obj)
	{
		var last = document.getElementById("menu_sub" + last_catID);
		if (last)
		{
			if (last.style)
				last.style.visibility = "hidden";
		}

		ShowHideSub(catID, selected, obj.id, 1);
	}


	function HideSub(catID, selected, obj)
	{
		timeout_hide[catID] = setTimeout('ShowHideSub(' + catID + ', ' + selected + ', "' + obj.id + '",0)',timeout_hide_val);
	}

	function ShowHideSub(catID, selected, obj, on)
	{
		var theSub = document.getElementById("menu_sub" + catID);

		if (!theSub) return;
		if (!theSub.style) return;

		if (typeof(obj) == "string")
			obj = document.getElementById(obj);

		if (on)
		{
			clearTimeout(timeout_hide[catID]);
			
			var menuleft = document.getElementById("menuleft");
			if (menuleft)
			{
				menuleft = getOffsets(menuleft);
				menuleft = menuleft.offsetX;
			}

			if (!menuleft)
				menuleft = 156;

			var offsets = getOffsets(obj);
			var menutop = offsets.offsetY;
			var ua = navigator.userAgent.toLowerCase();

			if (ua.indexOf("msie") > -1 && ua.indexOf("mac") > -1)
				menutop-=74;

			if (window.innerHeight) 
				var window_height = window.innerHeight;
			else 
				var window_height = document.body.clientHeight;

			if (window.pageYOffset)
				var window_top = window.pageYOffset;
			else
				var window_top = document.body.scrollTop;

			window_top = parseInt(window_top);

			//document.title = "WinHeight=" + window_height + ", WinY=" + window_top + ", SubHeight=" + theSub.offsetHeight + ", SubY=" + menutop;

			if ((menutop + theSub.offsetHeight + 5) > (window_height + window_top))
				menutop = window_top + (window_height - theSub.offsetHeight - 5);

			theSub.style.top = menutop + "px";
			theSub.style.left = menuleft + "px";

			theSub.style.visibility = "visible";

			// need to hide all selects
				if (menu_hide_selects)
				{
					var theSelects = document.getElementsByTagName("select");
					for (var i = 0; i < theSelects.length; i++)
					{
						theSelects[i].style.visibility = "hidden";
					}

				}

			last_catID = catID;
		}
		else
		{
			theSub.style.visibility = "hidden";
			// need to show all selects
				if (menu_hide_selects)
				{
					var theSelects = document.getElementsByTagName("select");
					for (var i = 0; i < theSelects.length; i++)
					{
						theSelects[i].style.visibility = "visible";
					}
				}
		}

		Hilite(obj, on, selected);

	}

	function MouseOutSub(catID, selected, obj)
	{
		if (typeof(obj) == "string")
			obj = document.getElementById(obj);

		HideSub(catID, selected, obj);
	}

	function MouseOverSub(catID, selected, obj)
	{
		ShowSub(catID, selected, document.getElementById(obj));
	}

