﻿function configureMenus(menu)
{
  // hide all submenus
  var ULs = $(menu).getElementsByTagName('UL')
  for (var i = 0; i < ULs.length; i++) {
    if (ULs[i].parentNode.id != menu) {
      if (ULs[i].parentNode.className != 'open') {
		ULs[i].style.display = 'none'
      }
    }
  }
  // add effects to submenus
  var obj = $(menu).getElementsByTagName('UL')[0].getElementsByTagName('LI')[0]
  ULs = obj.getElementsByTagName('UL')
  while (obj) {
    if (obj.nodeType == 1) {
      // check for sub <ul>
      ULs = obj.getElementsByTagName('UL')
      if (ULs.length > 0) {
        if (ULs[0].style.display == 'none') {
		  obj.className = 'menu-closed'
        } else {
          obj.className = 'menu-open'
        }
        firstLink = obj.getElementsByTagName('A')[0]
        firstLink.href = 'javascript:void(0)'
        firstLink.onclick = function() {
          subMenu = this.parentNode.getElementsByTagName('UL')[0]
          if (subMenu.style.display == 'none') {
            new Effect.BlindDown(subMenu)
            this.parentNode.className = 'menu-open'
          } else {
            new Effect.BlindUp(subMenu)
            this.parentNode.className = 'menu-closed'
          }
        }
        // configure inner <UL>
        innerObj = obj.getElementsByTagName('UL')[0].getElementsByTagName('LI')[0]
        while (innerObj) {
            if (innerObj.nodeType == 1) {
                // check for sub <ul>
                ULs = innerObj.getElementsByTagName('UL')
                if (ULs.length > 0) {
                    if (ULs[0].style.display == 'none') {
                        innerObj.className = 'menu-closed'
                    } else {
                        innerObj.className = 'menu-open'
                    }
                    firstLink = innerObj.getElementsByTagName('A')[0]
                    firstLink.href = 'javascript:void(0)'
                    firstLink.onclick = function() {
                        subMenu = this.parentNode.getElementsByTagName('UL')[0]
                        if (subMenu.style.display == 'none') {
                            new Effect.BlindDown(subMenu)
                            this.parentNode.className = 'menu-open'
                        } else {
                            new Effect.BlindUp(subMenu)
                            this.parentNode.className = 'menu-closed'
                        }
                    }
                }
            }
            innerObj = innerObj.nextSibling
        }
      }
    }
    obj = obj.nextSibling
  }
}

/*
  while (obj) {
    if (obj.nodeType == 1) {
      // check for sub <ul>
      ULs = obj.getElementsByTagName('UL')
      if (ULs.length > 0) {
        if (ULs[0].style.display == 'none') {
		  obj.className = 'menu-closed'
        } else {
          obj.className = 'menu-open'
        }
        firstLink = obj.getElementsByTagName('A')[0]
        firstLink.href = 'javascript:void(0)'
        firstLink.onclick = function() {
          subMenu = this.parentNode.getElementsByTagName('UL')[0]
          if (subMenu.style.display == 'none') {
            new Effect.BlindDown(subMenu)
            this.parentNode.className = 'menu-open'
          } else {
            new Effect.BlindUp(subMenu)
            this.parentNode.className = 'menu-closed'
          }
        }
      }
    }
    obj = obj.nextSibling
  }
  */