if (document.getElementById && document.getElementsByTagName) {

var navMenu = {

  navHolder : document.getElementById('navbar'),
  navItems : document.getElementById('navbar').getElementsByTagName('a'),
  lists : document.getElementById('navbar').getElementsByTagName('ul'),
  allNavItems : 0,
  allLists : 0,

  // array for menu levels currently displayed
  openMenus : [],

  // array tracking which item is pressed at each level
  pressedNav : [],

  // timer for when to close menus
  timer : null,

  // array of id values for submenus, which correspond to the link
  // sequence in the whole navigation sequence
  subMenus : ['','international','parentshare','life','browse'],

  init : function() {

    this.allNavItems = this.navItems.length;
    this.allLists = this.lists.length;

    util.configEvents();

    // disabling the visibility of the sub menus
    for (var i=0; i<this.allLists; i++) {
         this.lists[i].style.visibility = 'hidden';
    }

    // adding a number property to each nav link, to synchronize
    // them with the subMenus[] array
    for (i=0; i<this.allNavItems; i++) {
         this.navItems[i].number = i;
    }

    // assign events to outer element holding nav
    util.addEvent(this.navHolder, 'mouseover', this.displaySubMenu, false);
    util.addEvent(this.navHolder, 'focus', this.displaySubMenu, true);
    util.addEvent(this.navHolder, 'focusin', this.displaySubMenu, false);
    util.addEvent(this.navHolder, 'mouseout', this.setTimer, false);
    util.addEvent(this.navHolder, 'blur', this.setTimer, true);
    util.addEvent(this.navHolder, 'focusout', this.setTimer, false);

  },

  displaySubMenu : function(evt) {

    // pinpoint the link chosen
    var linkChosen = util.findTarget(evt, 'a', this);

    // if no link was found, stop processing
    if (!linkChosen) { return; }

    // a new link has been moused over or given focus, so erase the countdown
    if (navMenu.timer) { clearTimeout(navMenu.timer); }

    var menuLvl, menuToShow;
    var num = linkChosen.number;

    // if the link number is 4 or less, it is global nav (Level 1)
    if (num <= 4) { menuLvl = 1; }

    // if the link number is 5 or more, it is local nav (Level 2)
    if (num > 4) { menuLvl = 2; }

    // stop if the user is mousing over or tabbing to the same item again
    if (navMenu.openMenus[menuLvl] &&
        navMenu.openMenus[menuLvl] === navMenu.subMenus[num]) { return; }

    // shut off any other submenus
    if (navMenu.openMenus[menuLvl]) { navMenu.closeAllMenus(menuLvl); }

    // if there is no item in subMenus[] at that position, then do nothing
    // if there is an item in subMenus[] at that position, change the
    // indicated sub menu's visibility
    if (navMenu.subMenus[num]) {
      menuToShow = document.getElementById(navMenu.subMenus[num]).style;
      menuToShow.visibility = 'visible';
    }

    // assign that open menu to the openMenus[] array, with the position
    // in the array the same as the menu level (1 or 2)
    navMenu.openMenus[menuLvl] = navMenu.subMenus[num];

    // alter visual display if there is no class assigned to that anchor
    // if there is already a class assigned, then we assume it is "over" and do nothing
    if (linkChosen.className) { return; }
    linkChosen.className = 'over';

    // replace whatever item is in the pressedNav[] array with the one just activated
    // remove the class from that previous item
    if (navMenu.pressedNav[menuLvl]) { navMenu.pressedNav[menuLvl].className = ''; }
    navMenu.pressedNav[menuLvl] = linkChosen;

  },

  // setting a timer
  setTimer : function() {
    if (navMenu.timer) { clearTimeout(navMenu.timer); }
    navMenu.timer = setTimeout('navMenu.closeAllMenus(1)',1500);
  },

  // shutting down all menus, wiping all "over" classes and emptying out all
  // the items in openMenus[] and pressedNav[]
  closeAllMenus : function(lvl) {

    for (var i=navMenu.openMenus.length - 1; i>=lvl; i--) {
      if (navMenu.openMenus[i]) {
        var menuToHide = document.getElementById(navMenu.openMenus[i]).style;
        menuToHide.visibility = 'hidden';
      }
      navMenu.openMenus[i] = null;
      if (navMenu.pressedNav[i]) {
        navMenu.pressedNav[i].className = '';
        navMenu.pressedNav[i] = null;
      }
    }

  }

};

navMenu.init();

}
