/**
 *  Copyright 2010 Obsidian Dynamics.
 *  All rights reserved.
 */

var mainMenuId;
var subItemId;

function updateMenu()
{
  $('nav').getElements('li').each(function(menu, index) {
    // Indicates the current page

	if (menu.id == mainMenuId)
    {
      menu.set('class', 'selectedBg');
    }
    
    menu.removeEvents();
    menu.addEvents({
      'mouseover': function() {
        if (this.id == mainMenuId || this.id == 'leftMenu' || this.id == 'rightMenu' || this.id == 'emptyMenu')
        {
          return;
        }
        this.set('class', 'mouseoverBg');
      },
      'mouseout': function() {
        if (this.id == mainMenuId || this.id == 'leftMenu' || this.id == 'rightMenu' || this.id == 'emptyMenu')
        {
          return;
        }
        this.set('class', 'normalBg');
      },
      'click': function(){
        if (this.id == mainMenuId)
        {
          return;
        }
        var prefix = '';
        if (mainMenuId != 'menuItemHome' && mainMenuId != null)
        {
          prefix = '../';
        }
        if (this.id == 'menuItemHome')
        {
          window.location = prefix + 'index.html';
        }
        else if (this.id == 'menuItemDTS')
        {
          window.location = prefix + 'dts/index.html';
        }
        else if (this.id == 'menuItemNV')
        {
          window.location = prefix + 'dts_nv/index.html';
        }
        else if (this.id == 'menuItemGridlock')
        {
          window.location = prefix + 'gridlock/index.html';
        }
      }
    });
  });
}

function updateSubMenu()
{
  if (mainMenuId == null ||mainMenuId == 'menuItemHome')
  {
    //alert('setting dislay to none' + mainMenuId);
    $('subNav').setStyle('display', 'none');
  }
  else
  {
    //alert('setting dislay to not none');
    $('subNav').setStyle('display', '');
  }
  
  $('subNav').getElements('li').each(function(subMenu, index) {
    if (subMenu.id == subItemId)
    {
      subMenu.set('class', 'selectedSubmenu');
    }
    
    subMenu.removeEvents();
    subMenu.addEvents({
      'mouseover': function() {
        if (this.id == subItemId || this.id == 'leftSubmenu' || this.id == 'rightSubmenu' || this.id == 'emptySubmenu')
        {
          return;
        }
        this.set('class', 'mouseoverSubmenu');
      },
      'mouseout': function() {
        if (this.id == subItemId || this.id == 'leftSubmenu' || this.id == 'rightSubmenu' || this.id == 'emptySubmenu')
        {
          return;
        }
        this.set('class', 'normalSubmenu');
      },
      'click': function() {
        if (this.id == subItemId)
        {
          return;
        }
        if ( this.id == 'intro') {
          window.location = 'index.html';
        } else {
          window.location = this.id + '.html';
        }
      }
    });
  });
}

function hideSubMenu()
{
  $('subNav').setStyle('display', 'none');
}