// Node Functions

if(!window.Node){
  var Node = {ELEMENT_NODE : 1, TEXT_NODE : 3};
}

function checkNode1(node, filter){
  return (filter == null || node.nodeType == Node[filter] || node.nodeName.toUpperCase() == filter.toUpperCase());
}

function getChildren1(node, filter){
  var result = new Array();
  var children = node.childNodes;
  for(var i = 0; i < children.length; i++){
    if(checkNode1(children[i], filter)) result[result.length] = children[i];
  }
  return result;
}

function getChildrenByElement1(node){
  return getChildren1(node, "ELEMENT_NODE");
}

function getFirstChild1(node, filter){
  var child;
  var children = node.childNodes;
  for(var i = 0; i < children.length; i++){
    child = children[i];
    if(checkNode1(child, filter)) return child;
  }
  return null;
}

function getFirstChildByText1(node){
  return getFirstChild1(node, "TEXT_NODE");
}

function getNextSibling1(node, filter){
  for(var sibling = node.nextSibling; sibling != null; sibling = sibling.nextSibling){
    if(checkNode1(sibling, filter)) return sibling;
  }
  return null;
}
function getNextSiblingByElement1(node){
        return getNextSibling1(node, "ELEMENT_NODE");
}

// Menu Functions & Properties

var activeMenu1 = null;

function showMenu1() {
  if(activeMenu1){
    activeMenu1.className = "";
    getNextSiblingByElement1(activeMenu1).style.display = "none";
  }
  if(this == activeMenu1){
    activeMenu1 = null;
  } else {
    this.className = "active";
    getNextSiblingByElement1(this).style.display = "block";
    activeMenu1 = this;
  }
  return false;
}

function initMenu1(){
  var menus, menu, text, a, i;
  menus = getChildrenByElement1(document.getElementById("menu"));
  for(i = 0; i < menus.length; i++){
    menu = menus[i];
    text = getFirstChildByText1(menu);
    a = document.createElement("a");
    menu.replaceChild(a, text);
    a.appendChild(text);
    a.href = "#";
    a.onclick = showMenu;
    a.onfocus = function(){this.blur()};
  }
  
    var menus1, menu1, text1, a1, i1;
  menus1 = getChildrenByElement1(document.getElementById("menu1"));
  for(i = 0; i < menus1.length; i++){
    menu1 = menus1[i];
    text1 = getFirstChildByText1(menu1);
    a1 = document.createElement("a");
    menu1.replaceChild(a1, text1);
    a1.appendChild(text1);
    a1.href = "#";
    a1.onclick = showMenu1;
    a1.onfocus = function(){this.blur()};
  }

}

if(document.createElement) window.onload = initMenu1;