function topNav() {
  var tn = '<table cellpadding=0 cellspacing=1 border=0 width=100%>';
  tn += '<tr>';
  tn += '<td width=3%><div>&nbsp;</div></td>';
  for (var tnCount = 0; tnCount < tnav.length; tnCount++) {
    tn += '<td width=11%><div id="nav'+tnCount+'" class="navMain" onMouseover="menu('+tnCount+',-1,-1);" onMouseout="closeMenu(1);" onClick="'+tlink[tnCount]+'">'+tnav[tnCount]+'</div></td>';
    if (tnCount < (tnav.length - 1)) {
      tn += '<td width=2%><div>|</div></td>';
    }
  }
  tn += '<td><div>&nbsp;</div></td>';
  tn += '</tr>';
  tn += '</table>';
  document.write(tn);
}

function get(id) {return document.getElementById(id);}

function buildNav() {
  for (var c=0;c<tnav.length;c++) {
    var sub1Length = eval('snav_'+c+'.length');
    if (sub1Length > 0) {
      var posY = get('topAd') ? (get('topAd').offsetHeight + get('nav').offsetHeight) : (get('nav').offsetHeight);
      var posX = get('nav'+c).offsetParent.offsetLeft + 6;
      if (c == 1) {}
      document.write('<div id="snav'+c+'" class="drillShell" style="z-index:'+(c+10)+';top:'+posY+'px;left:'+posX+'px;">'+writeMenu(c,-1)+'</div>');
      for (var c1=0;c1<sub1Length;c1++) {
        var sub2Length = eval('snav_'+c+'_'+c1+'.length');
        if (sub2Length > 0) {
          var posX1 = posX + get('snav'+c).offsetWidth - 5;
          var posY1 = posY + get('bnav'+c+'_'+c1).offsetTop + 5;
          document.write('<div id="snav'+c+'_'+c1+'" class="drillShell" style="z-index:'+(c+100)+';top:'+posY1+'px;left:'+posX1+'px;">'+writeMenu(c,c1)+'</div>');
        }
      }
    }
  }
  navBuilt = true;
}

function writeMenu(n,s) {
  if (s < 0) {
    var curMenu = eval('snav_'+n);
    var curLink = eval('link_'+n);
    var id = "bnav"+n;
    var parent = tnav[n];
  } else {
    var curMenu = eval('snav_'+n+'_'+s);
    var curLink = eval('link_'+n+'_'+s);
    var id = "bnav"+n+"_"+s;
    var parent = eval('snav_'+n+'[s]');
  }
  var butClass = "drillButM";
//  if ((n == 0 && s > -1) || (n == 1 && s == 0)) {
//    butClass = "drillButL";
//  } else if (n == 3) {
//    butClass = "drillButM";
//  } else if (n == 4 && s > -1) {
//    butClass = "drillButS";
//  } else if (n == 6 || n == 5) {
//    butClass = "drillButT";
//  }
  var menu = '';
  for(var c=0;c < curMenu.length;c++) {
    menu += '<div id="'+id+'_'+c+'" class="'+butClass+'" onClick="'+curLink[c]+'" ';
    if (s < 0)
      menu += 'onMouseover="menu('+n+','+c+',-1);" ';
    else
      menu += 'onMouseover="menu('+n+','+s+','+c+');" ';
    menu += 'onMouseout="closeMenu(1);">'+curMenu[c]+'</div>';
  }
  return menu;
}

function closeMenu(st) {
  if (st == 1) {
    closeAll = setTimeout('closeMenu(2);',500);
  } else {
    menu(-1,-1,-1);
  }
}

function menu(n,s1,s2) {
  if (navBuilt) {
    if (openN > -1)
      clearTimeout(closeAll);
    // CLOSE OPEN TOP NAV - style of re-closed top nav items
    if (openN > -1 && openN != n) {
      get('nav'+openN).style.color = "white";
      if (eval('snav_'+openN+'.length') > 0)
        get('snav'+openN).style.visibility = "hidden";
    }
    // CLOSE OPEN SUB 1 - style of already-viewed menu items
    if (openS1 > -1 && openS1 != s1) {
      opensub1 = get('bnav'+openN+'_'+openS1);
      opensub1.style.backgroundColor = "red";
      opensub1.style.color = "white";

      if (eval('snav_'+openN+'_'+openS1+'.length') > 0)
        get('snav'+openN+'_'+openS1).style.visibility = "hidden";
    }
    // CLOSE OPEN SUB 2 - style of already-viewed SUBmenu items
    if (openS2 > -1 && openS2 != s2) {
      opensub2 = get('bnav'+openN+'_'+openS1+'_'+openS2);
      opensub2.style.backgroundColor = "red";
      opensub2.style.color = "white";
    }
    // TOP NAV EFFECTS
    
    if (n > -1) {
      // Initial style of primary level menu
      get('nav'+n).style.color = "#FFCC66";
      if (eval('snav_'+n+'.length') > 0) {
        sub0 = get('snav'+n);
        sub0.style.visibility = "visible";
        sub0.style.backgroundColor = "red";
        sub0.style.color = "orange";
      }
    }
    // SUB 1 EFFECTS - for parent of currently open child
    if (s1 > -1 && s1 < eval('snav_'+n+'.length')) {
      sub1 = get('bnav'+n+'_'+s1);
      sub1.style.color = "white";
      sub1.style.backgroundColor = "#000066";

      if (eval('snav_'+n+'_'+s1+'.length') > 0) {
        // Initial style of secondary level menu
        sub0 = get('snav'+n+'_'+s1)
        sub0.style.visibility = "visible";
        sub0.style.backgroundColor = "red";
        sub0.style.color = "orange";
      }
    }
    // SUB 2 EFFECTS - for currently open and selected submenu item
    if (s2 > -1 && s2 < eval('snav_'+n+'_'+s1+'.length')) {
      sub2 = get('bnav'+n+'_'+s1+'_'+s2);
      sub2.style.backgroundColor = "#000066";
      sub2.style.color = "white";
    }
    openN = n;
    openS1 = s1;
    openS2 = s2;
  }
}

function navLink(url,win) {
  if (win == "self") {
    window.location = url;
  } else if (win == "new") { 
    var newWin = window.open(url,'simusic');
    newWin.focus();
  }
}
