menus = [1, 2, 3, 5];
menus[1] = ["Computer Science", "Information Systems", "Information Technology", "Course Catalog"];
menus[2] = ["Course Catalog", "MSDN Software", "Scholarships", "Organizations", "Comp. Tech. Club", "About Us", "Alumni Letter"];
menus[3] = ["Faculty Profiles"];
menus[5] = ["Comp. Lab Schedule", "Board of Visitors", "ABET Accreditation", "Assess. of Learning"];

links = [1, 2, 3, 5];
s1 = "http://cs.sru.edu/dept/";
s2 = "http://cs.sru.edu/students/";
s3 = "http://cs.sru.edu/info/";
links[1] = [s1 + "cs.html", s1 + "is.html", s1 + "it.html", s1 + "catalog.html"];
links[2] = [s1 + "catalog.html", s2 + "msdn.html", s2 + "scholarships.html", s2 + "orgs.html", "http://cs.sru.edu/ctc/index.html", s2 + "about.html", s2 + "letter.html"];
links[3] = ["http://cs.sru.edu/faculty/faculty.html"];
links[5] = [s3 + "lab.html", s3 + "board.html", s3 + "info.html", "http://cs.sru.edu/~whit/assessment"];

window.onresize = function(){rebuild()};

function rebuild()
{
	var height;
	var width;

	var navMenu = document.getElementById("navmenu");
	height = findTop(navMenu);
	width = findLeft(navMenu);

	height += 20;
	width += 40;

	for (j in menus)
	{
		var ulVar = document.getElementById("menu"+j);
		var listVar = ulVar.getElementsByTagName("ul")[0];

		for (i in menus[j])
		{
			var listElement = listVar.getElementsByTagName("li")[i];
			listElement.style.top = (i * 25) + height + "px";
			listElement.style.left = (j * 110) + width + "px";
		}
	}	
}

function buildMenu()
{
	var height;
	var width;

	var navMenu = document.getElementById("navmenu");
	height = findTop(navMenu);
	width = findLeft(navMenu);

	height += 20;
	width += 40;

	for (j in menus)
	{
		var ulVar = document.getElementById("menu"+j);
		var listVar = document.createElement("ul");
		ulVar.onmouseover = function(){displayMenu(this)};
		ulVar.onmouseout = function(){hideMenu(this)};

		for (i in menus[j])
		{
			var listElement = document.createElement("li");
			listElement.style.top = (i * 25) + height + "px";
			listElement.style.left = (j * 110) + width + "px";
			listElement.onmouseover = function(){highlight(this)};
			listElement.onclick = function() {redirect(this)};
			listElement.onmouseout = function(){unlight(this)};
			var textVal = document.createTextNode(menus[j][i]);
			listElement.appendChild(textVal);
			listVar.style.display = "none";
			listVar.appendChild(listElement);
		}
		ulVar.appendChild(listVar);
	}
}

function displayMenu(list)
{
	l = list.childNodes.length - 1;
	list.childNodes[l].style.display = "inline";
}

function hideMenu(list)
{
	l = list.childNodes.length - 1;
	list.childNodes[l].style.display = "none";
}

function highlight(node)
{
	node.style.textDecoration = "underline";
	node.style.color = "rgb(30, 175, 30)";
}

function unlight(node)
{
	node.style.textDecoration = "none";
	node.style.color = "white";
}

function redirect(node)
{
	itemString = node.childNodes[0].nodeValue;
	for (j in menus)
	{
		for (i in menus[j])
		{
			if (itemString == menus[j][i])
			{
				window.location = links[j][i];
				return;
			}
		}
	}
}

function findTop(obj)
{
	var curTop = 0;
	if (obj.offsetParent)
	{
		do
		{
			curTop += obj.offsetTop;
		}while (obj = obj.offsetParent)
	}
	return curTop;
}

function findLeft(obj)
{
	var curLeft = 0;
	if (obj.offsetParent)
	{
		do
		{
			curLeft += obj.offsetLeft;
		}while (obj = obj.offsetParent)
	}
	return curLeft;
}
