/********************************************************
menu-functions.js

for use with mla-style-v1-0.css menus and content

Notes:
    The menus should be specified using <UL> and <LI> tags. 
  Each link should be contained within <A> and </A> tags.
    The id for each <A> tag (menus items and submenu items) 
  should be "MENU-#item#" where #item# is a unique name 
  for the link.
    The id for each submenu <UL> tag should be 
  "MENU-#item#-SUBMENU" where #item# is the same as the 
  parent menu item.
    Inactive links should have class "inactive" attributed
  to the <A> tag.
    The selected link should have class "selected" attributed
  to the <A> tag.
    There should be a corresponding content div with an id of 
  "CONTENT-#item#" where #item# corresponds to the name
  used in the menu.

********************************************************/

function menuClick(id) {
	var i, p, cs, c, s, d, n, is, ul;

	i = document.getElementById(id);

	if (i.className == "inactive") {
		return;
	}

	ul = i.parentNode;
	while (ul.nodeName != "UL") {
		ul = ul.parentNode;
	}

	/* unselect all menu items */
	is = document.getElementById("LAYOUT-MENU").getElementsByTagName("a");
	for (n=0;n<is.length;n++) {
		if (is[n].id.substr(0, 5) == "MENU-" && is[n].className == "selected") {
			is[n].className = "";
		}
	}

	/* hide all submenus of items in current menu level */
	var cs = ul.getElementsByTagName("ul");

	for (n=0;n<cs.length;n++) {
/*		c = document.getElementById(cs[n].id + "-SUBMENU");
		if (c != null) {
			c.style.display = "none";
		}*/
		cs[n].style.display = "none";
	}

	/* show= submenu if one exists*/
	s = document.getElementById(id + "-SUBMENU");
	if (s != null) {
		s.style.display = "block";
	}

	/* set menu item as selected */
	i.className = "selected";

	/* show/hide content as appropriate */
	showContent(id);
}


function showContent(id) {

	var es, n;
	
	/* hide all content divs */
	es = document.getElementsByTagName("div");

	for (n=0;n<es.length;n++) {
		if (es[n].id.substring(0, 8) == "CONTENT-") {
			es[n].className = "";
			es[n].style.display = "none";
		}
	}

	/* show selected content divs */
	d = document.getElementById("CONTENT-" + id.slice(5));
	d.style.display = "block";

	/* set widths to max for all requested elements */
	es = d.getElementsByTagName('*');
	for (n=0; n<es.length; n++) {
		if (es[n].getAttribute("maxwidth") == "yes") {
			p = es[n].parentNode;
			pw = p.scrollWidth;
			pl = 0;
			while (p != es[n].offsetParent) {
				pl += p.offsetLeft - 10;
				p = p.offsetParent;
			}
			l = pw - es[n].offsetLeft + pl - 10;
			es[n].style.width = l + "px";
		}
	}

}


function activateMenuItem(menuItem) {
	var i = document.getElementById("MENU-" + menuItem);
	
	if (i != null) {
		i.className = "";
	}
}

function deactivateMenuItem(menuItem) {
	var i = document.getElementById("MENU-" + menuItem);
	
	if (i != null) {
		i.className = "inactive";
	}
}

