/* Template JavaScript functions for Duke University's OIT's Office of Web services (OWS) generated templates */

function pickRandom(range) {
	/* A random number/image generation function */
	if (Math.random) {
		return Math.round(Math.random() * (range-1));
	} else {
		var now = new Date();
		return (now.getTime() / 1000) % range;
	}
}

function randomImage(linkIndicator) {
	/* This function generates a random number from 1 to the number of images in the imageArray, and then displays that image on the page calling the function. If 'withLargerImageLink' is passed as the linkIndicator, then the random image will also have a hyperlink that generates a pop-up window with a larger (higher-res) version of the image. */
	// First generate the random mumber from the range of possible random images using the pickRandom() function
	var imageChoice = pickRandom(imageArray.length);
	var imageNameWithoutRandomString = imageArray[imageChoice]["src"].slice(0,imageArray[imageChoice]["src"].indexOf("random"));
	// Now check to see whether 'withLargerImageLink' was passed, and if so, then generate the added HTML code needed to make the imaged linked.
	if (linkIndicator == "withLargerImageLink") {
		var openingLinkTag = '<a href="javascript:popUpWindow(\'' + imageNameWithoutRandomString + 'big.jpg\',\'popUp\',\'' + imageArray[imageChoice]["altTag"] + '\',\'840\',\'600\');">';
		var closingLinkTag = '</a>';
	} else {
		var openingLinkTag = "";
		var closingLinkTag = "";
	}
	/* This function generates the HTML code to insert the random image on the page and provide a link to a larger version of the random image */
	document.writeln('<div class="rightfloat">' + openingLinkTag + '<img src="' + imageArray[imageChoice]["src"] + '" height="' + randomImageHeight + '" width="' + randomImageWidth + '" border="0" align="right" alt="' + imageArray[imageChoice]["altTag"] + '" />' + closingLinkTag + '</div>');
	/* The following line should be inserted in the HTML template after the <script> tag that calls randomImage():
	<noscript><div class="rightfloat"><img src="images/spacer.gif" height="1" width="1" border="0" class="rightfloat" alt="spacer image in place of random image" /></div></noscript> */
}

function findPage(pageIdentifier) {
	/* This function basically parses through the siteArray and finds the individual array member (or sub-member) that corresponds to the document's passed pageIdentifier. It then returns that array member back to whatever called the function.  If there is no match, then "false" is passed back (which won't match with anything)*/
	/* First check to see if the matching page is in the top level of the array (i.e. the pageIndentifier is not a nested subcategory). If not, then check to see if this particular menu has a subcategory, and if so, then check to see if any of the subcategory array members matches the unique_id, and if so, then return the parent array member (since we only need to display where the location is from the top-level menu, not on submenus).  There are at least two improvements that could be made: (1) make this a recursive function that could follow an indefinite number of submenu levels; and (2) have the function return context-based information for every level of the menu and submenus.  Not now, though! */
	var results = false;
	for (var arrayMember in siteArray) {
		if (siteArray[arrayMember]["unique_id"] == pageIdentifier) {
			results = siteArray[arrayMember];
			break;
		} else if (typeof(siteArray[arrayMember]['subcategories']) == "object") {
			for (var subcategory in siteArray[arrayMember]['subcategories']) {
				if (siteArray[arrayMember]['subcategories'][subcategory]["unique_id"] == pageIdentifier) {
					results = siteArray[arrayMember];
					break;
				}
			}
		}
	}
	return results;
}

function generateBreadcrumb(pageIdentifier,breadcrumbLocation) {
	/* This function does one of two diffferent things, depending on what's passed as breadcrumbLoaction.  For a "tabImage" passed value, it finds and writes in the appropriate tab image (containing high-level breadcrumb text) to the breadcrumbs_bar part of the template.  For a "breadCrumbs" passed value, it writes out text representations of the ful breadcrumbs path (menu and submenu listings).  It uses the document's unique pageIdentifier strings, and calls that against the siteArray[member]['unique_id'] array member, and when it matches, it pulls out the appropriate values from that array member, using the "tab_image" array members (filename, width, height, alt text, etc.) for "tabImage", and using the link_name values for the arrayMember and its possible subcategories for the "breadCrumbs" option. */
	// Find matching array member (if there is no match, then false is returned to this variable)
	var matchingArray = findPage(pageIdentifier);
	// And now use the matchingArray members to determine the correct navigation tab image or breadcrumb text (depending on breadcrumbLocation.  1/21/04: Note the use of typeof() to detect an array member's presence.  Netscape 4.x does not like the use of straight existence test (e.g. "if(matchingArray)" in the line below).  Stupid Netscape...)
	if (typeof(matchingArray) == "object") {
		// First figure out if we're dealing with "tabImage" or "breadCrumbs", and assign the appropriate HTML code for the respective breadcrumb element.  We'll start with tabImage, because it's more straightforward.
		if (breadcrumbLocation == "tabImage") {
			var breadcrumbsCode = '<p class="navigationtab"><img src="images/white.gif" border="0" alt="whitespace" height="19" width="10" /><img src="images/tab_corner_lower_left.gif" alt="bordered blue and white tab edge" border="0" width="9" height="19" /><img src="' + imagesDirectory + matchingArray["tab_image"] + '" alt="' + matchingArray["tab_alt"] + '" border="0" width="' + matchingArray["tab_image_width"] + '" height="' + matchingArray["tab_image_height"] + '" /></p>';
		} else {
			// For all other breadcrumbLocation values (presumably only "breadCrumbs"), check for possible subcategories, then generate the HTML code for a full breadcrumb.  If there are subcategories, loop through the subcategory values and try to match against the pageIdentifier to get a very specific breadcrumb.  Note that the resulting breadcrumb fragment will be text-based, so this is only applicable to the "breadCrumbs" version of breadcrumbLocation.
			var subcategoryCrumb = "";
			var menuLinkTag = "";
			var menuLinkEndTag = "";
			if ((typeof(matchingArray['subcategories']) == "object") && (breadcrumbLocation == "breadCrumbs")) {
				for (subcategories in matchingArray['subcategories']) {
					if (matchingArray['subcategories'][subcategories]["unique_id"] == pageIdentifier) {
						// For matching subcategory pages, generate the HTML code for displaying the link_name of the subcategory page, as well as the right code to provide links to the subcategory page's parent menu page
						subcategoryCrumb = '<span class="breadcrumbtext">&nbsp;&nbsp;&gt;&gt;&nbsp;' + matchingArray["subcategories"][subcategories]["link_name"] + '</span>';
						menuLinkTag = '<a href="' + rootRelativePath + matchingArray["link"] + '">';
						menuLinkEndTag = "</a>";
						break;
					}
				}
			}
			// Now generate the breadcrumbs HTML code for the page.  The breadcrumbs will always contain a linked listing for the home page, and will contain either a listing for the current menu option (if that's where we're at), or else a linked listing of the menu option, plus a listing of the subcategory where we're at.

			var breadcrumbsCode = '<p class="breadcrumbs"><a href="' + rootRelativePath + '">' + siteName + '</a> &gt;&gt; ' + menuLinkTag + matchingArray["link_alt"] + menuLinkEndTag + subcategoryCrumb + '</p>';
		}
	} else {
	// If there is no matchingArray, then figure out whether we're dealing with a tabImage r a breadCrumbs parameter.  For the former, just write in a blank space where the navigation tab should be.  For the latter, just provide a link to the Home page.
		if (breadcrumbLocation == "tabImage") {
			var breadcrumbsCode = '<img src="images/spacer.gif" alt="___" border="0" width="1" height="19" />';
		} else {
			var breadcrumbsCode = '<p class="breadcrumbs"><a href="' + rootRelativePath + '">' + siteName + '</a></p>';
		}
	}
	document.writeln(breadcrumbsCode);
}

function generateLeftMenu(pageIdentifier) {
	/* This function writes out the left-side navigation menu using the MenuMaker functions defined below.  It uses the passed-in pageIdentifier to figure out which main category is the owner (or parent) of the particular page calling this function, and makes sure that that menu item is highlighted as "selected".  It uses each of the siteArray array members to determine the text/image names (and sizes) for the "on", "off", and "selected" states, as well as any possible subcategories. It tests for the */
	// First write out out the main left-side nav page link (that contains the name of the site).  Test to see if text links are being used (leftsideHomeLinkText has a non-empty strign value) or if graphic links are being used for the top link (leftsideHomeLinkImageName has a non-empty string value).
	if (leftsideHomeLinkImageName.length > 0) {
		var leftSideNavFirstLine = '<a href="index.php"><img src="' + imagesDirectory + leftsideHomeLinkImageName + '" height="' + leftsideHomeLinkImageHeight + '" width="' + leftsideHomeLinkImageWidth + '" border="0"alt="' + siteName + '" /></a>';
	} else if (leftsideHomeLinkText.length > 0) {
		var leftSideNavFirstLine = '<a href="' + rootRelativePath + '">' + leftsideHomeLinkText + '</a>';
	} else {
		var leftSideNavFirstLine = ''; // Just in case the site owner forgot to set up anything for the top leftnav link, a blank string will be used (this could be used to customize the left-nav look to remove the top listing...).
	}
	document.writeln(leftSideNavFirstLine);
	// Now match up the pageIdentifier to its appropriate siteArray member.  (If there is no match, then matchingArray is false)
	var matchingArray = findPage(pageIdentifier);
	// Now sort and then iterate through the siteArray, writing out a line for each of the main-level array members.  The matchingArray member must have the "selected" image passed in to the MenuMaker--all others just have the "off" value passed in.  The submenuInvoker is the MM function call to show submenus for leftside nav menus that have subcategories.  Right now we're just going to use a simple sort() method, not using the "order" sub-key member. 11/24/2003 NOTE: Apparently Netscape 7.0 (Mozilla 1.0.1) doesn't support the sort() method and silently ignores the array, so for now we won't even implement siteArray.sort() . Netscape 7.1 does support sort(), so if you don't care about Mozilla bugs (bug #157652 in this case), then implement the sort() method.  For now this is acceptable, because the site array was defined in order.

	var lastItemIndicator = ""; // This is a dummy variable to hold the last id of the siteArray that has submenus (since Javascript's a bit kludgy when it comes to associative arrays, and you can't just use length() to find out how long the associative array is (and besides, not all arrays elements may have subcategories)
	for (var arrayMember in siteArray) {
		// The first test is to see if the current arrayMember is the current page (or parent page)
		if ((siteArray[arrayMember] == matchingArray) && matchingArray) {
			var offOrSelected = "_selected.";
		} else {
			var offOrSelected = "_off.";
		}
		// The next test is to see if the arrayMember has subcategories (submenus), and if so, then to invoke the mmLoadMenus function for each subcategory, and then to code in the necessary code for calling submenus on the page.  If there are no subcategories, then submenuInvoker is an empty string.
		if ((typeof(siteArray[arrayMember]['submenuName']) == "string") && (typeof(siteArray[arrayMember]['subcategories']) == "object")) {
			// First invoke the submenu generator
			mmLoadMenus(siteArray[arrayMember]);
			// Then write out the code for that submenu
			submenuInvoker = "MM_showMenu(window." + siteArray[arrayMember]['submenuName'] + "," + (siteArray[arrayMember]['link_image_width'] || leftsideMenuWidth) + ",0,null,'" + siteArray[arrayMember]['unique_id'] + "');";
			// While we're at it, place the current array member's key (arrayMember) into the lastItemIndicator, so that we can invoke the submenus at the end of this function
			lastItemIndicator = arrayMember;
		} else {
			submenuInvoker = "";
		}
		// the last step of the for loop is to actually write out the necessary HTML that codes in the menus and submenus for that particular arrayMember (the syntax for the MM functions is from Macromedia).  Make sure to write the correct code based on whether the link is an image or text, though... (1/23/04 NOTE: Currently the implementation of text submenus is not functional...)
		// Let's first define default empty values for non-links
		var mouseoverCommands = "";
		var linkAnchorCodeStart = "";
		var linkAnchorCodeEnd = "";
		if (typeof(siteArray[arrayMember]['link_text']) == "string") {
			// Check to see if a link is provided in this arrayMember (if not, then it's probably a spacer, and no <a> element is needed either)
			if (siteArray[arrayMember]['link'] != '') {
				mouseoverCommands = "MM_swapImage('" + siteArray[arrayMember]["unique_id"] + "','','" + "something" + "',1);";
				linkAnchorCodeStart = '<a href="' + siteArray[arrayMember]["link"] + '" onmouseover="' + mouseoverCommands + submenuInvoker + '" onmouseout="MM_swapImgRestore();MM_startTimeout()">';
				linkAnchorCodeEnd = "</a>";
			}
			var linkTextOrImage = siteArray[arrayMember]["link_text"];
		} else if (typeof(siteArray[arrayMember]['link_image_name']) == "string") {
			// Check to see if a link is provided in this arrayMember (if not, then it's probably a spacer, and no <a> element is needed either)
			if (siteArray[arrayMember]['link'] != '') {
				mouseoverCommands = "MM_swapImage('" + siteArray[arrayMember]["unique_id"] + "','','" + imagesDirectory + siteArray[arrayMember]["link_image_name"] + "_on." + siteArray[arrayMember]["link_image_extension"] + "',1);";
				linkAnchorCodeStart = '<a href="' + siteArray[arrayMember]["link"] + '" onmouseover="' + mouseoverCommands + submenuInvoker + '" onmouseout="MM_swapImgRestore();MM_startTimeout()">';
				linkAnchorCodeEnd = "</a>";
			}
			var linkTextOrImage = '<img src="' + imagesDirectory + siteArray[arrayMember]["link_image_name"] + offOrSelected + siteArray[arrayMember]["link_image_extension"] +'" name="' + siteArray[arrayMember]["unique_id"] + '" width="' + siteArray[arrayMember]["link_image_width"] + '" height="' + siteArray[arrayMember]["link_image_height"] + '" border="0" id="' + siteArray[arrayMember]["unique_id"] + '" alt="' + siteArray[arrayMember]["link_alt"] + '" />';
		}
		document.writeln(linkAnchorCodeStart + linkTextOrImage + linkAnchorCodeEnd + '<br />');
	}
	// As the final step, we need to write out the submenus (if the array has any subcategories defined.  MM Menu appears to need us to do this just once, and do it from the last submenu id given. (I imagine it could be any submenu entry, but this seemed the safest way to do it/)
	if (lastItemIndicator.length > 0) {
		self[siteArray[lastItemIndicator]['submenuName']].writeMenus();
	}
}

function popUpWindow(linkURL, windowName, windowTitle, imageWidth, imageHeight) {
	// The following code snippet provides the pop-up window functionality for external links.  The basic idea is that the function opens a smaller window (without address bar) and then turns the focus onto it.
	var popUpWin = window.open('', windowName, "menubar,resizable,noscrollbars,width=" + imageWidth + ",height=" + imageHeight);
	var popUpDoc = popUpWin.document;
	popUpDoc.write('<html><head><title>' + windowTitle + '</title></head><body><p><img src="' + linkURL + '" border="0" alt="' + windowTitle + '" /></p></body></html>');
	popUpDoc.close();
	// var popUpWin = window.open(unescape(linkURL), windowName, "menubar,resizable,scrollbars,width=" + width + ",height=" + height);
	popUpWin.focus();
}

function imageLoader(imageURL, windowName, windowTitle) {
	// 12-1-03 NOTE: This function is not used, because of incompatibilities with Safari and IE on Macs (the former doesn't accept onload events, the latter doesn't seem to implement it properly, and Safari and Opera users will still be blocked with their default settings).
	// This is a very small function that simply (pre)loads up an image and then calls the following function, popUpImageWindow, after the image is loaded.  It's very useful for the following function (popUpImageWindow) because having this function's statements run separately from the main popUpImageWindow() function forces the script and browser to _wait_ until the image is loaded, and thus avoids timing issues in which the function proceeds before actually loading the image and retrieving the dimensions of the image.  It's basically a preload function.  Note that you need to create new methods/attributes for the imageObject image, so that all the necessary attributes are passed through via the "onload" event handler (you can't pass stuff like "windowName" and "windowTitle" to popUpImageWindow through normal function arguments (e.g. calling "popUpImageWindow(image,windowName,windowTitle)"), because the onload event handler requires a special evt call of a function.
	// PLEASE NOTE: Because this function uses the "onload" event handler, some programs may perceive this pop-up call as a prohibited action (too similar to ad pop-ups), so sometimes users will not be able to see the pop-up window at all because it's been suppressed by the browser or an add-in program.  For OWS testing purposes, the only browser that exhibits this behavior is Opera 7, when "refuse pop-up windows" or "allow requested pop-up windows only" is selected.  For this reason, this function will tell Opera users about this behavior (assuming that the users have set their Opera browsers to report themselves as Opera browsers, not as some other form).
	//alert("ImageLoader intiated");
	imageObject = new Image();
	imageObject.src = imageURL;
	imageObject.windowName = windowName;
	imageObject.windowTitle = windowTitle;
	imageObject.onload = popUpImageWindow;
	//alert("you've made it past the hard stuff--onload, src("+imageObject.src+"), windowName("+imageObject.windowName+"), windowTitle("+imageObject.windowTitle+")");
	// Lastly, check to see if the browser is reporting that it's an Opera browser.  If it is, then tell the user that they may not be able to see the pop-up if they have restricted pop-ups in their browser.
	//if(navigator.appName.indexOf("Opera") >= 0) {
	//	alert("Attention Opera User:\n\nYou may not be able to see the pop-up window you have just selected, depending on your browser settings.  If you have chosen \"Refuse pop-up windows\" or \"Open requested pop-up windows only\" in your preferences settings, then the image you just clicked on will probably not display in a separate window.\n\nTo see the pop-up image, you will want to change your preferences to allow pop-up windows (in Opera 7, you can control this using the F12 key).\n\nWe apologize for any inconvenience.");
	//}
}

function popUpImageWindow(evt) {
	// The following code snippet provides a pop-up window functionality for images (jpegs, gifs).  The basic idea is that the function opens a window slightly larger than the image (without address bar) and then turns the focus onto it.
	// First get the image and get its attributes, calling the preloader imageLoader() function
	var popUpImageWidth = this.width + 50; // provide a slight cushion left and right to account for scroll and window bars
	var popUpImageHeight = this.height + 40; // provide a slight cushion top and bottom to account for status and file menu bars
	//alert("popUpImage attributes:\n\nwidth: " + this.width + "\n(popUpImageWidth: " + popUpImageWidth + ")\n\nheight: " + this.height + "\n(popUpImageHeight: " + popUpImageHeight + ")\n\n(Got zeros?  Don't understand...)");
	// Now open up a new window and write in the code that will show the image and provide the windowTitle as the title of the window
	var popUpWin = window.open('', this.windowName, "menubar,resizable,noscrollbars,width=" + popUpImageWidth + ",height=" + popUpImageHeight);
	// Now write out the document source code (we need to do this so that we can manually set the Title of the window (if we used the popUpWindow function, then the image filename would be the window's title)
	var popUpDoc = popUpWin.document;
	popUpDoc.write('<html><head><title>' + this.windowTitle + '</title></head><body><p><img src="' + this.src + '" border="0" width="' + this.width + '" height="' + this.height + '" alt="' + this.windowTitle + '" /></p></body></html>');
	popUpDoc.close();
	popUpWin.focus();
}

/* Now the fun part, defining the submenus using the siteArray values !!! */
function mmLoadMenus(siteArrayMember) {
	// This is a modified macromedia function that defines all the possible menus on a page.  It appears to simply create floating variables on the window, using text and link strings passed to it.  This has been modified for the Duke templated sites by having individual siteArray members passed to it, and then iterating across the subcategory array members for the siteArray member.  All the submenu aesthetic definitions are done in the "static definitions" section of the javascript.
	// Define the submenuname
	var submenuName = siteArrayMember['submenuName']
	// First step, check to see if the menu already exists (if it's been defined).  Assuming it doesn't already exist, figure out the maximum length of the subcategory link_names (so you can figure out how wide the submenu needs to be), and then define the new floating variable, using the siteArray's submenuName.  Most of these values are just default MM Menu values, but can be modified in the "static definitions" portion of the javascript.
	if (!self[submenuName]) {
		// To figure out the maximum length of the subcategory entries, do a quick loop through the subcategories array and bubble-sort out the longest entry.  Then do a quick math formula to determine the right width (based on the assumption that the menu width will be defined in pixels--if we want to use ems (which is really better), then a lot more logic needs to be written in to the whole routine, since the MM maker routines are hard coded to deal with pixels).
		maximumSubcategoryWidth = 0;
		for (subcategories in siteArrayMember['subcategories']) {
			if (siteArrayMember['subcategories'][subcategories]["link_name"].length > maximumSubcategoryWidth) {
				maximumSubcategoryWidth = siteArrayMember['subcategories'][subcategories]["link_name"].length;
			}
		}
		// Now that we have the character length of the longest subcategory, we must calculate the appropriate width that the submenu box should be.
		submenuWidth = Math.ceil((maximumSubcategoryWidth * (submenusFontSize * (2 / 3)) + (submenusPadding * 2)));
		self[submenuName] = new Menu("root",submenuWidth,submenuPixelHeight,submenusFontFamily,submenusFontSize,submenusLinkFontColor,submenusHoverLinkFontColor,submenusIndividualMenuAreaBackgroundColor,submenusHoverBackgroundColor,submenusHorizontalAlignment,submenusVerticalAlignment,submenusPadding,submenusSpacing,submenusHidingTimeOut,submenusXaxisOffset,submenusYaxisOffset,submenusRelativeToItem,submenusOpaque,submenusVerticalIndicator,submenusItemIndent,true,true);
		for (subcategories in siteArrayMember['subcategories']) {
			self[submenuName].addMenuItem(siteArrayMember['subcategories'][subcategories]['link_name'],"location='" + siteArrayMember['subcategories'][subcategories]['link'] + "'");
		}
		// Now do the rest of the customization (used from the default MM Menu values)
		self[submenuName].hideOnMouseOut = true;
		self[submenuName].bgColor = submenusInteriorAndRightandBottomBorderColors;
		self[submenuName].menuBorder = 1;
		self[submenuName].menuLiteBgColor = submenusLeftAndTopBorderColors;
		self[submenuName].menuBorderBgColor = submenusBaseLayerBackgroundColor;
		// self[submenuName].writeMenus();
	}
}

function getCurrentYear() {
	// This is a small function that returns the current year, based on the time provided by the current browser's machine.
	document.writeln((new Date()).getFullYear());
}

function submenuIterator() {
	// This is just a small iterating function that gives all the non-function attributes of the submenus defined by mmLoadMenus (above).  It's used purely for diagnostic purposes, and the function call must be hand-inserted into a page to show up (using a document.writeln(submenuIterator()); script call).  It shows quite a bit of useful information about the submenus' attributes.
	results = "";
	for (arrayMember in siteArray) {
		if (siteArray[arrayMember]["subcategories"]) {
			results += '<div style="border: 1px thin solid;"><b>window.' + siteArray[arrayMember]["submenuName"] + '</b>\n<ul>\n';
			for (attribute in self[siteArray[arrayMember]["submenuName"]]) {
				if ((attribute != "addMenuItem") && (attribute != "writeMenus") && (attribute != "MM_showMenu") && (attribute != "onMenuItemOver") && (attribute != "onMenuItemAction") && (attribute != "hideMenu") && (attribute != "hideChildMenu") && (attribute != "hideMenu") && (attribute != "actions")) {
					results += '<li>' + attribute + ': ' + self[siteArray[arrayMember]["submenuName"]][attribute] + '</li>\n';
				}
			}
			results += '</ul>\n</div>\n';
		}
	}
	return results;
}

/**
 * mm_menu 20MAR2002 Version 6.0
 * Andy Finnell, March 2002
 * Copyright (c) 2000-2002 Macromedia, Inc.
 *
 * based on menu.js
 * by gary smith, July 1997
 * Copyright (c) 1997-1999 Netscape Communications Corp.
 *
 * Netscape grants you a royalty free license to use or modify this
 * software provided that this copyright notice appears on all copies.
 * This software is provided "AS IS," without a warranty of any kind.
 */

function Menu(label, mw, mh, fnt, fs, fclr, fhclr, bg, bgh, halgn, valgn, pad, space, to, sx, sy, srel, opq, vert, idt, aw, ah) 
{
	this.version = "020320 [Menu; mm_menu.js]";
	this.type = "Menu";
	this.menuWidth = mw;
	this.menuItemHeight = mh;
	this.fontSize = fs;
	this.fontWeight = "plain";
	this.fontFamily = fnt;
	this.fontColor = fclr;
	this.fontColorHilite = fhclr;
	this.menuBorder = 1;
	this.menuBgOpaque=opq;
	this.menuItemBorder = 1;
	this.menuItemIndent = idt;
	// this.bgColor = "#555555"; (Ignored)
	this.menuItemBgColor = bg;
	this.menuItemVAlign = valgn;
	this.menuItemHAlign = halgn;
	this.menuItemPadding = pad;
	this.menuItemSpacing = space;
	// this.menuLiteBgColor = "#ffffff"; (Ignored)
	// this.menuBorderBgColor = "#777777"; (Ignored)
	this.menuHiliteBgColor = bgh;
	// this.menuContainerBgColor = "#cccccc"; (Ignored)
	this.childMenuIcon = "arrows.gif";
	this.submenuXOffset = sx;
	this.submenuYOffset = sy;
	this.submenuRelativeToItem = srel;
	this.vertical = vert;
	this.items = new Array();
	this.actions = new Array();
	this.childMenus = new Array();
	this.hideOnMouseOut = true;
	this.hideTimeout = to;
	this.addMenuItem = addMenuItem;
	this.writeMenus = writeMenus;
	this.MM_showMenu = MM_showMenu;
	this.onMenuItemOver = onMenuItemOver;
	this.onMenuItemAction = onMenuItemAction;
	this.hideMenu = hideMenu;
	this.hideChildMenu = hideChildMenu;
	if (!window.menus) window.menus = new Array();
	this.label = " " + label;
	window.menus[this.label] = this;
	window.menus[window.menus.length] = this;
	if (!window.activeMenus) window.activeMenus = new Array();
}

function addMenuItem(label, action) {
	this.items[this.items.length] = label;
	this.actions[this.actions.length] = action;
}

function FIND(item) {
	if( window.mmIsOpera ) return(document.getElementById(item));
	if (document.all) return(document.all[item]);
	if (document.getElementById) return(document.getElementById(item));
	return(false);
}

function writeMenus(container) {
	if (window.triedToWriteMenus) return;
	var agt = navigator.userAgent.toLowerCase();
	window.mmIsOpera = agt.indexOf("opera") != -1;
	if (!container && document.layers) {
		window.delayWriteMenus = this.writeMenus;
		var timer = setTimeout('delayWriteMenus()', 500);
		container = new Layer(100);
		clearTimeout(timer);
	} else if (document.all || document.hasChildNodes || window.mmIsOpera) {
		document.writeln('<span id="menuContainer"></span>');
		container = FIND("menuContainer");
	}

	window.mmHideMenuTimer = null;
	if (!container) return;	
	window.triedToWriteMenus = true; 
	container.isContainer = true;
	container.menus = new Array();
	for (var i=0; i<window.menus.length; i++) 
		container.menus[i] = window.menus[i];
	window.menus.length = 0;
	var countMenus = 0;
	var countItems = 0;
	var top = 0;
	var content = '';
	var lrs = false;
	var theStat = "";
	var tsc = 0;
	if (document.layers) lrs = true;
	for (var i=0; i<container.menus.length; i++, countMenus++) {
		var menu = container.menus[i];
		if (menu.bgImageUp || !menu.menuBgOpaque) {
			menu.menuBorder = 0;
			menu.menuItemBorder = 0;
		}
		if (lrs) {
			var menuLayer = new Layer(100, container);
			var lite = new Layer(100, menuLayer);
			lite.top = menu.menuBorder;
			lite.left = menu.menuBorder;
			var body = new Layer(100, lite);
			body.top = menu.menuBorder;
			body.left = menu.menuBorder;
		} else {
			content += ''+
			'<div id="menuLayer'+ countMenus +'" style="position:absolute;z-index:1;left:10px;top:'+ (i * 100) +'px;visibility:hidden;color:' +  menu.menuBorderBgColor + ';">\n'+
			'  <div id="menuLite'+ countMenus +'" style="position:absolute;z-index:1;left:'+ menu.menuBorder +'px;top:'+ menu.menuBorder +'px;visibility:hide;" onmouseout="mouseoutMenu();">\n'+
			'  <div id="menuFg'+ countMenus +'" style="position:absolute;left:'+ menu.menuBorder +'px;top:'+ menu.menuBorder +'px;visibility:hide;">\n'+
			'';
		}
		var x=i;
		for (var i=0; i<menu.items.length; i++) {
			var item = menu.items[i];
			var childMenu = false;
			var defaultHeight = menu.fontSize + (2 * menu.menuItemPadding) + 10;
			if (item.label) {
				item = item.label;
				childMenu = true;
			}
			menu.menuItemHeight = menu.menuItemHeight || defaultHeight;
			var itemProps = '';
			if( menu.fontFamily != '' ) itemProps += 'font-family:' + menu.fontFamily +';';
			itemProps += 'font-weight:' + menu.fontWeight + ';fontSize:' + menu.fontSize + 'px;';
			if (menu.fontStyle) itemProps += 'font-style:' + menu.fontStyle + ';';
			if (document.all || window.mmIsOpera) 
				itemProps += 'font-size:' + menu.fontSize + 'px;" onmouseover="onMenuItemOver(null,this);" onclick="onMenuItemAction(null,this);';
			else if (!document.layers) {
				itemProps += 'font-size:' + menu.fontSize + 'px;';
			}
			var l;
			if (lrs) {
				var lw = menu.menuWidth;
				if( menu.menuItemHAlign == 'right' ) lw -= menu.menuItemPadding;
				l = new Layer(lw,body);
			}
			var itemLeft = 0;
			var itemTop = i * menu.menuItemHeight;
			if( !menu.vertical ) {
				itemLeft = i*menu.menuWidth;
				itemTop = 0;
			}
			var dTag = '<div id="menuItem'+ countItems +'" style="position:absolute;left:' + itemLeft + 'px;top:'+ itemTop +'px;'+ itemProps +'">';
			var dClose = '</div>'
			if (menu.bgImageUp) dTag = '<div id="menuItem'+ countItems +'" style="background:url('+menu.bgImageUp+');position:absolute;left:' + itemLeft + 'px;top:'+ itemTop +'px;'+ itemProps +'">';

			var left = 0, top = 0, right = 0, bottom = 0;
			left = 1 + menu.menuItemPadding + menu.menuItemIndent;
			right = left + menu.menuWidth - 2*menu.menuItemPadding - menu.menuItemIndent;
			if( menu.menuItemVAlign == 'top' ) top = menu.menuItemPadding;
			if( menu.menuItemVAlign == 'bottom' ) top = menu.menuItemHeight-menu.fontSize-1-menu.menuItemPadding;
			if( menu.menuItemVAlign == 'middle' ) top = ((menu.menuItemHeight/2)-(menu.fontSize/2)-1);
			bottom = menu.menuItemHeight - 2*menu.menuItemPadding;
			var textProps = 'position:absolute;left:' + left + 'px;top:' + top + 'px;';
			if (lrs) {
				textProps +=itemProps + 'right:' + right + ';bottom:' + bottom + ';';
				dTag = "";
				dClose = "";
			}
			
			if(document.all && !window.mmIsOpera) {
				item = '<div align="' + menu.menuItemHAlign + '">' + item + '</div>';
			} else if (lrs) {
				item = '<div style="text-align:' + menu.menuItemHAlign + ';">' + item + '</div>';
			} else {
				var hitem = null;
				if( menu.menuItemHAlign != 'left' ) {
					if(window.mmIsOpera) {
						var operaWidth = menu.menuItemHAlign == 'center' ? -(menu.menuWidth-2*menu.menuItemPadding) : (menu.menuWidth-6*menu.menuItemPadding);
						hitem = '<div id="menuItemHilite' + countItems + 'Shim" style="position:absolute;top:1px;left:' + menu.menuItemPadding + 'px;width:' + operaWidth + 'px;text-align:' 
							+ menu.menuItemHAlign + ';visibility:visible;">' + item + '</div>';
						item = '<div id="menuItemText' + countItems + 'Shim" style="position:absolute;top:1px;left:' + menu.menuItemPadding + 'px;width:' + operaWidth + 'px;text-align:' 
							+ menu.menuItemHAlign + ';visibility:visible;">' + item + '</div>';
					} else {
						hitem = '<div id="menuItemHilite' + countItems + 'Shim" style="position:absolute;top:1px;left:1px;right:-' + (left+menu.menuWidth-3*menu.menuItemPadding) + 'px;text-align:' 
							+ menu.menuItemHAlign + ';visibility:visible;">' + item + '</div>';
						item = '<div id="menuItemText' + countItems + 'Shim" style="position:absolute;top:1px;left:1px;right:-' + (left+menu.menuWidth-3*menu.menuItemPadding) + 'px;text-align:' 
							+ menu.menuItemHAlign + ';visibility:visible;">' + item + '</div>';
					}
				} else hitem = null;
			}
			if(document.all && !window.mmIsOpera) item = '<div id="menuItemShim' + countItems + '" style="position:absolute;left:0px;top:0px;">' + item + '</div>';
			var dText	= '<div id="menuItemText'+ countItems +'" style="' + textProps + 'color:'+ menu.fontColor +';">'+ item +'&nbsp</div>\n'
						+ '<div id="menuItemHilite'+ countItems +'" style="' + textProps + 'color:'+ menu.fontColorHilite +';visibility:hidden;">' 
						+ (hitem||item) +'&nbsp</div>';
			if (childMenu) content += ( dTag + dText + '<div id="childMenu'+ countItems +'" style="position:absolute;left:0px;top:3px;"><img src="'+ menu.childMenuIcon +'"></div>\n' + dClose);
			else content += ( dTag + dText + dClose);
			if (lrs) {
				l.document.open("text/html");
				l.document.writeln(content);
				l.document.close();	
				content = '';
				theStat += "-";
				tsc++;
				if (tsc > 50) {
					tsc = 0;
					theStat = "";
				}
				status = theStat;
			}
			countItems++;  
		}
		if (lrs) {
			var focusItem = new Layer(100, body);
			focusItem.visiblity="hidden";
			focusItem.document.open("text/html");
			focusItem.document.writeln("&nbsp;");
			focusItem.document.close();	
		} else {
		  content += '  <div id="focusItem'+ countMenus +'" style="position:absolute;left:0px;top:0px;visibility:hide;font-size:1px;" onclick="onMenuItemAction(null,this);">&nbsp;</div>\n';
		  content += '   </div>\n  </div>\n</div>\n';
		}
		i=x;
	}
	if (document.layers) {		
		container.clip.width = window.innerWidth;
		container.clip.height = window.innerHeight;
		container.onmouseout = mouseoutMenu;
		container.menuContainerBgColor = this.menuContainerBgColor;
		for (var i=0; i<container.document.layers.length; i++) {
			proto = container.menus[i];
			var menu = container.document.layers[i];
			container.menus[i].menuLayer = menu;
			container.menus[i].menuLayer.Menu = container.menus[i];
			container.menus[i].menuLayer.Menu.container = container;
			var body = menu.document.layers[0].document.layers[0];
			body.clip.width = proto.menuWidth || body.clip.width;
			body.clip.height = proto.menuHeight || body.clip.height;
			for (var n=0; n<body.document.layers.length-1; n++) {
				var l = body.document.layers[n];
				l.Menu = container.menus[i];
				l.menuHiliteBgColor = proto.menuHiliteBgColor;
				l.document.bgColor = proto.menuItemBgColor;
				l.saveColor = proto.menuItemBgColor;
				l.onmouseover = proto.onMenuItemOver;
				l.onclick = proto.onMenuItemAction;
				l.mmaction = container.menus[i].actions[n];
				l.focusItem = body.document.layers[body.document.layers.length-1];
				l.clip.width = proto.menuWidth || body.clip.width;
				l.clip.height = proto.menuItemHeight || l.clip.height;
				if (n>0) {
					if( l.Menu.vertical ) l.top = body.document.layers[n-1].top + body.document.layers[n-1].clip.height + proto.menuItemBorder + proto.menuItemSpacing;
					else l.left = body.document.layers[n-1].left + body.document.layers[n-1].clip.width + proto.menuItemBorder + proto.menuItemSpacing;
				}
				l.hilite = l.document.layers[1];
				if (proto.bgImageUp) l.background.src = proto.bgImageUp;
				l.document.layers[1].isHilite = true;
				if (l.document.layers.length > 2) {
					l.childMenu = container.menus[i].items[n].menuLayer;
					l.document.layers[2].left = l.clip.width -13;
					l.document.layers[2].top = (l.clip.height / 2) -4;
					l.document.layers[2].clip.left += 3;
					l.Menu.childMenus[l.Menu.childMenus.length] = l.childMenu;
				}
			}
			if( proto.menuBgOpaque ) body.document.bgColor = proto.bgColor;
			if( proto.vertical ) {
				body.clip.width  = l.clip.width +proto.menuBorder;
				body.clip.height = l.top + l.clip.height +proto.menuBorder;
			} else {
				body.clip.height  = l.clip.height +proto.menuBorder;
				body.clip.width = l.left + l.clip.width  +proto.menuBorder;
				if( body.clip.width > window.innerWidth ) body.clip.width = window.innerWidth;
			}
			var focusItem = body.document.layers[n];
			focusItem.clip.width = body.clip.width;
			focusItem.Menu = l.Menu;
			focusItem.top = -30;
            focusItem.captureEvents(Event.MOUSEDOWN);
            focusItem.onmousedown = onMenuItemDown;
			if( proto.menuBgOpaque ) menu.document.bgColor = proto.menuBorderBgColor;
			var lite = menu.document.layers[0];
			if( proto.menuBgOpaque ) lite.document.bgColor = proto.menuLiteBgColor;
			lite.clip.width = body.clip.width +1;
			lite.clip.height = body.clip.height +1;
			menu.clip.width = body.clip.width + (proto.menuBorder * 3) ;
			menu.clip.height = body.clip.height + (proto.menuBorder * 3);
		}
	} else {
		if ((!document.all) && (container.hasChildNodes) && !window.mmIsOpera) {
			container.innerHTML=content;
		} else {
			container.document.open("text/html");
			container.document.writeln(content);
			container.document.close();	
		}
		if (!FIND("menuLayer0")) return;
		var menuCount = 0;
		for (var x=0; x<container.menus.length; x++) {
			var menuLayer = FIND("menuLayer" + x);
			container.menus[x].menuLayer = "menuLayer" + x;
			menuLayer.Menu = container.menus[x];
			menuLayer.Menu.container = "menuLayer" + x;
			menuLayer.style.zindex = 1;
		    var s = menuLayer.style;
			s.pixeltop = -300;
			s.pixelleft = -300;
			s.top = '-300px';
			s.left = '-300px';

			var menu = container.menus[x];
			menu.menuItemWidth = menu.menuWidth || menu.menuIEWidth || 140;
			if( menu.menuBgOpaque ) menuLayer.style.backgroundColor = menu.menuBorderBgColor;
			var top = 0;
			var left = 0;
			menu.menuItemLayers = new Array();
			for (var i=0; i<container.menus[x].items.length; i++) {
				var l = FIND("menuItem" + menuCount);
				l.Menu = container.menus[x];
				l.Menu.menuItemLayers[l.Menu.menuItemLayers.length] = l;
				if (l.addEventListener || window.mmIsOpera) {
					l.style.width = menu.menuItemWidth + 'px';
					l.style.height = menu.menuItemHeight + 'px';
					l.style.pixelWidth = menu.menuItemWidth;
					l.style.pixelHeight = menu.menuItemHeight;
					l.style.top = top + 'px';
					l.style.left = left + 'px';
					if(l.addEventListener) {
						l.addEventListener("mouseover", onMenuItemOver, false);
						l.addEventListener("click", onMenuItemAction, false);
						l.addEventListener("mouseout", mouseoutMenu, false);
					}
					if( menu.menuItemHAlign != 'left' ) {
						l.hiliteShim = FIND("menuItemHilite" + menuCount + "Shim");
						l.hiliteShim.style.visibility = "inherit";
						l.textShim = FIND("menuItemText" + menuCount + "Shim");
						l.hiliteShim.style.pixelWidth = menu.menuItemWidth - 2*menu.menuItemPadding - menu.menuItemIndent;
						l.hiliteShim.style.width = l.hiliteShim.style.pixelWidth;
						l.textShim.style.pixelWidth = menu.menuItemWidth - 2*menu.menuItemPadding - menu.menuItemIndent;
						l.textShim.style.width = l.textShim.style.pixelWidth;	
					}
				} else {
					l.style.pixelWidth = menu.menuItemWidth;
					l.style.pixelHeight = menu.menuItemHeight;
					l.style.pixelTop = top;
					l.style.pixelLeft = left;
					if( menu.menuItemHAlign != 'left' ) {
						var shim = FIND("menuItemShim" + menuCount);
						shim[0].style.pixelWidth = menu.menuItemWidth - 2*menu.menuItemPadding - menu.menuItemIndent;
						shim[1].style.pixelWidth = menu.menuItemWidth - 2*menu.menuItemPadding - menu.menuItemIndent;
						shim[0].style.width = shim[0].style.pixelWidth + 'px';
						shim[1].style.width = shim[1].style.pixelWidth + 'px';
					}
				}
				if( menu.vertical ) top = top + menu.menuItemHeight+menu.menuItemBorder+menu.menuItemSpacing;
				else left = left + menu.menuItemWidth+menu.menuItemBorder+menu.menuItemSpacing;
				l.style.fontSize = menu.fontSize + 'px';
				l.style.backgroundColor = menu.menuItemBgColor;
				l.style.visibility = "inherit";
				l.saveColor = menu.menuItemBgColor;
				l.menuHiliteBgColor = menu.menuHiliteBgColor;
				l.mmaction = container.menus[x].actions[i];
				l.hilite = FIND("menuItemHilite" + menuCount);
				l.focusItem = FIND("focusItem" + x);
				l.focusItem.style.pixelTop = -30;
				l.focusItem.style.top = '-30px';
				var childItem = FIND("childMenu" + menuCount);
				if (childItem) {
					l.childMenu = container.menus[x].items[i].menuLayer;
					childItem.style.pixelLeft = menu.menuItemWidth -11;
					childItem.style.left = childItem.style.pixelLeft + 'px';
					childItem.style.pixelTop = (menu.menuItemHeight /2) -4;
					childItem.style.top = childItem.style.pixelTop + 'px';
					l.Menu.childMenus[l.Menu.childMenus.length] = l.childMenu;
				}
				l.style.cursor = "hand";
				menuCount++;
			}
			if( menu.vertical ) {
				menu.menuHeight = top-1-menu.menuItemSpacing;
				menu.menuWidth = menu.menuItemWidth;
			} else {
				menu.menuHeight = menu.menuItemHeight;
				menu.menuWidth = left-1-menu.menuItemSpacing;
			}

			var lite = FIND("menuLite" + x);
			var s = lite.style;
			s.pixelHeight = menu.menuHeight +(menu.menuBorder * 2);
			s.height = s.pixelHeight + 'px';
			s.pixelWidth = menu.menuWidth + (menu.menuBorder * 2);
			s.width = s.pixelWidth + 'px';
			if( menu.menuBgOpaque ) s.backgroundColor = menu.menuLiteBgColor;

			var body = FIND("menuFg" + x);
			s = body.style;
			s.pixelHeight = menu.menuHeight + menu.menuBorder;
			s.height = s.pixelHeight + 'px';
			s.pixelWidth = menu.menuWidth + menu.menuBorder;
			s.width = s.pixelWidth + 'px';
			if( menu.menuBgOpaque ) s.backgroundColor = menu.bgColor;

			s = menuLayer.style;
			s.pixelWidth  = menu.menuWidth + (menu.menuBorder * 4);
			s.width = s.pixelWidth + 'px';
			s.pixelHeight  = menu.menuHeight+(menu.menuBorder*4);
			s.height = s.pixelHeight + 'px';
		}
	}
	if (document.captureEvents) document.captureEvents(Event.MOUSEUP);
	if (document.addEventListener) document.addEventListener("mouseup", onMenuItemOver, false);
	if (document.layers && window.innerWidth) {
		window.onresize = NS4resize;
		window.NS4sIW = window.innerWidth;
		window.NS4sIH = window.innerHeight;
		setTimeout("NS4resize()",500);
	}
	document.onmouseup = mouseupMenu;
	window.mmWroteMenu = true;
	status = "";
}

function NS4resize() {
	if (NS4sIW != window.innerWidth || NS4sIH != window.innerHeight) window.location.reload();
}

function onMenuItemOver(e, l) {
	MM_clearTimeout();
	l = l || this;
	a = window.ActiveMenuItem;
	if (document.layers) {
		if (a) {
			a.document.bgColor = a.saveColor;
			if (a.hilite) a.hilite.visibility = "hidden";
			if (a.Menu.bgImageOver) a.background.src = a.Menu.bgImageUp;
			a.focusItem.top = -100;
			a.clicked = false;
		}
		if (l.hilite) {
			l.document.bgColor = l.menuHiliteBgColor;
			l.zIndex = 1;
			l.hilite.visibility = "inherit";
			l.hilite.zIndex = 2;
			l.document.layers[1].zIndex = 1;
			l.focusItem.zIndex = this.zIndex +2;
		}
		if (l.Menu.bgImageOver) l.background.src = l.Menu.bgImageOver;
		l.focusItem.top = this.top;
		l.focusItem.left = this.left;
		l.focusItem.clip.width = l.clip.width;
		l.focusItem.clip.height = l.clip.height;
		l.Menu.hideChildMenu(l);
	} else if (l.style && l.Menu) {
		if (a) {
			a.style.backgroundColor = a.saveColor;
			if (a.hilite) a.hilite.style.visibility = "hidden";
			if (a.hiliteShim) a.hiliteShim.style.visibility = "inherit";
			if (a.Menu.bgImageUp) a.style.background = "url(" + a.Menu.bgImageUp +")";;
		} 
		l.style.backgroundColor = l.menuHiliteBgColor;
		l.zIndex = 1;
		if (l.Menu.bgImageOver) l.style.background = "url(" + l.Menu.bgImageOver +")";
		if (l.hilite) {
			l.hilite.style.visibility = "inherit";
			if( l.hiliteShim ) l.hiliteShim.style.visibility = "visible";
		}
		l.focusItem.style.pixelTop = l.style.pixelTop;
		l.focusItem.style.top = l.focusItem.style.pixelTop + 'px';
		l.focusItem.style.pixelLeft = l.style.pixelLeft;
		l.focusItem.style.left = l.focusItem.style.pixelLeft + 'px';
		l.focusItem.style.zIndex = l.zIndex +1;
		l.Menu.hideChildMenu(l);
	} else return;
	window.ActiveMenuItem = l;
}

function onMenuItemAction(e, l) {
	l = window.ActiveMenuItem;
	if (!l) return;
	hideActiveMenus();
	if (l.mmaction) eval("" + l.mmaction);
	window.ActiveMenuItem = 0;
}

function MM_clearTimeout() {
	if (mmHideMenuTimer) clearTimeout(mmHideMenuTimer);
	mmHideMenuTimer = null;
	mmDHFlag = false;
}

function MM_startTimeout() {
	if( window.ActiveMenu ) {
		mmStart = new Date();
		mmDHFlag = true;
		mmHideMenuTimer = setTimeout("mmDoHide()", window.ActiveMenu.Menu.hideTimeout);
	}
}

function mmDoHide() {
	if (!mmDHFlag || !window.ActiveMenu) return;
	var elapsed = new Date() - mmStart;
	var timeout = window.ActiveMenu.Menu.hideTimeout;
	if (elapsed < timeout) {
		mmHideMenuTimer = setTimeout("mmDoHide()", timeout+100-elapsed);
		return;
	}
	mmDHFlag = false;
	hideActiveMenus();
	window.ActiveMenuItem = 0;
}

function MM_showMenu(menu, x, y, child, imgname) {
	if (!window.mmWroteMenu) return;
	MM_clearTimeout();
	if (menu) {
		var obj = FIND(imgname) || document.images[imgname] || document.links[imgname] || document.anchors[imgname];
		x = moveXbySlicePos (x, obj);
		y = moveYbySlicePos (y, obj);
	}
	if (document.layers) {
		if (menu) {
			var l = menu.menuLayer || menu;
			l.top = l.left = 1;
			hideActiveMenus();
			if (this.visibility) l = this;
			window.ActiveMenu = l;
		} else {
			var l = child;
		}
		if (!l) return;
		for (var i=0; i<l.layers.length; i++) { 			   
			if (!l.layers[i].isHilite) l.layers[i].visibility = "inherit";
			if (l.layers[i].document.layers.length > 0) MM_showMenu(null, "relative", "relative", l.layers[i]);
		}
		if (l.parentLayer) {
			if (x != "relative") l.parentLayer.left = x || window.pageX || 0;
			if (l.parentLayer.left + l.clip.width > window.innerWidth) l.parentLayer.left -= (l.parentLayer.left + l.clip.width - window.innerWidth);
			if (y != "relative") l.parentLayer.top = y || window.pageY || 0;
			if (l.parentLayer.isContainer) {
				l.Menu.xOffset = window.pageXOffset;
				l.Menu.yOffset = window.pageYOffset;
				l.parentLayer.clip.width = window.ActiveMenu.clip.width +2;
				l.parentLayer.clip.height = window.ActiveMenu.clip.height +2;
				if (l.parentLayer.menuContainerBgColor && l.Menu.menuBgOpaque ) l.parentLayer.document.bgColor = l.parentLayer.menuContainerBgColor;
			}
		}
		l.visibility = "inherit";
		if (l.Menu) l.Menu.container.visibility = "inherit";
	} else if (FIND("menuItem0")) {
		var l = menu.menuLayer || menu;	
		hideActiveMenus();
		if (typeof(l) == "string") l = FIND(l);
		window.ActiveMenu = l;
		var s = l.style;
		s.visibility = "inherit";
		if (x != "relative") {
			s.pixelLeft = x || (window.pageX + document.body.scrollLeft) || 0;
			s.left = s.pixelLeft + 'px';
		}
		if (y != "relative") {
			s.pixelTop = y || (window.pageY + document.body.scrollTop) || 0;
			s.top = s.pixelTop + 'px';
		}
		l.Menu.xOffset = document.body.scrollLeft;
		l.Menu.yOffset = document.body.scrollTop;
	}
	if (menu) window.activeMenus[window.activeMenus.length] = l;
	MM_clearTimeout();
}

function onMenuItemDown(e, l) {
	var a = window.ActiveMenuItem;
	if (document.layers && a) {
		a.eX = e.pageX;
		a.eY = e.pageY;
		a.clicked = true;
    }
}

function mouseupMenu(e) {
	hideMenu(true, e);
	hideActiveMenus();
	return true;
}

function getExplorerVersion() {
	var ieVers = parseFloat(navigator.appVersion);
	if( navigator.appName != 'Microsoft Internet Explorer' ) return ieVers;
	var tempVers = navigator.appVersion;
	var i = tempVers.indexOf( 'MSIE ' );
	if( i >= 0 ) {
		tempVers = tempVers.substring( i+5 );
		ieVers = parseFloat( tempVers ); 
	}
	return ieVers;
}

function mouseoutMenu() {
	if ((navigator.appName == "Microsoft Internet Explorer") && (getExplorerVersion() < 4.5))
		return true;
	hideMenu(false, false);
	return true;
}

function hideMenu(mouseup, e) {
	var a = window.ActiveMenuItem;
	if (a && document.layers) {
		a.document.bgColor = a.saveColor;
		a.focusItem.top = -30;
		if (a.hilite) a.hilite.visibility = "hidden";
		if (mouseup && a.mmaction && a.clicked && window.ActiveMenu) {
 			if (a.eX <= e.pageX+15 && a.eX >= e.pageX-15 && a.eY <= e.pageY+10 && a.eY >= e.pageY-10) {
				setTimeout('window.ActiveMenu.Menu.onMenuItemAction();', 500);
			}
		}
		a.clicked = false;
		if (a.Menu.bgImageOver) a.background.src = a.Menu.bgImageUp;
	} else if (window.ActiveMenu && FIND("menuItem0")) {
		if (a) {
			a.style.backgroundColor = a.saveColor;
			if (a.hilite) a.hilite.style.visibility = "hidden";
			if (a.hiliteShim) a.hiliteShim.style.visibility = "inherit";
			if (a.Menu.bgImageUp) a.style.background = "url(" + a.Menu.bgImageUp +")";
		}
	}
	if (!mouseup && window.ActiveMenu) {
		if (window.ActiveMenu.Menu) {
			if (window.ActiveMenu.Menu.hideOnMouseOut) MM_startTimeout();
			return(true);
		}
	}
	return(true);
}

function hideChildMenu(hcmLayer) {
	MM_clearTimeout();
	var l = hcmLayer;
	for (var i=0; i < l.Menu.childMenus.length; i++) {
		var theLayer = l.Menu.childMenus[i];
		if (document.layers) theLayer.visibility = "hidden";
		else {
			theLayer = FIND(theLayer);
			theLayer.style.visibility = "hidden";
			if( theLayer.Menu.menuItemHAlign != 'left' ) {
				for(var j = 0; j < theLayer.Menu.menuItemLayers.length; j++) {
					var itemLayer = theLayer.Menu.menuItemLayers[j];
					if(itemLayer.textShim) itemLayer.textShim.style.visibility = "inherit";
				}
			}
		}
		theLayer.Menu.hideChildMenu(theLayer);
	}
	if (l.childMenu) {
		var childMenu = l.childMenu;
		if (document.layers) {
			l.Menu.MM_showMenu(null,null,null,childMenu.layers[0]);
			childMenu.zIndex = l.parentLayer.zIndex +1;
			childMenu.top = l.Menu.menuLayer.top + l.Menu.submenuYOffset;
			if( l.Menu.vertical ) {
				if( l.Menu.submenuRelativeToItem ) childMenu.top += l.top + l.parentLayer.top;
				childMenu.left = l.parentLayer.left + l.parentLayer.clip.width - (2*l.Menu.menuBorder) + l.Menu.menuLayer.left + l.Menu.submenuXOffset;
			} else {
				childMenu.top += l.top + l.parentLayer.top;	
				if( l.Menu.submenuRelativeToItem ) childMenu.left = l.Menu.menuLayer.left + l.left + l.clip.width + (2*l.Menu.menuBorder) + l.Menu.submenuXOffset;
				else childMenu.left = l.parentLayer.left + l.parentLayer.clip.width - (2*l.Menu.menuBorder) + l.Menu.menuLayer.left + l.Menu.submenuXOffset;
			}
			if( childMenu.left < l.Menu.container.clip.left ) l.Menu.container.clip.left = childMenu.left;
			var w = childMenu.clip.width+childMenu.left-l.Menu.container.clip.left;
			if (w > l.Menu.container.clip.width)  l.Menu.container.clip.width = w;
			var h = childMenu.clip.height+childMenu.top-l.Menu.container.clip.top;
			if (h > l.Menu.container.clip.height) l.Menu.container.clip.height = h;
			l.document.layers[1].zIndex = 0;
			childMenu.visibility = "inherit";
		} else if (FIND("menuItem0")) {
			childMenu = FIND(l.childMenu);
			var menuLayer = FIND(l.Menu.menuLayer);
			var s = childMenu.style;
			s.zIndex = menuLayer.style.zIndex+1;
			if (document.all || window.mmIsOpera) {
				s.pixelTop = menuLayer.style.pixelTop + l.Menu.submenuYOffset;
				if( l.Menu.vertical ) {
					if( l.Menu.submenuRelativeToItem ) s.pixelTop += l.style.pixelTop;
					s.pixelLeft = l.style.pixelWidth + menuLayer.style.pixelLeft + l.Menu.submenuXOffset;
					s.left = s.pixelLeft + 'px';
				} else {
					s.pixelTop += l.style.pixelTop;
					if( l.Menu.submenuRelativeToItem ) s.pixelLeft = menuLayer.style.pixelLeft + l.style.pixelLeft + l.style.pixelWidth + (2*l.Menu.menuBorder) + l.Menu.submenuXOffset;
					else s.pixelLeft = (menuLayer.style.pixelWidth-4*l.Menu.menuBorder) + menuLayer.style.pixelLeft + l.Menu.submenuXOffset;
					s.left = s.pixelLeft + 'px';
				}
			} else {
				var top = parseInt(menuLayer.style.top) + l.Menu.submenuYOffset;
				var left = 0;
				if( l.Menu.vertical ) {
					if( l.Menu.submenuRelativeToItem ) top += parseInt(l.style.top);
					left = (parseInt(menuLayer.style.width)-4*l.Menu.menuBorder) + parseInt(menuLayer.style.left) + l.Menu.submenuXOffset;
				} else {
					top += parseInt(l.style.top);
					if( l.Menu.submenuRelativeToItem ) left = parseInt(menuLayer.style.left) + parseInt(l.style.left) + parseInt(l.style.width) + (2*l.Menu.menuBorder) + l.Menu.submenuXOffset;
					else left = (parseInt(menuLayer.style.width)-4*l.Menu.menuBorder) + parseInt(menuLayer.style.left) + l.Menu.submenuXOffset;
				}
				s.top = top + 'px';
				s.left = left + 'px';
			}
			childMenu.style.visibility = "inherit";
		} else return;
		window.activeMenus[window.activeMenus.length] = childMenu;
	}
}

function hideActiveMenus() {
	if (!window.activeMenus) return;
	for (var i=0; i < window.activeMenus.length; i++) {
		if (!activeMenus[i]) continue;
		if (activeMenus[i].visibility && activeMenus[i].Menu && !window.mmIsOpera) {
			activeMenus[i].visibility = "hidden";
			activeMenus[i].Menu.container.visibility = "hidden";
			activeMenus[i].Menu.container.clip.left = 0;
		} else if (activeMenus[i].style) {
			var s = activeMenus[i].style;
			s.visibility = "hidden";
			s.left = '-200px';
			s.top = '-200px';
		}
	}
	if (window.ActiveMenuItem) hideMenu(false, false);
	window.activeMenus.length = 0;
}

function moveXbySlicePos (x, img) { 
	if (!document.layers) {
		var onWindows = navigator.platform ? navigator.platform == "Win32" : false;
		var macIE45 = document.all && !onWindows && getExplorerVersion() == 4.5;
		var par = img;
		var lastOffset = 0;
		while(par){
			if( par.leftMargin && ! onWindows ) x += parseInt(par.leftMargin);
			if( (par.offsetLeft != lastOffset) && par.offsetLeft ) x += parseInt(par.offsetLeft);
			if( par.offsetLeft != 0 ) lastOffset = par.offsetLeft;
			par = macIE45 ? par.parentElement : par.offsetParent;
		}
	} else if (img.x) x += img.x;
	return x;
}

function moveYbySlicePos (y, img) {
	if(!document.layers) {
		var onWindows = navigator.platform ? navigator.platform == "Win32" : false;
		var macIE45 = document.all && !onWindows && getExplorerVersion() == 4.5;
		var par = img;
		var lastOffset = 0;
		while(par){
			if( par.topMargin && !onWindows ) y += parseInt(par.topMargin);
			if( (par.offsetTop != lastOffset) && par.offsetTop ) y += parseInt(par.offsetTop);
			if( par.offsetTop != 0 ) lastOffset = par.offsetTop;
			par = macIE45 ? par.parentElement : par.offsetParent;
		}		
	} else if (img.y >= 0) y += img.y;
	return y;
}

function MM_swapImgRestore() { 
	//v3.0
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { 
	//v3.0
	var d=document;
	if(d.images) {
		if(!d.MM_p) d.MM_p=new Array();
		var i,j=d.MM_p.length,a=MM_preloadImages.arguments;
		for (i=0; i<a.length; i++) {
			if (a[i].indexOf("#")!=0) {
				d.MM_p[j]=new Image;
				d.MM_p[j++].src=a[i];
			}
		}
	}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

