function MenuItem(name, href, pageID){
		this.name = name;
		this.href = href;
		this.pageID = pageID;
		this.parent = null;
		this.children = null;
		this.isInPath = false;
}
PAGEID_TEMPLATE = 999;
PAGEID_HOME = 0;
PAGEID_TOPSCORELIST = 1;
PAGEID_TOPSCORELIST_KLONDIKE = 11;
PAGEID_TOPSCORELIST_GOLF = 12;
PAGEID_TOPSCORELIST_SEAHAVENTOWERS = 13;
PAGEID_SCREENSHOTS = 8;
PAGEID_SCREENSHOTS1 = 81;
PAGEID_SCREENSHOTS2 = 82;
PAGEID_SCREENSHOTS3 = 83;
PAGEID_REQ = 3;
PAGEID_CONTACT = 4;

var menuItemTopScore = new MenuItem('Top scores', 'topscorelistklondike.asp', PAGEID_TOPSCORELIST);
var menuItem1 = new MenuItem('Klondike', 'topscorelistklondike.asp', PAGEID_TOPSCORELIST_KLONDIKE);
menuItem1.parent = menuItemTopScore;
var menuItem2 = new MenuItem('Golf', 'topscorelistgolf.asp', PAGEID_TOPSCORELIST_GOLF);
menuItem2.parent = menuItemTopScore;
var menuItem3 = new MenuItem('Seahaven Towers', 'topscorelistseahaventowers.asp', PAGEID_TOPSCORELIST_SEAHAVENTOWERS);
menuItem3.parent = menuItemTopScore;
menuItemTopScore.children = new Array(menuItem1, menuItem2, menuItem3);

var menuItemScreenshots = new MenuItem('Screenshots', 'screenshots1.html', PAGEID_SCREENSHOTS);
var menuItem81 = new MenuItem('#1', 'screenshots1.html', PAGEID_SCREENSHOTS1);
menuItem81.parent = menuItemScreenshots;
var menuItem82 = new MenuItem('#2', 'screenshots2.html', PAGEID_SCREENSHOTS2);
menuItem82.parent = menuItemScreenshots;
var menuItem83 = new MenuItem('#3', 'screenshots3.html', PAGEID_SCREENSHOTS3);
menuItem83.parent = menuItemScreenshots;
menuItemScreenshots.children = new Array(menuItem81, menuItem82, menuItem83);

menuItems = new Array(
	new MenuItem('Home', 'index.html', PAGEID_HOME),
	menuItemTopScore,
	menuItemScreenshots,
	new MenuItem('Requirements', 'req.html', PAGEID_REQ),
	new MenuItem('Contact', 'contact.asp', PAGEID_CONTACT)
);

function generateFrameStart(){
	document.write('<BODY background="images/tiled194.jpg">');	
	document.write('<center>');
	document.write('<table cellpadding="10" border="0" width = "720" height="100%" background="images/t1273.jpg"><tr><td valign="top">');	
}

function generateFrameEnd(){	
	document.write("</td></tr></table></center></body>");
}

function generateLogo(){
	document.write('<center><IMG src="images/logov2.jpg"></IMG></center>');
}

function generateMenu(pageID){
	var activeMenuItem = findMenuItem(pageID);
	if (activeMenuItem != null){
		markMenuPath(activeMenuItem);
	}
	// Do level 1
	document.write('<center><table cellspacing="10" cellpadding="10"><tr>');
	for (var i = 0; i < menuItems.length; i++){
		var menuItem = menuItems[i];
		if (menuItem == activeMenuItem){
			//document.write('<td bgcolor="Silver">');
			document.write('<td background="images/tiled706green.jpg">');
		} else {			
			document.write('<td>');
		}
		document.write("<A href='" + menuItem.href + "'><b>" + menuItem.name + "</b></A>");
		document.write("</td>");
	}
	document.write("</tr></table></center>");	
	// Do level 2
	var menuItemInPath = findMenuItemInPath(menuItems);
	if (menuItemInPath != null && menuItemInPath.children != null){
		document.write('<center><table cellspacing="10" cellpadding="10"><tr>');
		for (var i = 0; i < menuItemInPath.children.length; i++){
			var menuItem = menuItemInPath.children[i];
			if (menuItem == activeMenuItem){
				document.write('<td background="images/tiled706green.jpg">');
			} else {
				document.write('<td>');
			}
			document.write("<A href='" + menuItem.href + "'><b>" + menuItem.name + "</b></A>");
			document.write("</td>");
		}
		document.write("</tr></table></center>");	
	}
}

function findMenuItemInPath(menuItems_local){
	
	for (var i = 0; i < menuItems_local.length; i++){
		if (menuItems_local[i].isInPath){		
			return menuItems_local[i];
		}
	}
	return null;
}

function markMenuPath(menuItem){
	while (true){
		menuItem.isInPath = true;
		menuItem = menuItem.parent;
		if (menuItem == null){
			break;
		}
	}
}

function findMenuItem(targetPageID){	
	for (var i = 0; i < menuItems.length; i++){
		var result = findMenuItem_Impl(menuItems[i], targetPageID);
		if (result != null){
			return result;
		}
	}
	return null;
}

function findMenuItem_Impl(menuItem, targetPageID){
	if (menuItem.pageID == targetPageID){
		return menuItem;
	}
	if (menuItem.children != null){
		for (var i = 0; i < menuItem.children.length; i++){
			result = findMenuItem_Impl(menuItem.children[i], targetPageID);
			if (result != null){
				return result;
			}
		}
	}
	return null;
}
