function addEvents() {

  var oTopNav = document.getElementById('navigation');

  if (oTopNav.firstChild) {

    var oMainItem = oTopNav.firstChild;
    while (oMainItem) {

      if (oMainItem.firstChild) {

        var oSubItem = oMainItem.firstChild;
        while(oSubItem) {

          if (oSubItem.tagName == 'A') {

            oSubItem.onmouseover = function() {hideall();showPopup(this);};
            oSubItem.onmouseout = function() {hide();};

          }

          if (oSubItem.className == 'subnav') {

            oSubItem.onmouseover=function() {clearTimer();};
            oSubItem.onmouseout=function() {hide();};

          }

          oSubItem = oSubItem.nextSibling
        }

      }

      oMainItem = oMainItem.nextSibling;

    }

  }

}

var timerID = 0;

function clearTimer() {

  if(timerID) {
    clearTimeout(timerID);
    timerID  = 0;
  }

}
function showPopup(popupLink) {

	//var flashExists = document.getElementById("flash");

	//if (flashExists != null) 
	//{ 
	  //document.getElementById('flash').style.visibility = 'hidden';
	//}

  clearTimer();

  popupLink = popupLink.parentNode;
  popup = popupLink.id;
  var oContainer = document.getElementById(popup);

  if(oContainer.firstChild) { // check for children
    var oChild = oContainer.firstChild;
    while(oChild) { // run over them
      if(oChild.nodeType==1 && oChild.className == 'subnav') {
        oChild.style.display = "block";
      }
      oChild = oChild.nextSibling;
    }
  } else {

    alert("no children");

  }

}

function hide() {

  timerID = setTimeout('hideall()',1000);

}

function hideall() {

  var oList = document.getElementsByTagName('ul');
  var i;
  for(i in oList) {
    if(oList[i].className=='subnav')
    oList[i].style.display='none';
  }

	//var flashExists = document.getElementById("flash");
  
	//if (flashExists != null) 
	//{ 
	  //document.getElementById('flash').style.visibility = 'visible';
	//}
}

addLoadEvent(addEvents);
addLoadEvent(hideall);