var thing;
function menu (id, title, url, myClass, highlight) {
	this.id = id;
	this.title = title;
	this.url = url;
	this.className = myClass;
	this.highlight = highlight;
	this.menus = new Array();
	this.addMenu = addMenu;
	this.getMenuTree = getMenuTree;
	this.render = render;
	this.parentMenu = null;
	this.left = 0;
	this.top = 0;
	this.height = 20;
	this.width = 202;
	this.type = 1;
}

function addMenu(menu) {
	if (menu.parentMenu == null) {
		menu.parentMenu = this;
		menu.left = 0;
		menu.top = this.height * this.menus.length;
		menu.height = (this.subheight)?this.subheight:this.height;
		menu.width = (this.subwidth)?this.subwidth:this.width;
		this.menus[this.menus.length] = menu;
	} else {
		alert (menu.id + " already is assigned to " + menu.parentMenu.id);
	} // if
} // addMenu

function getMenuTree() {
	myText = this.id + "\n<blockquote>\n";
	for (var i = 0; i < this.menus.length; i++) {
		myText += this.menus[i].getMenuTree();
	} // for 
	myText += "\n</blockquote>\n";
	return myText;
} // getMenuTree

function render(toObject) {
	var renderingTo = false;
	var myObj = document.getElementById(toObject);
	if (toObject == null) {
		myHTML = "<div id=\"" + this.id + "\" class=\"" + this.className + "\" onClick=\"navigate('" + this.url + "');\" onMouseOver=\"expand('" + this.id + "')\" onMouseOut=\"contract('" + this.id + "')\" style=\"position:absolute; top:" + this.top + "px; left:" + this.left + "px; height:" + this.height + "px; width:" + this.width + "px;\">" +
		"<table style=\"margin:0px\" border=0 cellpadding=0 cellspacing=0 width=" + this.width + " height=" + this.height + "><tr><TD height=" + this.height + " valign=center class=menuText>" + this.title + "</TD></tr></table>" + "\n";
	} else {
		alert(this.id + " rendering to " + toObject);
		myHTML = "<div id=\"" + this.id + "\">";
		myObj.onMouseOver = function() { alert(this.id) };
		renderingTo = true;
	} // if
	if (this.menus.length > 0) {
		var subleft = (this.type)?this.width:'-1';
		var subtop = (this.type)?'-1':this.height;
		myHTML += "<div id=\"" + this.id + "_sub\" onMouseOver=\"expand('" + this.id + "')\" onMouseOut=\"contract('" + this.id + "')\" style=\"position:absolute; top:" + subtop + "px; left:" + subleft + "px; width:" + this.width + "px; visibility:hidden\">\n";
		for (var i = 0; i < this.menus.length; i++) {
		  myHTML += this.menus[i].render(null);
		} // for
		myHTML += "</div>\n";
	} // if
	myHTML += "</div>\n";
	if (renderingTo) {
		myObj.innerHTML += myHTML;
	} else {
		return myHTML;
	} // if
} // render

function test (string) {
	// thing = window.open();
	// thing.document.write(string + "\n<br>");
} // test
test('foo!');

var navigating = false;
function navigate(url) {
   if (!navigating) {
   	navigating = true;
	// alert(url);
   	window.location = url;
   	window.setTimeout('navigating=false', 200);
   } // if
} // navigatealert

  function expand(menu) {
	// alert(document.getElementById(menu).className);
	thisClass = document.getElementById(menu).className;
	formerClass = document.getElementById(menu).formerClass;
	if (formerClass == null || formerClass == thisClass) {
		document.getElementById(menu).formerClass = thisClass;
  		document.getElementById(menu).className = thisClass + "_over";
	} // if
	if (document.getElementById(menu + "_sub")) {
		document.getElementById(menu + "_sub").style.visibility = 'visible';
		if (document.getElementById(menu).timeout > 0) {
			var timeout = document.getElementById(menu).timeout;
			window.clearTimeout(timeout);
			document.getElementById(menu).timeout = null;
			window.status = "Timeout " + timeout + " cleared.";
		} // if
	} // if
  } // if

  function contract(menu) {
  	document.getElementById(menu).className = document.getElementById(menu).formerClass;
	if (document.getElementById(menu + "_sub")) {
		// alert ("document.getElementById('" + menu + "'_sub').style.visibility = 'hidden'");
		if (document.getElementById(menu).timeout > 0) {
			/* skip */;
		} else {
			document.getElementById(menu).timeout = window.setTimeout("document.getElementById('" + menu + "_sub').style.visibility = 'hidden'", 200);
			window.status = "Timeout " + document.getElementById(menu).timeout + " set.";
		} // if
	} // if
  } // if

function makeMenus(menuName, myClass, n, step) {
	var menus = new Array();
	menus[0] = new menu(menuName + "0", menuName, 'http://www.foo.com', myClass, '');
	menus[0].type = 0;
	for (i = 1; i < n; i++) {
		menus[i] = new menu(menuName + i, menuName + i, '', myClass, '');
		p = parseInt((i - 1) / step);
		menus[p].addMenu(menus[i]);
	} // for 
	return menus[0];
} // makeMenus

function doContact() {
	window.open("../contact.php", "contact", "width=550,height=600,scrollbars=yes");
}

function doWindow(myUrl, myTitle, myWidth, myHeight) {
	statusString = "width="+myWidth+",height="+myHeight+",scrollbars=no";
	window.open(myUrl, myTitle, statusString);
}
