var layerOffImage=new Image(1,18);
layerOffImage.src="/images/menus/off.gif";
var layerOnImage=new Image(1,18);
layerOnImage.src="/images/menus/on.gif";

timeout=null;
var menusShowing=null;
var divElementLit=null;
function navImageOn(imgPrefix,isWhite)
{
  if (timeout != null) {
    clearTimeout(timeout);
    timeout=null;
  }
  if (menusShowing != null)
    hideAllMenus();
  if (!isWhite) {
    if (document.layers)
	eval("document.images[\""+imgPrefix+"Img\"].src="+imgPrefix+"OnImage.src");
    else if (document.getElementById)
	eval("document.getElementById(\""+imgPrefix+"Img\").src="+imgPrefix+"OnImage.src");
  }
  addMenu(imgPrefix);
}
function addMenu(prefix)
{
  var menuId;
  if (document.layers) {
    menuId=document.layers[prefix+"MenuLayer"];
    if (menuId != null)
	menuId.visibility="show";
    else
	return;
  }
  else if (document.getElementById) {
    eval("menuId=document.getElementById(\""+prefix+"MenuDiv\")");
    if (menuId != null)
	menuId.style.visibility="visible";
    else
	return;
  }

  var lastIndex;
  if (menusShowing == null) {
    lastIndex=0;
    menusShowing=new Array(1);
    menusShowing[lastIndex]=prefix;
  }
  else {
    var newMenusShowing=new Array(menusShowing.length+1);
    for (n=0; n < menusShowing.length; n++)
	newMenusShowing[n]=menusShowing[n];
    newMenusShowing[n]=prefix;
    lastIndex=n;
    menusShowing=newMenusShowing;
  }
}
function navImageOff(imgPrefix,isWhite)
{
  var image;
  if (document.layers) {
    if (!isWhite)
	eval("document.images[\""+imgPrefix+"Img\"].src="+imgPrefix+"OffImage.src");
  }
  else if (document.getElementById) {
    eval("image=document.getElementById(\""+imgPrefix+"Img\")");
    if (!isWhite) {
	eval("var src="+imgPrefix+"OffImage.src");
	image.src=src;
    }
  }

  var menu;
  if (document.layers)
    menu=document.layers[imgPrefix+"MenuLayer"];
  else if (document.getElementById)
    eval("menu=document.getElementById(\""+imgPrefix+"MenuDiv\")");
  if (menu != null)
    timeout=setTimeout("hideAllMenus()",100);
}
function removeMenu(prefix)
{
  if (menusShowing == null)
    return;

  var n=0;
  var index=-1;
  while (n < menusShowing.length) {
    if (menusShowing[n] == prefix) {
	index=n;
	n=menusShowing.length;
    }
    n++;
  }
  if (index >= 0) {
    newMenusShowing=new Array(menusShowing.length-1);
    m=0;
    for (n=0; n < menusShowing.length; n++) {
	if (n != index) {
	  newMenusShowing[m]=menusShowing[n];
	  m++;
	}
    }
    menusShowing=newMenusShowing;
  }
}
function hideAllMenus()
{
  if (menusShowing == null)
    return;
  for (n=menusShowing.length-1; n >= 0; n--) {
    if (document.layers)
	document.layers[menusShowing[n]+"MenuLayer"].visibility="hide";
    else if (document.getElementById)
	eval("document.getElementById(\""+menusShowing[n]+"MenuDiv\").style.visibility=\"hidden\"");
  }
  menusShowing=null;
}

function clickHandler(e) {
  if (e.which == 1 && menu_href != "")
    window.location=menu_href;

  return false;
}
var menu_href;
function layerElementOn(prefix,elementIndex,href,childPrefix)
{
  if (timeout != null) {
    clearTimeout(timeout);
    timeout=null;
  }
  while (prefix != menusShowing[menusShowing.length-1]) {
    document.layers[menusShowing[menusShowing.length-1]+"MenuLayer"].visibility="hide";
    removeMenu(menusShowing[menusShowing.length-1]);
  }
  document.layers[prefix+"MenuLayer"].document.layers[elementIndex].background.src=layerOnImage.src;
  document.layers[prefix+"MenuLayer"].document.layers[elementIndex].captureEvents(Event.MOUSEDOWN);
  document.layers[prefix+"MenuLayer"].document.layers[elementIndex].onMouseDown=clickHandler;
  menu_href=href;
  if (childPrefix != "")
    addMenu(childPrefix);
}
function layerElementOff(prefix,elementIndex)
{
  document.layers[prefix+"MenuLayer"].document.layers[elementIndex].background.src=layerOffImage.src;
  if (menusShowing != null) {
    var hide=false;
    for (n=0; n < menusShowing.length; n++) {
	if (prefix == menusShowing[n])
	  hide=true;
    }
    if (hide)
	timeout=setTimeout("hideAllMenus()",100);
  }
}

function divElementOn(prefix,elementIndex,childPrefix)
{
  var divId;
  if (timeout != null) {
    clearTimeout(timeout);
    timeout=null;
  }
  while (menusShowing.length > 0 && prefix != menusShowing[menusShowing.length-1]) {
    eval("document.getElementById(\""+menusShowing[menusShowing.length-1]+"MenuDiv\").style.visibility=\"hidden\"");
    removeMenu(menusShowing[menusShowing.length-1]);
  }
  if (divElementLit != null && (prefix != divElementLit.prefix || elementIndex != divElementLit.elementIndex)) {
    eval("document.getElementById(\""+divElementLit.prefix+"MenuDiv\").getElementsByTagName(\"div\")["+divElementLit.elementIndex+"].style.backgroundColor=\"#dfcfb3\"");
    divElementLit=null;
  }
  eval("divId=document.getElementById(\""+prefix+"MenuDiv\")");
  divId.getElementsByTagName("div")[elementIndex].style.backgroundColor="#feeccc";
  divElementLit=new Object();
  divElementLit.prefix=prefix;
  divElementLit.elementIndex=elementIndex;
  if (childPrefix != "")
    addMenu(childPrefix);
}
function divElementOff(prefix,elementIndex)
{
  eval("var divId=document.getElementById(\""+prefix+"MenuDiv\")");
  divId.getElementsByTagName("div")[elementIndex].style.backgroundColor="#dfcfb3";
  if (divElementLit != null && prefix == divElementLit.prefix && elementIndex == divElementLit.elementIndex)
    divElementLit=null;
  timeout=setTimeout("hideAllMenus()",100);
}

function doFinalAdjustments()
{
  if (document.getElementById) {
    var x=document.getElementById("homeImg");
    var homeBottom=17+x.offsetTop;
// Mac version of MSIE doesn't seem to handle the 5px body margin within the
//  browser window properly, so do it for MSIE
    if (navigator.appVersion.indexOf("Macintosh") > 0 && navigator.appVersion.indexOf("MSIE") > 0)
	homeBottom+=5;
    while ( (x=x.offsetParent) != null)
	homeBottom+=x.offsetTop;
// 113 is the base value for the menu tops
    var homeOffset=homeBottom-113;
    if (homeOffset > 0) {
	var elements=document.getElementsByTagName("div");
	for (n=0; n < elements.length; n++) {
	  var length=elements[n].id.length;
	  if (length > 7 && elements[n].id.substr(length-7,7,"") == "MenuDiv")
	    elements[n].style.top=(parseInt(elements[n].style.top)+homeOffset)+"px";
	}
    }
  }
}
