function handleMainNavClick(mainNavLabel) {
  highlightSelectedMenuItem(mainNavLabel);
  showSubNavMenu(mainNavLabel);
}

function highlightSelectedMenuItem(mainNavLabel) {
  var mainNavMenu = document.getElementById('main_nav_menu');
  var anchors = mainNavMenu.getElementsByTagName('A');

  // unhighlight all items
  for (var i = 0; i < anchors.length; i++ ) {
    dojo.debug('anchor: ' + anchors[i]);

    anchors[i].style.margin = '0 40px 5px 0';
    anchors[i].style.background = 'url(../images/common/bullet_lt.gif) no-repeat 100% 50%';

    var span = anchors[i].getElementsByTagName('SPAN')[0];
    span.style.padding = '0 7px 0 0';
  }
  // highlight selected one.
  var selectedAnchor = document.getElementById(mainNavLabel + '_anchor');
  selectedAnchor.style.background = 'url(../images/main_nav_home_bg.gif) no-repeat 100% 50%';
  selectedAnchor.style.margin = '0 0 5px 0';

  var selectedSpan = document.getElementById(mainNavLabel + '_span');
  selectedSpan.style.padding = '0 22px 0 0';

}

// show the appropriate menu
function showSubNavMenu(mainNavLabel) {
//dojo.debug('mainNavMenu: ' + mainNavMenu);

  var subNav = document.getElementById('sub_nav');
  var uls = subNav.getElementsByTagName('UL');
  for (var i = 0; i < uls.length; i++ ) {
    if ((mainNavLabel + '_menu') == uls[i].getAttribute('id')) {
      uls[i].style.display = 'block';
dojo.debug('ul: ' + uls[i].getAttribute('id'));
    } 
    else { uls[i].style.display = 'none'; }
  }
  if (mainNavLabel == 'decade') { 
    showDecadeMenu('1600s'); 
dojo.debug('showing decade menu');
  }
}

function showDecadeMenu(id) {
  //var ul = document.getElementById(id);
  var ulIds = ['1600s', '1700s', '1800s', '1900s', '2000s'];
  var backgroundStyles = [
    'url(/images/decade_arrow.gif) no-repeat 0 0.8em',
    'url(/images/decade_arrow.gif) no-repeat 0 4em',
    'url(/images/decade_arrow.gif) no-repeat 0 7.2em',
    'url(/images/decade_arrow.gif) no-repeat 0 10.4em',
    'url(/images/decade_arrow.gif) no-repeat 0 13.6em',
  ];
  for (var index in ulIds) {
    if (ulIds[index] == id) { 
dojo.debug('ulId: '+ulIds[index]);
      dojo.html.setStyle(dojo.byId(ulIds[index]), 'visibility', 'visible'); 
      dojo.html.setStyle(dojo.byId(ulIds[index]), 'display', 'block'); 
      dojo.html.setStyle(dojo.byId(ulIds[index]), 'background', backgroundStyles[index]); 
    }
    else { dojo.html.setStyle(dojo.byId(ulIds[index]), 'visibility', 'hidden'); }
  }
}
