/* code for dynamic menu */
/* This should be Unix-compatible */

var menu_sub_offsetY = 8,
    menu_sub_offsetX = -4; // set according with table.margin

var menu_highlight_mode = 2; // 0=use next colors, 1=use highlighting, 2=use classes

var menu_normal_color = "#0A7B9D",
    menu_highlight_color = "#2A9BBD";

var menu_normal_class = "menurow_tr",
    menu_highlight_class = "menurow_tr2";

function getLinked(item) { // item must be a TR element
  var c;
  c = item.cells.item(0).id;
  if (c == null || c == "") return(null);
  if (c.substr(0,6) == "linkto") return(document.getElementById(c.substr(6)));
  return(null);
}

function over(item) { // open submenu
  var tab, subtab, r,g,b;
  tab = item.parentNode;
  if (tab.tagName != "TABLE") tab = tab.parentNode;
  hideChildren(tab);
  switch (menu_highlight_mode) {
  	case 0:
  	  item.style.backgroundColor = menu_highlight_color;
  	  break;
  	case 1:
      item.id = item.bgColor;    // save old color
      if (item.id == "") item.id = tab.style.backgroundColor;
      r = parseInt(item.id.substr(1,2),16);
      g = parseInt(item.id.substr(3,2),16);
      b = parseInt(item.id.substr(5,2),16);
      r = Math.min(r+0x20, 0xFF);
      g = Math.min(g+0x20, 0xFF);
      b = Math.min(b+0x20, 0xFF);
      item.style.backgroundColor = "#" + r.toString(16) + g.toString(16) + b.toString(16);
      break;
  	case 2:
  	  item.className = menu_highlight_class;
  	  break;
  }
  subtab = getLinked(item);
  if (subtab == null) return;
  subtab.style.top = tab.offsetTop+item.offsetTop+menu_sub_offsetY+"px";
  subtab.style.left = tab.offsetLeft+tab.offsetWidth+menu_sub_offsetX+"px";
  //subtab.style.tableLayout = "fixed";
  //subtab.style.width = "100px";
  subtab.style.display = "block";
}

function out(item) {
  switch (menu_highlight_mode) {
  	case 0:
  	  item.style.backgroundColor = menu_normal_color;
  	case 1:
  	  item.style.backgroundColor = item.id;
  	case 2:
  	  item.className = menu_normal_class;
  	  break;
  }
}

function hideChildren(item) { // item must be a TABLE
  var link,i;
  for (i=0; i<item.rows.length; i++) {
    link = getLinked(item.rows.item(i));
    if (link != null) {
      hideChildren(link);
      link.style.display = "none";
    }
  }
}

function openlink(loc) {
  document.location = loc;
}
