current_menu = "";
menu_on = 0;

function buildMenu(menu_name, menu_array, menu_width)
{
	// [0] - Background Color
	// [1] - Border Color
	// [2] - Highlight Color
	// [5] - Link Name
	// [6] - Link HREF
	// [7] - Link Target
	
	if (menu_width != -1)
	{
		output_width = "width=" + menu_width
	}
	else
	{
		output_width = ""
	}

	document.write("<span id=\"" + menu_name + "\" style=\"position: absolute;  display: none;\" onMouseOver=\"stopTimer();\" onMouseOut=\"startTimer();\">\n");
	document.write("<table border=0 cellpadding=0 cellspacing=0 " + output_width + "background=\"images/trans.gif\" bgcolor=\"" + menu_array[0] + "\">\n");
	
	for (i = 3; i < menu_array.length; i = i + 3)
	{
		if (menu_array[i] == "")
		{
			break;
		}
	
		document.write("<tr>\n");
	
		if (i == 3)
		{
			document.write("<td id=\"" + menu_name + i + "\" style=\"border: 1px solid #" + menu_array[1] + ";\">\n");
		}
		else
		{
			document.write("<td id=\"" + menu_name + i + "\" style=\"border-bottom: 1px solid #" + menu_array[1] + "; border-left: 1px solid #" + menu_array[1] + "; border-right: 1px solid #" + menu_array[1] + ";\"\n");
		}
		
		document.write("<span onClick=\"goUrl('" + menu_array[i+1] + "', '" + menu_array[i+2] + "');\" onMouseOver=\"stopTimer(), menuItemOn('" + menu_name + i + "', '" + menu_array[2] + "');\" onMouseOut=\"menuItemOff('" + menu_name + i + "', '" + menu_array[0] + "');\">\n");
		document.write("<table border=0 cellpadding=0 cellspacing=0><tr><td class=\"dhtml_link_cell\" width=\"100%\">\n");
		
		if (menu_array[i+2] == "")
		{
			document.write("<a class=\"dhtml_link\" href=\"" + menu_array[i+1] + "\">" + menu_array[i] + "</a>\n");
		}
		else
		{
			document.write("<a class=\"dhtml_link\" href=\"" + menu_array[i+1] + "\" target=\"" + menu_array[i+2] + "\">" + menu_array[i] + "</a>\n");
		}
		
		document.write("</td></tr></table>\n");
		document.write("</span>\n");
		document.write("</td>\n");
		
		document.write("</tr>\n");
	}
	
	document.write("</table>\n");
	document.write("</span>\n");
}

function menuItemOn(element_name, element_color)
{
	eval("document.getElementById(\"" + element_name + "\").style.background='#" + element_color + "'");
}

function menuItemOff(element_name, element_color)
{
	eval("document.getElementById(\"" + element_name + "\").style.background='#" + element_color + "'");
}

function showMenu(menu_name, side)
{
	if (current_menu != "")
	{
		hideMenu();
	}
	
	current_menu = menu_name;
	
	parentWidth = eval("document.getElementById(\"parent_" + menu_name + "\").offsetWidth");
	parentHeight =  eval("document.getElementById(\"parent_" + menu_name + "\").offsetHeight");


	if (side == "left")
	{
		xPos = getAbsPos("parent_" + menu_name)[0];
		yPos = getAbsPos("parent_" + menu_name)[1];
		
//		xPos -= (eval("document.getElementById(\"" + menu_name + "\").offsetWidth"));
		xPos -= 152;
//		alert(menu_name);
//		yPos -= parentHeight;
	}
	
	if (side == "bottom")
	{
		xPos = getAbsPos("parent_" + menu_name)[0];
		yPos = getAbsPos("parent_" + menu_name)[1];
		yPos += parentHeight + 2;
	}
	
	// show menu
	eval("document.getElementById(\"" + menu_name + "\").style.left='" + xPos + "'");
	eval("document.getElementById(\"" + menu_name + "\").style.top='" + yPos + "'");
	eval("document.getElementById(\"" + menu_name + "\").style.display='block'");
	
}

function hideMenu()
{
	// hide menu
	eval("document.getElementById(\"" + current_menu + "\").style.display='none'");
	current_menu = "";
}

function startTimer()
{
	menu_on = setTimeout("hideMenu()", 500);
}

function stopTimer()
{
	if (menu_on != 0)
	{
		clearTimeout(menu_on);
	}
}

function goUrl(go_url, go_target)
{
	if (go_url != "")
	{
		if (go_target != "")
		{
			window.open(go_url);
		}
		else
		{
			location.href = go_url;
		}
	}
}

function getX(el) 
{ 
	xPos = el.offsetLeft; 
	tempEl = el.offsetParent; 
	while (tempEl != null) 
	{ 
		xPos += tempEl.offsetLeft; 
		tempEl = tempEl.offsetParent; 
	} 
	return xPos; 
} 

function getY(el) 
{ 
	yPos = el.offsetTop; 
	tempEl = el.offsetParent; 
	
	while (tempEl != null) 
	{ 
		yPos += tempEl.offsetTop; tempEl = tempEl.offsetParent; 
	} 
	
	return yPos; 
} 

function getAbsPos(id) 
{ 
	var el = document.all ? document.all(id) : document.getElementById ? document.getElementById(id) : null; 
	
	if (el) 
	{ 
		var trueX = getX(el); 
		var trueY = getY(el); 
	} 
	
	return new Array(trueX, trueY);
} 