var menuTimeout = 350

var menuSections = new Array()
var menuCountHide = new Array()

var menuSectionCnt = 0
var menuBoxCnt = 0

function menuShow(section, elements) {
  for (var j = 0; j < menuSections.length; j++) {
    if (menuSections[j] != section) {
      menuHide(menuSections[j], menuCountNodes(menuSections[j]))    }  }
  for (var j = 1; j <= elements; j++) {
    document.getElementById(section + '-' + j).style.visibility = 'visible'  } }

function menuHide(section, elements) {
  for (var j = 1; j <= elements; j++) {
    document.getElementById(section + '-' + j).style.visibility = 'hidden'   }
  document.getElementById(section).style.zIndex = -1 }

function menuTryHide(section, elements, countHide) {
  if (countHide != menuCountHide[section]) {
    return   }
  menuHide(section, elements) }

function menuCountNodes(element) {
  retn = 0
  nodes = document.getElementById(element).childNodes.length
  for (var j = 0; j < nodes; j++) {
    if (document.getElementById(element).childNodes[j].nodeType == 1) {
      retn++     }   }
  return retn }

function menuInitSection(section) {
  var elements = menuCountNodes(section)
  for (var j = 0; j <= elements; j++) {
    var s = (j == 0 ? (section + '-top') : (section + '-' + j))
    if (j == 0) {
      document.getElementById(s).onmouseover = function() {
        menuShow(section, elements)
        menuCountHide[section]++
        for (var jj = 0; jj < menuSections.length; jj++) {
          document.getElementById(section).style.zIndex = 1
          if (menuSections[jj] != section) {
            document.getElementById(menuSections[jj]).style.zIndex = -1     }   }  }  } 
      else {
      document.getElementById(s).onmouseover = function() {
        //menuShow(section, elements)
        menuCountHide[section]++   }    }
    document.getElementById(s).onmouseout = function() {
      setTimeout("menuTryHide('" + section + "', " + elements + ", " + menuCountHide[section] + ")", menuTimeout)  }  } }

function menuMakeId(nodes) {
  for (var j = 0; j < nodes.length; j++) {
    switch (nodes[j].className) {
      case 'top':
        menuSectionCnt++
        menuBoxCnt = 0
        nodes[j].id = 'menu-' + menuSectionCnt + '-top'
        break
      case 'section':
        nodes[j].id = 'menu-' + menuSectionCnt
        menuSections[menuSections.length] = nodes[j].id
        break
      case 'box':
        menuBoxCnt++
        nodes[j].id = 'menu-' + menuSectionCnt + '-' + menuBoxCnt
        break }
    if (nodes[j].childNodes) {
      menuMakeId(nodes[j].childNodes)  }  } }

function menuInit() {
if(!document.getElementById) 
return 

  menuMakeId(document.getElementById('menu').childNodes)
  for (var j = 0; j < menuSections.length; j++) {
    menuCountHide[menuSections[j]] = 0 }
  for (var j = 0; j < menuSections.length; j++) {
    menuInitSection(menuSections[j]) } }
