<!--

// DYNAMIC MENUS - CODE
//
// Davide Andrea 4/9/2005
// Loosely based on code from buttongenerator.com

// Global variables
overBtnOrSub = false; 	// Flag set if the cursor is over a button or over a submenu 
noOfButtons = 0; 		// Number of Buttons (will be set later)
subMenuPosX	= 0;		// Horizontal position of left side of submenus
originalImageSrc = null	// The button's image before we hovered over it

// Global constants
SubMenuPrefix = 'submenu';	// Prefix used in the ID of submenus
SubMenuHideX = 100;	// Additional amount by which a hidden submenu is moved to the left

// AT START-UP, PARSE THE INPUT STRING AND GENERATE SUB MENUS
//document.write('<script type="text/javascript" src="menudata1.js"></script>');
buttonSubMenuData = SubMenuDataStr.split('^');
noOfButtons = buttonSubMenuData.length -1;

for (btnIndex = 1; btnIndex <= noOfButtons; btnIndex++) {	// For each button...
	subMenuData = new Array();
	if (buttonSubMenuData[btnIndex].length > 0){	// If the button has a submenu...
		buttonItemsData = new Array();
		buttonItemsData = buttonSubMenuData[btnIndex].split('+');
		noOfItems = buttonItemsData.length -1;

		// Create a div for it with a drop menu and an un-numbered list of the items
		document.write('<div id = "' + SubMenuPrefix + (btnIndex) + '" class = "dropmenu" ');	
		document.write('OnMouseOver = "GoIn(\'' + (btnIndex) + '\');"');
		document.write('OnMouseOut = "GoOut(\'' + (btnIndex) + '\');">');
		document.write('<ul>');

		for (itemNo = 1; itemNo <= noOfItems; itemNo++) {	// For each item in this button's submenu...
			subMenuData[itemNo] = buttonItemsData[itemNo].split('\t');
			//
			document.write('<li>');
			document.write('<a href = "' + subMenuData[itemNo][1] + '">');
			document.write( subMenuData[itemNo][0] + '</a>');
			document.write('</li>');
		}
		document.write('</ul>');

		// Find the screen coordinates of this button
		btnRef = document.images[BtnID_Prefix + btnIndex];	// Get a reference to the button

		// The line above finds the button using name="" instead of the id="". 
		// ID is preferred by newer browsers, but Name is more compatible with older browsers
		// If we used the id, we'd use the following line
		// In the page, find the button image whose tag has an id="..." element that ends with the button's number
		//btnRef = getElement(BtnID_Prefix + btnIndex);	// Get a reference to the button

		if (btnRef) { // If we have a reference to it...
			butX = btnRef.offsetLeft;	// Get its left...
			butY = btnRef.offsetTop;	// ... and top coordinates
			btnRef = btnRef.offsetParent;	// Get the reference to the container that contains this button
			while (btnRef != null) {		// From each container to its parent, until we reach the window...
				butX += btnRef.offsetLeft;	// Offset the coordinates by the relative position of this element...
				butY += btnRef.offsetTop;	// ...with respect to its container
				btnRef = btnRef.offsetParent;	// Get a reference to this element's container
			} 
		}
		
		// Hide the submenu by placing it next to the button, but all the way to the left, off screen
		// Later, when we want to show it, we'll just move it to the right, next to the button, and keep it at the same height
		subMenuRef = getElement(SubMenuPrefix + btnIndex);	// Get a reference to the submenu
		subMenuPosX = butX + SubMenuDeltaX; 				// Save the horizontal position where we'll place the submenus when showing them later (we only need to do this once, but it's easier to do it for each button)
		subMenuRef.style.left = -SubMenuWidth - SubMenuHideX; // Place the submenu all the way to the right, off screen
		subMenuRef.style.top = butY + SubMenuDeltaY;		// Line-up the submenu with its button

	} else {						// If the button has no submenu...
		// Create an empty div for it
		document.write('<div id = "' + SubMenuPrefix + (btnIndex) + '">');	
	}
	document.write('</div>');
}

// Preload the overlay images, to speed-up their display
if (document.images) {	// If the browser has a cache for images...
	overImages = []		// Prepare an array for the images
	for(btnNo = 1; btnNo <= noOfButtons; btnNo++) {	// For each button image...
		overImages[btnNo] = new Image(BtnWidth,BtnHeight)	// Create a blank image
		overImages[btnNo].src = ButtonFolder + FilePrefixHiLite + btnNo + FilePostfixHiLite // Fill that image with the overlay button image
	}
	
}


// THE CURSOR STARTED HOVERING OVER A BUTTON OR SUBMENU
function GoIn(btnNo) { // Receives the number of the button

	// Save the original image, so we may restore it later (this could be the normal or the selected image, depending on the menu and on the page)
	originalImageSrc = document.images[BtnID_Prefix + btnNo].src	

	// Highlight the button's image
	// Find the button image whose tag has an name="..." element that ends with the button's number
	// Replace the source of that image with the image file whose name has that same number, but is highligted
	// If the browser has a cache for images, use the preloaded image, else load it it on the fly
	document.images[BtnID_Prefix + btnNo].src = document.images? overImages[btnNo].src : ButtonFolder + FilePrefixHiLite + btnNo + FilePostfixHiLite

	// The line above finds the button using name="" instead of the id="". 
	// ID is preferred by newer browsers, but Name is more compatible with older browsers
	// If we used the id, we'd use the following line
	// In the page, find the button image whose tag has an id="..." element that ends with the button's number
	//document.getElementById(BtnID_Prefix + btnNo).src = ButtonFolder + FilePrefixHiLite + btnNo + FilePostfixHiLite;
	
	// Flag that the cursor is hovering over a buton or its submenu
	overBtnOrSub = true;

	// Show this button's submenu by moving it next to the button
	// and hide all the other submenus
	for (btnIndex = 1; btnIndex <= noOfButtons; btnIndex++) { // For each button...
		// If the submenu for this button, show it by placing it next to the button,
		//  else hide its submenu by moving it all the way to the left
		getElement(SubMenuPrefix + btnIndex).style.left = btnIndex == btnNo? subMenuPosX : -SubMenuWidth - SubMenuHideX;	
	}
}



// THE CURSOR LEFT A BUTTON OR ITS SUBMENU
function GoOut(btnNo) { // Receives the number of the button

	// Restore the button to the normal image
	// For comments, see GoIn, above
	if (originalImageSrc) document.images[BtnID_Prefix + btnNo].src = originalImageSrc  // IF we dis save the original image of this button, restore it (we didn't save it if the mouse entered this button befire the scripts were full loeaded, and is exiting it after they are loaded)
	// ButtonFolder + FilePrefixNormal + btnNo + FilePostfixNormal;
	//document.getElementById(BtnID_Prefix + btnNo).src = ButtonFolder + FilePrefixNormal + btnNo + FilePostfixNormal;

	// Flag that the cursor is done hovering over a buton or its submenu
	overBtnOrSub = false;
	
	// Tell Javascript to hide this button's submenu, in a little while
	subMenuID = SubMenuPrefix + btnNo;
	setTimeout('hideSubMenu(subMenuID)',SubMenuPersistTime);
}



// HIDE A SUBMENU AFTER A TIME-OUT
// Called by Javascript a while after we told it to do so
function hideSubMenu(subMenuID) { // Receives the ID of the submenu
	if ( overBtnOrSub == false ) { // If not still over a button or over a menu...
		getElement(subMenuID).style.left = -SubMenuWidth - SubMenuHideX; // Get a reference to the submenu and hide it by moving it off screen to the left
	}
}


// GET REFERENCE OF ELEMENT BY ID
// Return a reference to the first object it finds with a given ID
// Works with multiple browsers
function getElement(id) { // Receives the ID of the object
	// For newer DOM browsers, use the getElementById function. For older browsers use the document.all funcion
	return (document.getElementById ? document.getElementById(id) : (document.all ? document.all(id) : null)); 
}




-->
