/* * TopNav.js, by Jeff W. McClung * * Purpose - This file should contain all of the javascript nessesary for the top-nav * drop-down menus on www.americas.creative.com. * * Componants - * Function to find co-ordinates of a given anchor ( ) - anchorposition.js * Function to grab a given object by its name * Function to hide all menu items * Function to show a given menu item * * All this code should be cross-browser compatible. It should work in IE4+, NS4+, Opera 5, and Mozilla 0.9+. * * This code is largely my own creation, but is also largely inspired and in some cases outright borrowed from * the fine work found on these two javascript sites: * * http://www.xs4all.nl/~ppk/js/ * http://www.mattkruse.com/ * * Thank you, and H.A.N.D. * --Jeff */ //browser detection, OS detection (Macintosh) var NS4 = 0; var NS6 = 0; var IE4 = 0; var IE5 = 0; var MAC = 0; if (document.layers) { NS4=1; } else if (document.getElementById) { if (navigator.appName == "Netscape") { NS6=1; } else { IE5=1; } } else if (document.all) { IE4=1; } if (navigator.appVersion.indexOf('Mac') != -1) { MAC = 1; } //end browser detection //Global drop-down menu objects x1 = new Object(); x2 = new Object(); x3 = new Object(); x4 = new Object(); //x, y coordinates for the menu objects (used by mmhide [mouse-move hide] function to know when to hide menus) var Top, Left, Bottom, Right; Top = 0; Left = 0; Bottom = 0; Right = 0; //grabs an object by name function getObj(name) { if ((NS6)||(IE5)) { return document.getElementById(name).style; } else if (IE4) { return document.all[name].style; } else if (NS4) { return document.layers[name]; }} //cross-browser variables //ie = hidden, visible var hide = ""; //ns = hide, show var show = ""; if(NS4) { hide="hide"; show="show"; //NS4 vars document.captureEvents(Event.MOUSEMOVE); //NS4 event capture document.onmousemove=mmHide; } else { hide="hidden"; show="visible"; } //IE4/5, NS6 vars if(NS6){ document.addEventListener("mousemove", mmHide, false); } //NS6 event capture function hideAll() { /* cross-browser object vars (x1, x2, etc. = the pull-down menus) defined after the in the document. */ x1.visibility = hide; x2.visibility = hide; x3.visibility = hide; x4.visibility = hide; } function showMenu(name, aName, homePage) { if ( ((MAC)&&(homePage)) || ((homePage)&&(!IE4)&&(!IE5)) ) {} else { //the menus won't show over Flash animations in anything but IE. hideAll(); position = getAnchorPosition(aName); x = getObj(name); //offset positions var offsetY, offsetX; Top = position.y; Left = position.x; //Fixing "Top" and the Top Offset so this looks alike in many browsers if ((IE5)||(IE4)) { offsetY = 21; } if (NS6) { Top = Top - 15; offsetY = 29; } if (NS4) { offsetY = 27; } if (MAC) { Top = Top + 18; } if ((x.visibility == "VISIBLE")||(x.visibility == "HIDDEN")) { Top = Top - 15; offsetY = 30; } //Opera 5 if (name != "menu1") {Left = Left - 10; offsetX = 10;} else {Left = Left - 10; offsetX = 10;} //Top, Left, Right, Bottom used by mmhide to know when to hide the menus (global vars). if (name == "menu1") { Right = Left + 155; Bottom = Top + 120; } // Home if (name == "menu2") { Right = Left + 150; Bottom = Top + 120; } // Corporate if (name == "menu3") { Right = Left + 165; Bottom = Top + 210; } // Products if (name == "menu4") { Right = Left + 175; Bottom = Top + 210; } // Support if (name == "menu5") { Right = Left + 155; Bottom = Top + 260; } // Shop if (name == "menu6") { Right = Left + 165; Bottom = Top + 190; } // Contact Us //do the deed x.top = Top + offsetY; x.left = Left + offsetX; x.visibility = show; } } function mmHide(e) { //mouse move hide /* cross-browser object vars (x1, x2, etc. = the pull-down menus) defined after the in the document. */ if((IE4)||(IE5)){ //cross-browser vars for the mouse coordinates if ((x1.visibility == "HIDDEN")||(x1.visibility == "VISIBLE")) { //in other words, is this Opera? mouseX = window.event.x; mouseY = window.event.y; } else { mouseX = window.event.x+document.body.scrollLeft; mouseY = window.event.y+document.body.scrollTop; } }else if((NS4)||(NS6)){ mouseX = e.pageX; mouseY = e.pageY; } if ((mouseX > Right)||(mouseX < Left)||(mouseY > Bottom)||(mouseY < Top)) { hideAll(); } }