// JavaScript Document

// menu Creation Program
// Developed by Kodaionline Team

var menuTimeout = 400

var menuSections = new Array()
var menuCntHide = new Array()

var menuSectionCount = 0
var menuBoxCount = 0
var top=0

function menuShow(section, elements) {
  for (var i = 0; i < menuSections.length; i++) {
    if (menuSections[i] != section) {
      menuHide(menuSections[i], menuCntNode(menuSections[i]))
    }
  }
  for (var i = 1; i <= elements; i++) {
    document.getElementById(section + '-' + i).style.visibility = 'visible'
  }
}

function menuHide(section, elements) {
  for (var i = 1; i <= elements; i++) {
    document.getElementById(section + '-' + i).style.visibility = 'hidden'
  }
  document.getElementById(section).style.zIndex = -1
}

function menuTryHide(section, elements, countHide) {
  if (countHide != menuCntHide[section]) {
    return
  }
  menuHide(section, elements)
}

function menuCntNode(element) {
  top = 0
  nodes = document.getElementById(element).childNodes.length
  for (var i = 0; i < nodes; i++) {
    if (document.getElementById(element).childNodes[i].nodeType == 1) {
      top++
    }
  }
  return top
}

function menuLoadSection(section) {
  var elements = menuCntNode(section)
  for (var i = 0; i <= elements; i++) {
    var m = (i == 0 ? (section + '-top') : (section + '-' + i))
    if (i == 0) {
      document.getElementById(m).onmouseover = function() {
        menuShow(section, elements)
        menuCntHide[section]++
        for (var a = 0; a < menuSections.length; a++) {
          document.getElementById(section).style.zIndex = 1
          if (menuSections[a] != section) {
            document.getElementById(menuSections[a]).style.zIndex = -1
          }
        }
      }
    } else {
      document.getElementById(m).onmouseover = function() {
        //menuShow(section, elements)
        menuCntHide[section]++
      }
    }
    document.getElementById(m).onmouseout = function() {
      setTimeout("menuTryHide('" + section + "', " + elements + ", " + menuCntHide[section] + ")", menuTimeout)
    }
  }
}

function menuId(nodes) {
  for (var i = 0; i < nodes.length; i++) {
    switch (nodes[i].className) {
      case 'top':
        menuSectionCount++
        menuBoxCount = 0
        nodes[i].id = 'menu-' + menuSectionCount + '-top'
        break
      case 'section':
        nodes[i].id = 'menu-' + menuSectionCount
        menuSections[menuSections.length] = nodes[i].id
        break
      case 'box':
        menuBoxCount++
        nodes[i].id = 'menu-' + menuSectionCount + '-' + menuBoxCount
        break
    }
    if (nodes[i].childNodes) {
      menuId(nodes[i].childNodes)
    }
  }
}

function menuLoad() {
  menuId(document.getElementById('menu').childNodes)
  for (var i = 0; i < menuSections.length; i++) {
    menuCntHide[menuSections[i]] = 0
  }
  for (var i = 0; i < menuSections.length; i++) {
    menuLoadSection(menuSections[i])
  }
}
