/****************************************************************************** * navbar.js * * * * Copyright 1999 by Mike Hall. * * Web address: http://www.brainjar.com * * Last update: December 13, 1999. * * * * Creates a interactive DHTML navigation bar with drop-down menus. * * Note: requires dhtmllib.js * * Script featured on Dynamic Drive DHTML code library (http://dynamicdrive.com) * ******************************************************************************/ //***************************************************************************** // Define the default look of the navigation bar. //***************************************************************************** var navBarY = 0; // Default position. var navBarX = 0; var navBarWidth = -1; // Sizes var navBarHeaderWidth = 100; var navBarMenuWidth = 175; var navBarBorderWidth = 1; var navBarPaddingWidth = 4; var navBarBorderColor = "#000000"; // Colors. var navBarHeaderBgColor = "#999999"; var navBarHeaderFgColor = "#000000"; var navBarActiveBgColor = "#666666"; var navBarActiveFgColor = "#ffffff"; var navBarItemBgColor = "#cccccc"; var navBarItemFgColor = "#000000"; var navBarHighBgColor = "#000080"; var navBarHighFgColor = "#ffffff"; var navBarHeaderFontFamily = "Arial,Helvetica,sans-serif"; // Fonts. var navBarHeaderFontStyle = "plain"; var navBarHeaderFontWeight = "bold"; var navBarHeaderFontSize = "10pt"; var navBarItemFontFamily = "MS Sans Serif,Arial,Helvetica,sans-serif"; var navBarItemFontStyle = "plain"; var navBarItemFontWeight = "bold"; var navBarItemFontSize = "8pt"; var navBarTrackX = false; // Tracking flags. var navBarTrackY = false; //***************************************************************************** // Define the navigation bar menu array. //***************************************************************************** var navBarMenus = new Array(); // List of menus. //***************************************************************************** // Initialize the navigation bar. //***************************************************************************** var navBar; // Base layer. var navBarHeight; // Height of navigation bar headers. // These variables are used to determine if a resize event is a true one. // Necessary due to a bug in older NS4 releases. var origWidth; var origHeight; function navBarInit() { var menu = new Array(); var layer, norm, high, dmmy; var last; var width; var on, off; var i, j, x, y, z; var link; if (!isMinNS4 && !isMinIE4) return; // Fix for resize bug. if (isMinNS4) { origWidth = window.innerWidth; origHeight = window.innerHeight; } window.onresize = navBarReload; // Check sizes. if (navBarMenuWidth < navBarHeaderWidth) navBarMenuWidth = navBarHeaderWidth; // Build the navigation bar. navBarBuild(); moveLayerTo(navBar, navBarX, navBarY); showLayer(navBar); // Get each menu, position it, initialize it and set up event handling. x = 0; y = 0; i = 0; while ((layer = getLayer("menu" + (i + 1), window)) != null) { // Set menu width. width = navBarMenuWidth; if (i == navBarMenus.length - 1) width = navBarWidth - x; // Initialize the menu container. menu[i] = layer; moveLayerTo(layer, x, y); // Initialize the three layers that make up each menu item. z = 0; j = 0; while ((layer = getLayer("item" + (i + 1) + "_" + (j + 1), menu[i])) != null) { // Normal item layer. norm = layer; moveLayerTo(norm, 0, z); clipLayer(norm, navBarBorderWidth, navBarBorderWidth, width - navBarBorderWidth, getHeight(norm) - navBarBorderWidth); if (isMinNS4 && j > 0) layer.visibility = "inherit"; else showLayer(norm); // Highlighted item layer. high = getLayer("high" + (i + 1) + "_" + (j + 1), menu[i]); moveLayerTo(high, 0, z); clipLayer(high, navBarBorderWidth, navBarBorderWidth, width - navBarBorderWidth, getHeight(norm) - navBarBorderWidth); hideLayer(high); // Transparent, dummy item layer. Used to capture mouse events. dmmy = getLayer("dmmy" + (i + 1) + "_" + (j + 1), menu[i]); moveLayerTo(dmmy, 0, z); clipLayer(dmmy, 0, 0, width, getHeight(norm)); if (j == 0) menu[i].high = high; else { dmmy.high = high; dmmy.onmouseover = navBarItemOn; dmmy.onmouseout = navBarItemOff; } link = navBarMenus[i][j * 2 + 1]; if (link != "") { if (isMinNS4) { dmmy.document.link = link; dmmy.document.onmousedown = navBarItemGo; } if (isMinIE4) { dmmy.link = link; dmmy.onmousedown = navBarItemGo; } } // Set up position for next item. z += getHeight(norm) - navBarBorderWidth; if (j == 0) off = z + navBarBorderWidth - 1; on = z + navBarBorderWidth; j++; } x += navBarHeaderWidth - navBarBorderWidth; // Set up clipping sizes for menu container. menu[i].offWidth = navBarHeaderWidth; menu[i].offHeight = off + 1; menu[i].onWidth = width; menu[i].onHeight = on; menu[i].onmouseover = navBarMenuOn; menu[i].onmouseout = navBarMenuOff; clipLayer(menu[i], 0, 0, menu[i].offWidth, menu[i].offHeight); // Display the menu container layer. showLayer(menu[i]); i++; } // Save bar height. navBarHeight = menu[i - 1].offHeight; // Dummy out mouse events for the filler. menu[i - 1].onmouseover = null; menu[i - 1].onmouseout = null; // Clip filler. clipLayer(menu[i - 1], 0, 0, menu[i - 1].onWidth, menu[i - 1].offHeight); // Clip base layer so it won't interfere with underlying page. clipLayer(navBar, 0, 0, navBarWidth, menu[0].offHeight); // Set tracking. if (navBarTrackX || navBarTrackY) { navBarScroll(); if (isMinNS4) setInterval('navBarScroll()', 20); if (isMinIE4) window.onscroll = navBarScroll; } } //***************************************************************************** // Dynamically build the HTML for the navigation bar and add it to the page. //***************************************************************************** function navBarBuild() { var i, j, k, str, tmp; var padding, width; var headText, actvText, itemText, highText; var tblStart, tblEnd; // Add a dummy menu for filler. navBarMenus[navBarMenus.length] = new Array(" ", ""); // Set total navigation bar width according to value defined: // // < 0 - set to window width. // = 0 - calulate size according to menu definition. // > 0 - use given value or calculated size, whichever is greater. width = (navBarMenus.length - 2) * (navBarHeaderWidth - navBarBorderWidth) + (navBarMenus[navBarMenus.length - 2].length > 2 ? navBarMenuWidth : navBarHeaderWidth); if (navBarWidth < 0) navBarWidth = Math.max(getWindowWidth(), getPageWidth()) - navBarX; if (navBarWidth == 0) navBarWidth = width; if (navBarWidth > 0) navBarWidth = Math.max(navBarWidth, width); // Set up code for menu item text. padding = navBarPaddingWidth + navBarBorderWidth; headText = 'color:' + navBarHeaderFgColor + ';' + 'font-family:' + navBarHeaderFontFamily + ';' + 'font-size:' + navBarHeaderFontSize + ';' + 'font-style:' + navBarHeaderFontStyle + ';' + 'font-weight:' + navBarHeaderFontWeight + ';'; actvText = 'color:' + navBarActiveFgColor + ';' + 'font-family:' + navBarHeaderFontFamily + ';' + 'font-size:' + navBarHeaderFontSize + ';' + 'font-style:' + navBarHeaderFontStyle + ';' + 'font-weight:' + navBarHeaderFontWeight + ';'; itemText = 'color:' + navBarItemFgColor + ';' + 'font-family:' + navBarItemFontFamily + ';' + 'font-size:' + navBarItemFontSize + ';' + 'font-style:' + navBarItemFontStyle + ';' + 'font-weight:' + navBarItemFontWeight + ';'; highText = 'color:' + navBarHighFgColor + ';' + 'font-family:' + navBarItemFontFamily + ';' + 'font-size:' + navBarItemFontSize + ';' + 'font-style:' + navBarItemFontStyle + ';' + 'font-weight:' + navBarItemFontWeight + ';'; tblStart = '
| '; tblEnd = ' |