<!--hide this script from non-javascript-enabled browsers
// Complete javascript menu, works well in explorer and reasonably well in netscape (no hover text color changes on menus)

//check for explorer
if (document.all)
{
  n=0;
  ie=1;
  fShow="visible";
  fHide="hidden";
  menuSubItemStyleClass="clsSubMenuItemIE";
  menuHeaderStyleClass="clsMenuHeaderStyleIE";
}
else if (document.layers)
//assume netscape
{
  n=1;
  ie=0;
  fShow="show";
  fHide="hide";
  menuSubItemStyleClass="clsSubMenuItemNS";
  menuHeaderStyleClass="clsMenuHeaderStyleNS";
}
else
{
//some other totally unsupported browser
  n=0;
  ie=1;
  fShow="visible";
  fHide="hidden";
  menuSubItemStyleClass="clsSubMenuItemIE";
  menuHeaderStyleClass="clsMenuHeaderStyleIE";
}

// as expected netscape gets a bit confused, hence the need for this routine, which gets
// invoked as part of this routines initialisation. You will also need the standard netscape
// resize bug fix included within your HEAD section of your pages.
function RefreshMenuNS()
{
   if (n) // for Netscape only
   {
      var menubarIndex = 1;   // ignore "Home"
      for (index=0;index < top.document.layers.length;index++) 
      {
         if (top.document.layers[index].id.indexOf("submenu") != -1)
         {
            layerHTMLstring = "";
            layerHTMLstring += "<table border="+menubar.subMenuPaneBorder+" bgcolor="+menubar.bgColor+">\n";
        
            for (itemIndex=0;itemIndex < top.document.layers[index].document.links.length;itemIndex++)
            {
               /* Now rewrite the layer using our stored text. */
               layerHTMLstring += "<tr><td><a class="+menuSubItemStyleClass+" title='' href='";
               layerHTMLstring += menubar.subMenuLayerDataArray[menubarIndex][itemIndex].location;
               layerHTMLstring += "'>";
               layerHTMLstring += menubar.subMenuLayerDataArray[menubarIndex][itemIndex].text;
               layerHTMLstring += "&nbsp;</a></td></tr>\n";
            }

            layerHTMLstring += "</table>\n";
            top.document.layers[index].document.open();
            top.document.layers[index].document.write(layerHTMLstring);
            top.document.layers[index].document.close();
            top.document.layers[index].onMouseOver = setCurMenuVisible2;
            top.document.layers[index].onMouseOut = setCurMenuInvisible;
            menubarIndex++;
         }

         if (top.document.layers[index].id.indexOf("menuheader") != -1)
         {
            top.document.layers[index].visibility = fShow;
         }
      }
   }
}

function MenuLayerData()
{
  // no code needed, just a hook used for netscape layers
}

function addItem(idItem, text, location)
{
  var Lookup = "<!-- ITEM "+idItem+" -->";
  if (HTMLstr.indexOf(Lookup) != -1)
  {
    alert(idItem + " already exist");
    return;
  }

  var MENUitem = "\n<!-- ITEM "+idItem+" -->\n";
  
  /* each menu header is given width according to its text length and a running */
  /* total is kept, to allow a final column to be appended which ensures the menu */
  /* bar fills the screen width */
  this.menuHeaderPaneWidth = (text.length + 2) * this.menuHeaderPaneWidthFactor;
  tabwidth=tabwidth+this.menuHeaderPaneWidth;
  if (n)
  {
    var index = this.subMenuLayerDataArray.length;
    this.subMenuLayerDataArray[index] = new Array();
    this.menuHeaderLayerDataArray[idItem] = new MenuLayerData();
    this.menuHeaderLayerDataArray[idItem].location = location;

    MENUitem += "<td width="+this.menuHeaderPaneWidth+" height="+this.subMenuPaneHeight+">\n";
    MENUitem += "<ilayer name="+idItem+"menuheader" + " width="+this.menuHeaderPaneWidth+" visibility=hide>";
    MENUitem += "<a title='" + text + "' ";
    if (location!=null) MENUitem += "href='"+location+"' ";
    else MENUitem += "href='.' ";
    MENUitem += " class="+menuHeaderStyleClass;
    MENUitem += " onMouseOver='displaySubMenu(";
    MENUitem += '"';
    MENUitem += idItem;
    MENUitem += '"';
    MENUitem += ")' onMouseOut='setCurMenuInvisible2();' onclick='return ";
    if (location==null) MENUitem += "false;'>";
    else MENUitem += "true;'>";
    MENUitem += "&nbsp;&nbsp;";
    MENUitem += text;
    MENUitem += "&nbsp;";
    MENUitem += "</a>";
    MENUitem += "</ilayer>";
    MENUitem += "</td>\n";
  }
  else if (ie)
  {
    MENUitem += "<td  height="+this.subMenuPaneHeight+">\n";
	/* the menuHeaderStyle on the DIV seems to affect vertical positioning of the header menubar text? */
    MENUitem += "<div width="+this.menuHeaderPaneWidth+" id='"+idItem+"' style='position:relative; "+this.menuHeaderStyle+"' "
    MENUitem += 'onMouseOver="';
    MENUitem += "displaySubMenu('"+idItem+"')";
    MENUitem += '" ';
    MENUitem += "onMouseOut='setCurMenuInvisible();'>\n";
    //MENUitem += "<a class="+menuHeaderStyleClass+" title='"+text+"'";
    MENUitem += "<a class="+menuHeaderStyleClass+" title=''";
    if (location != null)
    {
      MENUitem += "href='"+location+"' onClick='hideCurrentMenu()'";
    }
    else
    {
      MENUitem += "href='.' ";
      MENUitem += "onClick='return false;'"
    }
    MENUitem += ">";
    MENUitem += "&nbsp;&nbsp;";
    MENUitem += text;
    MENUitem += "&nbsp;";
    MENUitem += "</a>\n";
    MENUitem += "</div>\n";
    MENUitem += "</td>\n";
  }
  
  MENUitem += "<!-- END OF ITEM "+idItem+" -->\n";
  MENUitem += "<!-- MAIN_MENU -->\n";

  HTMLstr = HTMLstr.replace("<!-- MAIN_MENU -->\n", MENUitem);
  
}

function addSubItem(idParent, text, location)
{
  var MENUitem = "";
  Lookup = "<!-- ITEM "+idParent+" -->";
  if (HTMLstr.indexOf(Lookup) == -1)
  {
    alert(idParent + " not found");
    return;
  }
  Lookup = "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->";
  if (HTMLstr.indexOf(Lookup) == -1)
  {
    if (n)
    {
	  MENUitem += "\n";
      MENUitem += "<layer id='"+idParent+"submenu' visibility=hide bgcolor='"+this.bgColor+"'";
      MENUitem += " onMouseOut='setCurMenuInvisible();' onMouseOver='setCurMenuVisible2();'";
      MENUitem += "'>\n";
      MENUitem += "<table border="+this.subMenuPaneBorder+" bgcolor="+this.bgColor+">\n";
      MENUitem += "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->\n";
      MENUitem += "</table>\n";
      MENUitem += "</layer>\n";
    }
    else if (ie)
    {
      MENUitem += "\n";
      MENUitem += "<span bgcolor=black id='"+idParent+"submenu' onMouseOut='setCurMenuInvisible();'";
      MENUitem += " onMouseOver='setCurMenuVisible();'";
      MENUitem += " style='background-color:"+this.bgColor+"; position:absolute; visibility: hidden '>\n";
      MENUitem += "<table border="+this.subMenuPaneBorder+" bgcolor="+this.bgColor+">\n";
      MENUitem += "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->\n";
      MENUitem += "</table>\n";
      MENUitem += "</span>\n";
    }

    MENUitem += "\n";
    MENUitem += "<!-- SUB_MENU -->\n";
    HTMLstr = HTMLstr.replace("<!-- SUB_MENU -->\n", MENUitem);
  }

  if (n)
  {
      var currentMenuIndex = this.subMenuLayerDataArray.length - 1;
      var index = this.subMenuLayerDataArray[currentMenuIndex].length;
      this.subMenuLayerDataArray[currentMenuIndex][index] = new MenuLayerData();
      this.subMenuLayerDataArray[currentMenuIndex][index].text = text;
      this.subMenuLayerDataArray[currentMenuIndex][index].location = location;
  }
  
	MENUitem = "<tr><td><a class="+menuSubItemStyleClass+" title='' href='"+location+"'>"+text+"&nbsp;</a></td></tr>\n";
  MENUitem += Lookup;
  HTMLstr = HTMLstr.replace(Lookup, MENUitem);
  

}

function showMenuBar()
{
  document.writeln(HTMLstr);
}

function MenuBar()
{
//  this.bgColor = "#005bbf";
this.bgColor="#3366CC";
  var tabwidth=0;
  
  if (ie)
  {
    /* style (as well as styleClass) needed for IE DIV */
    this.menuHeaderStyle = "font: bold 7pt Verdana, Arial, Helvetica; color: white; text-decoration: none;";
    //this.subMenuPaneWidth = subMenuPaneWidth;
    this.menuHeaderPaneWidthFactor = 7;
    this.subMenuPaneHeight = 18;
    this.menuHeaderIndent = 7;
  }
  else if (n)
  {
    this.subMenuLayerDataArray = new Array();
    this.menuHeaderLayerDataArray = new Array();
	
    this.menuHeaderStyle = "font: bold 8pt Verdana, Arial, Helvetica; color: white; text-decoration: none;";
    //this.subMenuPaneWidth = subMenuPaneWidth - 9;
    this.menuHeaderPaneWidthFactor = 6;
    this.subMenuPaneHeight = 18;
    this.menuHeaderIndent = 1;
  }
  this.mainPaneBorder = 0;
  this.subMenuPaneBorder = 0;

  this.addItem    = addItem;
  this.addSubItem = addSubItem;
  this.showMenuBar   = showMenuBar;

  lastMenu = null;
  lastMenuHeading = null;

  HTMLstr = "<!-- MENU PANE DECLARATION BEGINS -->\n";
  HTMLstr += "\n";
  HTMLstr += "<table width=100% cellpadding=0 height=14 cellspacing=0 bgcolor="+this.bgColor+" border="+this.mainPaneBorder+">\n";
  HTMLstr += "<tr>";
  HTMLstr += "<td width='"+this.menuHeaderIndent+"'><font face='verdana,arial,sans-serif' size='1' color='#ffffff'>&nbsp;</font></td>";
  HTMLstr += "<!-- MAIN MENU STARTS -->\n";
  HTMLstr += "<!-- MAIN_MENU -->\n";
  HTMLstr += "<!-- MAIN MENU ENDS -->\n";
  HTMLstr += "<td width='RIGHTMARGIN'><font face='verdana,arial,sans-serif' size='1' color='#ffffff'>&nbsp;</font></td>";
  HTMLstr += "</tr>\n";
  HTMLstr += "</table>\n";
  HTMLstr += "\n";
  HTMLstr += "<!-- SUB MENU STARTS -->\n";
  HTMLstr += "<!-- SUB_MENU -->\n";
  HTMLstr += "<!-- SUB MENU ENDS -->\n";
  HTMLstr += "\n";
  HTMLstr += "<!-- MENU PANE DECLARATION ENDS -->\n";
}

function displaySubMenu(idMainMenu)
{
  var menu;
  var submenu;
  //alert(eval("nav" + idMainMenu));
  
  if (n)
  {
    idMainMenuLayerName = idMainMenu + "menuheader";
    menu = document.layers[idMainMenuLayerName];

     if (document.layers[idMainMenu+"submenu"] != null)
    {
      submenu = document.layers[idMainMenu+"submenu"];
      if (lastMenu != null && lastMenu != submenu) hideCurrentMenu();
	  
      submenu.left = document.layers[idMainMenuLayerName].pageX + 3;
      submenu.top  = document.layers[idMainMenuLayerName].pageY +
      document.layers[idMainMenuLayerName].clip.height;
		if (eval("nav" + idMainMenu)) {
      		submenu.visibility = fShow;
		}

      submenu.onMouseOut=hideCurrentMenu;
    } else
    {
      if (lastMenu != null) hideCurrentMenu();
    }
  }
  else if (ie)
  {
     if (document.getElementById(idMainMenu+"submenu") != null)
    {
      menu = eval(idMainMenu);
      submenu = eval(idMainMenu+"submenu.style");

      var totalOffset = 0;
      var item = menu;
      do
      {
        totalOffset += eval('item.offsetLeft');
        item = eval('item.offsetParent');
      } while (item != null);
      submenu.left = totalOffset+3;

      submenu.top  = menu.style.top;
	  if (eval("nav" + idMainMenu)) {
      		submenu.visibility = fShow;
		}
      
    }

    if (lastMenu != null && lastMenu != submenu)
    {
      hideCurrentMenu();
    }

  }
  
  setCurMenuVisible();
  lastMenu = submenu;
  lastMenuHeading = menu;

}

function hideCurrentMenu()
{
  if (lastMenu != null)
  {
    lastMenu.visibility = fHide;
    lastMenu = null;
    lastMenuHeading = null;
  }
}

var timeOutID = null;
function setCurMenuVisible()
{
   if (timeOutID)
  {
    clearTimeout(timeOutID);
    timeOutID = null;
  }
}

function setCurMenuVisible2()
{
   if (timeOutID)
  {
    clearTimeout(timeOutID);
    timeOutID = null;
  }

  /* This timeout when executed should clear out any hide timeout set by leaving the menu bar. (?) */  
  timeOutID = setTimeout("setCurMenuVisible()", 300)
  
}

function setCurMenuInvisible()
{
   if (ie || 
         (n && lastMenuHeading && lastMenu &&
          lastMenuHeading.name+"submenu" != lastMenu.name))
  {
    timeOutID = setTimeout("hideCurrentMenu()", 500)
  }
}

function setCurMenuInvisible2()
{
   if (n)
  {
    timeOutID = setTimeout("hideCurrentMenu()", 500)
  }
}

//only used for non netscape and non explorer browsers
//since all they get are option lists
function LoadPage(strPDM) {
	intIndex = eval('document.all.' + strPDM + '.selectedIndex');
	if(eval('document.all.' + strPDM + '[' + intIndex + '].value') != '') {
		top.location = eval('document.all.' + strPDM + '[' + intIndex + '].value');
	}
}


var menubar = new MenuBar();
var tabwidth=0;
	
	//products
	menubar.addItem("prods", "Products & Advice", null);
	menubar.addSubItem("prods","Common Javascript","commonjs.php");
	menubar.addSubItem("prods","CommonADO Classes","commonado.php");
	menubar.addSubItem("prods","Class Architect","classarchitect.php");
	menubar.addSubItem("prods","Programming Tips","progtips.php");
	menubar.addSubItem("prods","Dynamic Option Lists","listexample.php");
	var navprods=true;
	
	//ADO Sites
	menubar.addItem("ado", "ASP/ADO Sites", null);
	menubar.addSubItem("ado","ASPFree","http://www.aspfree.com/default.asp");
	menubar.addSubItem("ado","4GuysFromRollA","http://www.4guysfromrolla.com");
	menubar.addSubItem("ado","ASPWorkshops","http://www.aspworkshops.com");
	menubar.addSubItem("ado","15Seconds","http://www.15seconds.com");
	menubar.addSubItem("ado","ASP101","http://www.asp101.com");
	menubar.addSubItem("ado","ASPWire","http://www.aspwire.com");
	menubar.addSubItem("ado","ASPIndex","http://www.aspin.com");
	var navado=true;

	//VB Sites
	menubar.addItem("vb", "VB Sites", null);
	menubar.addSubItem("vb","AbstractVB","http://abstractvb.com");
	menubar.addSubItem("vb","CodeProject","http://www.codeproject.com");
	var navvb=true;

	//Books
	menubar.addItem("books", "Books", null);
	menubar.addSubItem("books", "Recommended Reading", "books.php");
	var navbooks=true;

	//Contact
	menubar.addItem("contactus", "Contact Us", null);
	menubar.addSubItem("contactus","Wise Tuna Forum","forumsmf/index.php");
//	menubar.addSubItem("contactus","Email Feedback","contactform.php");
//	menubar.addSubItem("contactus", "View/Leave Comments", "gb.php");
	menubar.addSubItem("contactus", "Who is Wise Tuna?", "deepthought.php");
	var navcontactus=true;

	//Fun
	menubar.addItem("fun","Light Relief",null);
	menubar.addSubItem("fun","Tune a Tuna","tunafish.php");
	var navfun=true;

//code added 12/6/01
// force total table column widths to be width of screen (e.g. 100%)
tabwidth=tabwidth+menubar.menuHeaderIndent+menubar.menuHeaderIndent;
if (ie) var bodywidth=document.body.clientWidth-tabwidth;
else var bodywidth=window.innerWidth-tabwidth;
HTMLstr = HTMLstr.replace("RIGHTMARGIN", bodywidth);


	menubar.showMenuBar();

if (ie)
{
  document.body.onclick=hideCurrentMenu;
  document.body.onscroll=hideCurrentMenu;
}
else if (n)
{
  document.onmousedown=hideCurrentMenu;
  window.captureEvents(Event.MOUSEMOVE);
  RefreshMenuNS();
}

//stop hiding -->
