var menuBg = "none";
var menuHideDelay = 650;
var menuStyle = "width:25px;";

function createMenuHtml(name, items) {
	// Initialize
	var html = "";

	// Generate the menu contents
	html += '<table border="0" cellpadding="0" cellspacing="0" onselectstart="return false;">';
	html += '<tr>';
	html += '	<td rowspan="' + (items.length*2+1) + '"><img src="/departments/public_works/images/spacer.gif" width="20" height="1"></td>';
	html += '	<td rowspan="' + (items.length*2+1) + '" bgcolor="white"><img src="/departments/public_works/images/spacer.gif" width="7" height="1"></td>';
	html += '	<td bgcolor="white"><img src="/departments/public_works/images/spacer.gif" width="1" height="1"></td>';
	html += '	<td width="12" valign="top"><img src="/departments/public_works/images/menu_top.gif" width="12" height="12"></td>';
	html += '</tr>';
	for (var i = 0; i < items.length; i++) {
		if (i > 0) {
			html += '<tr>';
			html += '	<td height="14" bgcolor="white"><img src="/departments/public_works/images/spacer.gif" width="1" height="14"></td>';
			html += '	<td width="12" height="14" bgcolor="white"><img src="/departments/public_works/images/spacer.gif" width="12" height="1"></td>';
			html += '</tr>';
		}
		html += '<tr>';
		html += '	<td height="15" bgcolor="white"><table border="0" cellpadding="0"><tr>';
		html += '		<td><img src="/departments/public_works/images/menu_arrow.gif" width="4" height="7" hspace="8"></td>';
		html += '		<td nowrap class="menu" style="cursor:pointer; cursor:hand;" onclick="location.href = \'' + items[i][1]+ '\';"><a';
		html += '			href="' + items[i][1] + '">' + items[i][0] + '&nbsp;&nbsp;</a></td></tr></table></td>';
		html += '	<td width="12" height="14" bgcolor="white"><img src="/departments/public_works/images/spacer.gif" width="12" height="1"></td>';
		html += '</tr>';
	}
	html += '<tr>';
	html += '	<td bgcolor="white"><img src="/departments/public_works/images/spacer.gif" width="1" height="12"></td>';
	html += '	<td width="12" height="12"><img src="/departments/public_works/images/menu_bottom.gif" width="12" height="12"></td>';
	html += '</tr>';
	html += '</table>';
	return html;
}

function createMenu(name, items) {
	// Create the menu
	var menu = new PopupMenu(name, createMenuHtml(name, items), menuBg, menuHideDelay, menuStyle);
	return menu;
}

function openMenu(menuIdx, xOffset, yOffset) {
	var xOff = xOffset;
	var yOff = 0;

	if (typeof(xOff) == 'undefined')
	{
		xOff = 150;
		yOff = -5;
	}
	else
	{
		if (document.all)
		{
			xOff += 42;
			yOff += 126;
		}
		else
		{
			if(yOffset != 0) yOff=yOffset;
			if(xOffset == 262) xOff=xOff+200;
			
			
		}
	}
	//alert(xOffset);
	
	//alert(xOff +  " " + yOff);
	menus[menuIdx].Show(xOff, yOff);
}

/*
function openMenu() {
	len = openMenu.length;
	var menuIdx;
	var xOff;
	var yOff;
	var yOffset;
	alert(len);
	switch (len)
	{//simulates two overloaded functions
		case 2:
			menuIdx = openMenu[0];
			xOff = openMenu[1];
			yOff = 0;
			yOffset = 0;
			break;
		case 3:
			menuIdx = openMenu[0];
			xOff = openMenu[1];
			yOff = openMenu[2];
			yOffset = openMenu[2];
			break;
          
        }//end switch statement

	
	if (typeof(xOff) == 'undefined')
	{
		xOff = 150;
		yOff = -5;
	}
	else
	{
		if (document.all)
		{
			xOff += 42;
			yOff += 126;
		}
	}
	if(yOffset != 0) yOff=yOffset;
	//alert(xOff +  " " + yOff);
	menus[menuIdx].Show(xOff, yOff);
}
*/
function openItem(menuName, url) {
	popupMenus.map[menuName].Hide(true);
	location.navigate(url);
}

// Create the menu objects
var menus = new Array();

if (typeof(menuItems) != 'undefined') {
	for (var i = 0; i < menuItems.length; i++) {
		if (menuItems[i][2]) menus[i] = createMenu(String(i), menuItems[i][2]);
	}
}
