/*
* Defines a menu item.
* Params:
* name - images name
* link - where the menu item links to
* alt - The alt tag used.
*/
function menuItem(aName,aLink,anAlt) {
this.name = aName;
this.link = aLink;
this.alt = anAlt;
this.imageOn = new Image();
this.imageOff = new Image();
}
/*
* Returns a sub-menu based on the menu items passed in.
* Params:
* imagePath - The path to the images,e.g. "/common/images/subNav/"
* menuItems - An array of menu items.
* selectedName - The name of the item that is selected
* (Should be a menuItem.name)
*/
function makeMenu(imagePath, menuItems, selectedName) {
setupImages(imagePath, menuItems);
//Top section of the menu
var colspan = menuItems.length + menuItems.length-1;
var topPart = "
\n"
+ "\n | "
+ " | "
+ "\n | \n
";
var middlePart = "\n\n";
for (var i = 0; i < menuItems.length; i++) {
middlePart = middlePart + "    | \n";
if (i != menuItems.length-1) {
//Add divider
middlePart = middlePart + " | ";
}
}
middlePart = middlePart + "\n
";
//Bottom section of the menu
var buttomPart = "\n\n"
+ " | \n
\n
";
return topPart + (middlePart + buttomPart);
}
/*
* Sets the images ready for mouse overs:
* imagePath - The path to the images,e.g. "/common/images/subNav/"
* menuItems - An array of menu items.
*/
//duplicate this code for now in subNav.js, but remove from subNav.js when we put Bikes site live
function setupImages(imagePath, menuItems) {
if (document.images) {
for (var i = 0; i < menuItems.length; i++) {
menuItems[i].imageOn.src = eval('"' + imagePath + menuItems[i].name + "_on.gif" + '"');
menuItems[i].imageOff.src = eval('"' + imagePath + menuItems[i].name + "_off.gif" + '"');
} //end for
} //end if
}
// Function to 'activate' pics.
function menuImgOn(imgName, index, menuItems) {
if (document.images) {
document[imgName].src = menuItems[index].imageOn.src;
}
}
// Function to 'deactivate' pics.
function menuImgOff(imgName, index, menuItems) {
if (document.images) {
document[imgName].src = menuItems[index].imageOff.src;
}
}