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

var navMenu = {

  body : document.getElementsByTagName('body')[0],
  navHolder : document.getElementById('navbar'),
  navItems : document.getElementById('navbar').getElementsByTagName('a'),
  lists : document.getElementById('navbar').getElementsByTagName('ul'),
  styleMenu : document.createElement('div'),  
  
  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 : ['','about','','spdinfo','','','','','','','','store'],

  init : function() {

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

    //util.configEvents();
    navMenu.util.configEvents();
	// this.buildStyleMenu();
	// this.retrieveStoredSettings();
	
    // 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
    navMenu.util.addEvent(this.navHolder, 'mouseover', this.displaySubMenu, false);
    navMenu.util.addEvent(this.navHolder, 'focus', this.displaySubMenu, true);
    navMenu.util.addEvent(this.navHolder, 'focusin', this.displaySubMenu, false);
    navMenu.util.addEvent(this.navHolder, 'mouseout', this.setTimer, false);
    navMenu.util.addEvent(this.navHolder, 'blur', this.setTimer, true);
    navMenu.util.addEvent(this.navHolder, 'focusout', this.setTimer, false);
	// navMenu.util.addEvent(this.styleMenu, 'click', this.setStyle, false);

  },
  
/*
  buildStyleMenu : function() {
    var betaHdr = document.createElement('h3');
	var betaHdrTxt = document.createTextNode('Theme Menu (beta)');
	var betaMsg = document.createElement('div');
	var betaMsgTxt = document.createTextNode('This is a beta theme changing menu. It is buggy and you will have to reset the style on every page.');
	var softLink = document.createElement('a');
	var standardLink = document.createElement('a');
	var blackWhiteLink = document.createElement('a');
	softLink.className = standardLink.className = blackWhiteLink.classsName = 'styleMenuItem';
	softLink.href = standardLink.href = blackWhiteLink.href = '#';
    var softText = document.createTextNode('Soft Theme');
	var standardText = document.createTextNode('Standard Theme');
	var blackWhiteText = document.createTextNode('Black and White');
  
    navMenu.styleMenu.id = 'styleMenu';
	betaHdr.id = 'styleMenuHead';
	betaMsg.id = 'styleMenuMsg';
	navMenu.styleMenu.appendChild(betaHdr).appendChild(betaHdrTxt);
	navMenu.styleMenu.appendChild(standardLink).appendChild(standardText);
	navMenu.styleMenu.appendChild(softLink).appendChild(softText);
	navMenu.styleMenu.appendChild(blackWhiteLink).appendChild(blackWhiteText);
	navMenu.styleMenu.appendChild(betaMsg).appendChild(betaMsgTxt);
	navMenu.body.appendChild(navMenu.styleMenu);
  
  },
*/
/*
  retrieveStoredSettings : function() {
    // restore theme settings
      var theTheme = navMenu.util.findCookie('theTheme');
     
      if (theTheme !== null && theTheme < 2) {
      
      //  navMenu.resetAppearance('viewControlAnchors');
        theTheme = parseInt(theTheme);  // convert string to number
        navMenu.viewControlAnchors[theTheme].id = 'current';
        navMenu.body.className = (theTheme) ? 'soft' : 'blackWhite'; 
		
      }
          
    },
*/



  
  displaySubMenu : function(evt) {

    // pinpoint the link chosen
    var linkChosen = navMenu.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 8 or less, it is global nav (Level 1)
    if (num <= 11) { menuLvl = 1; }

    // if the link number is more than 8, it is local nav (Level 2)
    if (num > 11) { 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 1.5 second 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;
      }
    }

  },

/*
  setStyle : function(evt) {
    
	// pinpoint the link chosen
    var style = navMenu.util.findTarget(evt, 'a', this);
    // var oldStyle = document.getElementById('currentTheme');
	// oldStyle.id = ''; 
  
    if (!style) { return; }

	// navMenu.resetAppearance();
	
    var theme;
	
    switch (style.firstChild.nodeValue) {
 
      case 'Soft Theme' :
      
        navMenu.body.className = 'soft';
        theme = 0;
		break;
      
      case 'Black and White' :
      
        navMenu.body.className = 'blackWhite';
        theme = 1;
		break;

      default :
        
        navMenu.body.className = '';

    }
    
	navMenu.util.stopDefault(evt);
    
	style.id = 'currentTheme';
	
   // navMenu.util.createCookie('theTheme',theme);
  
  },
  */
 /*  // delete id values for all items in a collection
  resetAppearance : function() {
    var styleLinks = navMenu.styleMenu.getElementsByTagName('a');
    [styleLinks].id = '';
	// all_styleLinks = 0;
    // for (var i=0; i<['all_' + styleLinks]; i++) { [styleLinks][i].id = ''; } 
	
  },
*/
   util : {

    createCookie : function(name,value,expiration,path,domain,secure) {
      var data = name + "=" + escape(value);
      if (expiration) { 
          var expiresAt = new Date();
          expiresAt.setTime(expiration);
          data += "; expires=" + expiresAt.toGMTString();
      }
      if (path) { data += "; path=" + path; }
      if (domain) { data += "; domain=" + domain; }
      if (secure) { data += "; secure"; }
      document.cookie = data;
    },
  
    findCookie : function(name) {  
      var query = name + "=";
      var queryLength = query.length;
      var cookieLength = document.cookie.length;
      var i=0;
      while (i<cookieLength) {
        var position = i + queryLength;
        if (document.cookie.substring(i,position) === query) {
           return this.findCookieValue(position);
        }
        i = document.cookie.indexOf(" ", i) + 1;
        if (i === 0) { break; }  
      }
      return null;  
    },

    findCookieValue : function(position) {
      var endsAt = document.cookie.indexOf(";", position);
      if (endsAt === -1) { endsAt = document.cookie.length; }
      return unescape(document.cookie.substring(position,endsAt));
    },

    configEvents : function() {
      if (document.addEventListener) {
        this.addEvent = function(el, type, func, capture) { el.addEventListener(type, func, capture); };
        this.stopBubble = function(evt) { evt.stopPropagation(); };
        this.stopDefault = function(evt) { evt.preventDefault(); };
        this.findTarget = function(evt, targetNode, container) {
         var currentNode = evt.target;
         while (currentNode && currentNode !== container) {
          if (currentNode.nodeName.toLowerCase() === targetNode) { return currentNode; break; }
          else { currentNode = currentNode.parentNode; }
         };
         return false;
        };
      }
      else if (document.attachEvent) {
       this.addEvent = function(el, type, func) { el["e" + type + func] = func; el[type + func] = function() { el["e" + type + func] (window.event); }; el.attachEvent("on" + type, el[type + func]); };
       this.stopBubble = function(evt) { evt.cancelBubble = true; };
       this.stopDefault = function(evt) { evt.returnValue = false; };
       this.findTarget = function(evt, targetNode, container) { var currentNode = evt.srcElement; 
        while (currentNode && currentNode !== container) {
         if (currentNode.nodeName.toLowerCase() === targetNode) { return currentNode; break; }
         else { currentNode = currentNode.parentNode; }
        };
        return false;
       };
      }
    }
  
  }
 
  
  
};

navMenu.init();

}

