/* Written by Nathan Wilkes, Saraden Studios All rights reserved Copyright (c) 2002 nathan@saraden.co.nz */ menuImageNone = 0; menuImageIcon = 1; menuImageFull = 2; menuDivsDirty = new Array(); menuSpacers = 0; menuNavWidth = 0; function menuObjMenu (theClass) { this.CSSClass = theClass; this.DisplayDiv = null; this.Children = new Array(); this.AddChild = function AddChild (childobj) { var theIDX; theIDX = this.Children.length; this.Children[theIDX] = childobj; return childobj; } } function menuObjItem (theImage, imagemouseover, imagewidth, imageheight, theImageType, theText, theURL, theMenuObj) { this.Image = theImage; this.ImageMouseover = imagemouseover; this.ImageWidth = imagewidth this.ImageHeight = imageheight; this.ImageType = theImageType; this.Text = theText; this.URL = theURL; this.PopupMenu = theMenuObj; } function menuDefine (baseclass)//, menuitem1(p=1)... { var theObj, x; theObj = new menuObjMenu (baseclass); for (x = 1; x < arguments.length; x++) theObj.AddChild (arguments[x]); return theObj; } function menuItem (image, imagemouseover, imagewidth, imageheight, imagetype, text, url, menuobj) { return new menuObjItem (image, imagemouseover, imagewidth, imageheight, imagetype, text, url, menuobj); } function menuCountChildren (obj) { var fChildren = false, iCount = 0, iTempCount = 0, x; for (x = 0; x < obj.Children.length; x++) { if (obj.Children[x].PopupMenu != null) { fChildren = true; iTempCount = menuCountChildren (obj.Children[x].PopupMenu); if (iTempCount > iCount) iCount = iTempCount; } } return fChildren?iCount+1:iCount; } function menuSetImage (imageid, image) { if (document.getElementById) document.getElementById(imageid).src = image; else if (eval ("document."+imageid)) eval ("document."+imageid+".src = '"+image+"'"); } function DrawNavigation (NavWidth) { var x, ImagesWidth, aFlag, moverextra, moutextra; for (x = 0; x < menuMaxLevels; x++) menuDivsDirty[x] = false; //work out how big the spacers need to be menuNavWidth = NavWidth; ImagesWidth = 0; for (x = 0; x < menu_RootObject.Children.length; x++) ImagesWidth += menu_RootObject.Children[x].ImageWidth; menuSpacers = Math.round((NavWidth-ImagesWidth) / (menu_RootObject.Children.length+1)); //Draw the nav images and tags in for (x = 0; x < menu_RootObject.Children.length; x++) { if (menuSpacers > 0) document.write (""); aFlag = false; if (menu_RootObject.Children[x].URL != null) aFlag = true; if (menu_RootObject.Children[x].PopupMenu != null) aFlag = true; if (menu_RootObject.Children[x].ImageMouseover != null) aFlag = true; if (aFlag) { moverextra = ""; moutextra = ""; if (menu_RootObject.Children[x].ImageMouseover != null) { moverextra = "menuSetImage ('menuimgroot"+x+"', '"+menu_RootObject.Children[x].ImageMouseover+"');"; moutextra = "menuSetImage ('menuimgroot"+x+"', '"+menu_RootObject.Children[x].Image+"');"; } document.write (""); } document.write ("\""+menu_RootObject.Children[x].Text+"\""); if (aFlag) document.write (""); } } function setZIndex (styleobj) { var high; high = 20; if (document.getElementById) { var aDivs = document.getElementsByTagName("DIV"); for (var x = 0; x < aDivs.length; x++) if (aDivs[x].style.zIndex > high) high = aDivs[x].style.zIndex; } else { for (var x = 0; x < document.layers.length; x++) if (document.layers[x].zIndex > high) high = document.layers[x].zIndex; } styleobj.zIndex = high+1; } function GetMenuWidth (menuobj) { var iIdx = menuobj.DisplayDiv; var tobj; if (document.getElementById) tobj = document.getElementById("menuLayer"+iIdx); else if (document.layers) tobj = document.layers["menuLayer"+iIdx]; if (tobj) { if (document.getElementById) return Number(tobj.offsetWidth); else if (document.layers) return Number(tobj.document.width); } else return 0; } function menuDrawPopup (parent, child) { var x, layIDX, pObj, cObj, mObj, sContent, iLayX, iLayY, rObj, rChild, pPath; var sWidth, flag, tobj, cutidx, tmpstr, pcut, iChildNum; //Get objects pObj = eval(parent); cObj = eval(parent+"."+child); mObj = eval(parent+"."+child+".PopupMenu"); //Check for allready open state if (mObj.DisplayDiv != null) { if (document.getElementById) tobj = document.getElementById("menuLayer"+mObj.DisplayDiv); else if (document.layers) tobj = document.layers["menuLayer"+mObj.DisplayDiv]; tobj.onmouseover(); return; } //Get free layer. layIDX = -1; for (x = 0; x < menuMaxLevels; x++) if (!menuDivsDirty[x]) { menuDivsDirty[x] = true; layIDX = x; break; } //No free layers - see if there is one marked as closing we can destroy if (layIDX == -1) for (x = 0; x < menuMaxLevels; x++) { if (document.getElementById) tobj = document.getElementById("menuLayer"+x); else if (document.layers) tobj = document.layers["menuLayer"+x]; if (tobj.menuTimerID != null) { menuClosePopup (tobj.parentref, tobj.childref, true); menuDivsDirty[x] = true; layIDX = x; break; } } if (layIDX == -1) return; mObj.DisplayDiv = layIDX; //build content sContent = "" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"
" for (x = 0; x < mObj.Children.length; x++) { flag = false; if (mObj.Children[x].PopupMenu != null) flag = true; tags = "onMouseOver=\"menuDrawPopup('"+parent+"."+child+".PopupMenu', 'Children["+x+"]');\" onMouseOut=\"menuClosePopup ('"+parent+"."+child+".PopupMenu', 'Children["+x+"]');\""; if (flag) sContent = sContent + "
"; if (mObj.Children[x].URL != null) sContent = sContent + ""; else sContent = sContent + "" switch (mObj.Children[x].ImageType) { case 0: sContent = sContent + mObj.Children[x].Text; break; case 1: sContent = sContent + "  " + mObj.Children[x].Text break; case 2: sContent = sContent + ""+mObj.Children[x].Text+"
" break; } if (flag) { sContent = sContent + "
" if (document.layers) { sContent = sContent + "" } sContent = sContent + ""+(document.layers?"":"")+"
" } if (mObj.Children[x].URL != null) sContent = sContent + "" else sContent = sContent + "" if (flag) sContent = sContent + "
" else sContent = sContent + "
" } sContent = sContent +"
" //Write layer contents if (document.getElementById) document.getElementById("menuLayer"+layIDX).innerHTML = sContent; else if (document.layers) { document.layers["menuLayer"+layIDX].document.open (); document.layers["menuLayer"+layIDX].document.write (sContent); document.layers["menuLayer"+layIDX].document.close (); } //Workout offsets if (document.body) if (document.body.clientWidth) sWidth = Number(eval("document.body.clientWidth")); if (window.innerWidth) sWidth = Number(eval("window.innerWidth")); if (sWidth < menuNavWidth) sWidth = menuNavWidth; iLayY = 111; pPath = parent+"."+child; zindex = 100; if (parent != "menu_RootObject") { cutidx = parent.indexOf (".", parent.indexOf (".")+1); pPath = parent.substring (0, cutidx); zindex = 50; } cutidx = pPath.indexOf ("."); rObj = eval (pPath.substring(0, cutidx)); rChild = eval (pPath); iLayX = (sWidth/2) - (menuNavWidth/2); for (x = 0; x < rObj.Children.length; x++) { if (rObj.Children[x] == rChild) break; iLayX += menuSpacers + rObj.Children[x].ImageWidth; } iLayX += menuSpacers; //Now that we've got the "root menu" position - work out offset for popups (if this is). if (parent != "menu_RootObject") { cutidx = parent.indexOf ("."); pcut = parent.indexOf (".", cutidx+1); while (parent.indexOf (".", cutidx+1) != -1) { iLayY += 13; //constant space from top of menu to first row cutidx = parent.indexOf (".", cutidx+1); //get "popupmenu....." window.status = parent+" "+pcut+" "+cutidx; if (pcut < cutidx) { tmpstr = parent.substring (pcut+1, cutidx); iChildNum = Number(tmpstr.substring (tmpstr.indexOf ("[")+1, tmpstr.indexOf ("]"))); iLayY += 18*iChildNum; //constant space from top of row to top of next row of text } if (parent.indexOf (".", cutidx+1) != -1) //check if there are any more { tmpstr = parent.substring (0, parent.indexOf (".", cutidx+1)); iLayX += GetMenuWidth (eval(tmpstr))-10; cutidx = parent.indexOf (".", cutidx+1); } pcut = cutidx; } tmpstr = child; iChildNum = Number(tmpstr.substring (tmpstr.indexOf ("[")+1, tmpstr.indexOf ("]"))); iLayY += 18*iChildNum; //constant space for row to row as above iLayX += GetMenuWidth (eval(parent))-10; } if (iLayX + GetMenuWidth (mObj) > sWidth) iLayX = sWidth - GetMenuWidth (mObj); //Set layer position and properties if (document.getElementById) { document.getElementById("menuLayer"+layIDX).style.top = iLayY+"px"; document.getElementById("menuLayer"+layIDX).style.left = iLayX+"px"; setZIndex(document.getElementById("menuLayer"+layIDX).style); document.getElementById("menuLayer"+layIDX).style.visibility = "visible"; tobj = document.getElementById("menuLayer"+layIDX); } else if (document.layers) { document.layers["menuLayer"+layIDX].pageX = iLayX; document.layers["menuLayer"+layIDX].pageY = iLayY; setZIndex(document.layers["menuLayer"+layIDX]); document.layers["menuLayer"+layIDX].visibility = 'visible'; tobj = document.layers["menuLayer"+layIDX]; } //set layer data tobj.menuTimerID = null; tobj.parentref = parent; tobj.childref = child; tobj.onmouseover = menuCloseCancel; tobj.onmouseout = menuCloseStart; } function menuCloseCancel () { var pPath, cutidx, pObj, lObj; clearTimeout (this.menuTimerID); this.menuTimerID = null; //Cancel all parent closings too pPath = this.parentref; if (pPath != "menu_RootObject") { cutidx = pPath.indexOf ("."); while (pPath.indexOf (".", cutidx+1) != -1) { cutidx = pPath.indexOf (".", cutidx+1); //get "popupmenu....." if (pPath.indexOf (".", cutidx+1) != -1) //check if there are any more { tmpstr = pPath.substring (0, pPath.indexOf (".", cutidx+1)); pObj = eval(tmpstr); if (document.getElementById) lObj = document.getElementById("menuLayer"+pObj.DisplayDiv); else if (document.layers) lObj = document.layers["menuLayer"+pObj.DisplayDiv]; clearTimeout (lObj.menuTimerID); lObj.menuTimerID = null; cutidx = pPath.indexOf (".", cutidx+1); } } pObj = eval(pPath); if (document.getElementById) lObj = document.getElementById("menuLayer"+pObj.DisplayDiv); else if (document.layers) lObj = document.layers["menuLayer"+pObj.DisplayDiv]; clearTimeout (lObj.menuTimerID); lObj.menuTimerID = null; } } function menuCloseStart () { var pPath, cutidx, pObj, lObj; menuClosePopup (this.parentref,this.childref); //Start all parent closings too pPath = this.parentref; if (pPath != "menu_RootObject") { cutidx = pPath.indexOf ("."); while (pPath.indexOf (".", cutidx+1) != -1) { cutidx = pPath.indexOf (".", cutidx+1); //get "popupmenu....." if (pPath.indexOf (".", cutidx+1) != -1) //check if there are any more { tmpstr = pPath.substring (0, pPath.indexOf (".", cutidx+1)); pObj = eval(tmpstr); if (document.getElementById) lObj = document.getElementById("menuLayer"+pObj.DisplayDiv); else if (document.layers) lObj = document.layers["menuLayer"+pObj.DisplayDiv]; menuClosePopup (lObj.parentref, lObj.childref); cutidx = pPath.indexOf (".", cutidx+1); } } pObj = eval(pPath); if (document.getElementById) lObj = document.getElementById("menuLayer"+pObj.DisplayDiv); else if (document.layers) lObj = document.layers["menuLayer"+pObj.DisplayDiv]; menuClosePopup (lObj.parentref, lObj.childref); } } function menuClosePopup (parent, child, flag, timeout) { var x, layIDX, pObj, cObj, mObj, sContent, sBackground; //Get objects mObj = eval(parent+"."+child+".PopupMenu"); layIDX = mObj.DisplayDiv; //If we're really shutting if (flag) { //Hide layer if (document.getElementById) { clearTimeout (document.getElementById("menuLayer"+layIDX).menuTimerID); document.getElementById("menuLayer"+layIDX).menuTimerID = null; document.getElementById("menuLayer"+layIDX).style.visibility = 'hidden'; } else if (document.layers) { clearTimeout (document.layers["menuLayer"+layIDX].menuTimerID); document.layers["menuLayer"+layIDX].menuTimerID = null; document.layers["menuLayer"+layIDX].visibility = 'hidden'; } //'Clean' layer mObj.DisplayDiv = null; menuDivsDirty[layIDX] = false; } //Start timer else { if (arguments.length < 4) timeout = 50; if (document.getElementById) { document.getElementById("menuLayer"+layIDX).menuTimerID = setTimeout ("menuClosePopup ('"+parent+"','"+child+"',true);", timeout); } else if (document.layers) { document.layers["menuLayer"+layIDX].menuTimerID = setTimeout ("menuClosePopup ('"+parent+"','"+child+"',true);", timeout); } } }