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/police/_img/spacer.gif" width="25" height="1"></td>';
	html += '	<td rowspan="' + (items.length*2+1) + '" bgcolor="white"><img src="/departments/police/_img/spacer.gif" width="7" height="1"></td>';
	html += '	<td bgcolor="white"><img src="/departments/police/_img/spacer.gif" width="1" height="1"></td>';
	html += '	<td width="12" valign="top"><img src="/departments/police/_img/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/police/_img/spacer.gif" width="1" height="14"></td>';
			html += '	<td width="12" height="14" bgcolor="white"><img src="/departments/police/_img/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/police/_img/img_arrow.gif" width="15" height="15" hspace="8"></td>';
		html += '		<td nowrap class="menu" style="cursor:pointer; cursor:hand;" onclick="location.href = \'' + items[i][1] + '\';"><a';
		html += '			="' + items[i][1] + '">' + items[i][0] + '&nbsp;&nbsp;</a></td></tr></table></td>';
		html += '	<td width="12" height="14" bgcolor="white"><img src="/departments/police/_img/spacer.gif" width="12" height="1"></td>';
		html += '</tr>';
	}
	html += '<tr>';
	html += '	<td bgcolor="white"><img src="/departments/police/_img/spacer.gif" width="1" height="12"></td>';
	html += '	<td width="12" height="12"><img src="/departments/police/_img/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) {
	menus[menuIdx].Show(145, -5);
}

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]);
	}
}
