

if ( ! versions_loaded ) {

    // Determine Browser Version
    var bV   = parseInt( navigator.appVersion );
    var NS4  = (document.layers)         ? true : false;
    var NS3  = (document.images)         ? true : false;
    var IE4  = ((document.all)&&(bV>=4)) ? true : false;
    var ver4 = (NS4 || IE4)              ? true : false;

    // Determine Browser Platform
    var MAC   = (navigator.userAgent.indexOf("Mac")      != -1) ? true : false;
    var Opera = (navigator.userAgent.indexOf("Opera")    != -1) ? true : false;
    var IE5   = (navigator.userAgent.indexOf("MSIE 5.0") != -1) ? true : false;
    
    var versions_loaded = true;
}


/* **********************************************************************
 * Create a MenuItem object.
 * **********************************************************************/

function MenuItem( miname, mivalue ) {
    if ( ! Opera ) {
	this.name  = miname;
	this.value = mivalue;
	this.bold  = false;
	return( this );
    }
}

    
    
    
/* **********************************************************************
 * Create the Menu object.
 * **********************************************************************/
    
var allmenus    = new Array(); // tracks all created menus for later printing.
allmenus.length = 0;
    
function getMenuImage( menuname ) {
    var imgname = null;
    if ( allmenus[menuname] )
	imgname = allmenus[menuname].imagename;
    return( imgname );
}

function Menu( mname, _imagename ) {
    // Set up properties for this instance
    this.name                   = mname;
    this.imagename              = _imagename;
    Menu.prototype.items        = new Array();
    Menu.prototype.items.length = 0;
    // Add the menu to the list of menus if it's not the prototype
    if ( mname != "discard" ) {
	allmenus[allmenus.length++] = this;
	allmenus[mname]             = this;
    }
    return( this );
}

function Menu_addMenuItem( miname, mivalue ) {
    var newitem      = new MenuItem( miname, mivalue );
    newitem.index    = this.items.length;
    newitem.menuname = this.name;
    this.items[this.items.length++] = newitem;
    return( newitem );
}

function Menu_addMenuItemHeader( miname, mivalue ) {
    var newitem = this.addMenuItem( miname, mivalue );
    newitem.bold = true;
    return( newitem );
}

function Menu_addMenuSeparator( hidden ) {
    var newitem = new MenuItem( "separator", "---" );
    newitem.hidden = hidden;
    this.items[this.items.length++] = newitem;
    return( newitem );
}

function Menu_print() {
    var menu = this;
    // write the header
    var output = "";
    if ( NS4 || ( IE4 && ! MAC ) ) {

	if ( navigator.appName == "Microsoft Internet Explorer" ) {
	    output += '<div id="' + menu.name + '" ';
	    output += 'onMouseOver="showMenu(\'' + menu.name + '\')" ';
	    output += 'onMouseOut="hideMenu(\'' + menu.name + '\')" ';
	    output += 'style="position:absolute;z-index:59600;visibility:hidden;"';
	    output += '>\n';
	}
	else {
	    output += '<layer name="' + menu.name + '" ';
	    output += 'onMouseOver="showMenu(\'' + menu.name + '\')" ';
	    output += 'onMouseOut="hideMenu(\'' + menu.name + '\')" ';
	    output += 'visibility="hidden" zIndex=569000"';
	    output += '>\n';
	}
	    output += '<table border="0" cellpadding="0" cellspacing="0" bgcolor="' + menu.bgcolor + '">\n';
            output += '<tr bgcolor="' + menu.bordercolor + '"><td rowspan="6" width="1"><img src="bin/spacer.gif" alt height="1" width="1"></td>';
	    output += '<td colspan="3" height="1"><img src="bin/spacer.gif" alt height="1" width="1"></td>';
	    output += '<td rowspan="6" width="1"><img src="bin/spacer.gif" alt height="1" width="1"></td></tr>\n';
	    output += '<tr><td width="3"><img src="bin/spacer.gif" alt height="1" width="1"></td>';
	    output += '<td><img src="bin/spacer.gif" alt height="1" width="1"></td>';
	    output += '<td width="5"><img src="bin/spacer.gif" alt height="1" width="1"></td></tr>\n';
	    output += '<tr><td width="3"><img src="bin/spacer.gif" alt height="1" width="1"></td>';
	    output += '<td><table border="0" cellpadding="0" cellspacing="0">';
	    output += '<tr><td valign="top" >\n';
	// now add all the menu items
	for ( var j = 0; j < menu.items.length; j++ ) {
	    var mi = menu.items[j];
	    if ( mi.name == "separator" ) {
		if ( mi.hidden ) {
		    output += "<br>";
		}
		else {
		    output +=  '<hr class="magellan" size="1">' ;
		}
	    }
	    else {
		output += makeMenuItem( mi, false );
	    }
	    output += '\n';
	}
      // and add in the footer
	    output += '</tr></table></td></td>\n';
	    output += '<td width="5"><img src="bin/spacer.gif" alt height="1" width="1"></td></tr>\n';
	    output += '<tr><td width="3"><img src="bin/spacer.gif" alt height="1" width="1"></td>\n';
	    output += '<td><img src="bin/spacer.gif" alt height="1" width="1"></td>';
	    output += '<td width="5"><img src="bin/spacer.gif" alt height="1" width="1"></td></tr>\n';
          output += '<tr bgcolor="' + menu.bordercolor + '"><td colspan="4" height="1"></td></tr>';
	    output += '</table>\n';
	if ( navigator.appName == "Microsoft Internet Explorer" ) {
	    output += '</div>\n';
	}
	else {
	    output += '</layer>\n';
	}
	document.write( output );
    }
}

function Menu_getHeight() {
    var height = 0;
    var i;
    for ( i = 0; i < this.items.length; i++ ) {
	height += getObjHeight( this.items[i].name );
    }
    return( height );
}

function makeMenuItem( mi ) {
    var output = "";
    output += '<tr height="1"><td></td></tr>';
    output += '<tr><td>&nbsp;<a href="' + mi.value + '" class="menu"';
    output += ' id="' + mi.menuname + mi.index + 'link"';
    output += ' onMouseOver="highlightLink(\'' + mi.menuname + '\',' + mi.index + ',true)"';
    output += ' onMouseOut="highlightLink(\'' + mi.menuname + '\',' + mi.index + ',false)"';
    output += '>';
    output +=  mi.name + '</a>&nbsp;</td></tr><tr height="1"><td><img src="bin/spacer.gif" alt height="1" width="1"></td></tr>' ;
    return( output );
}

if ( ! Opera ) {
    new MenuItem( "", "" );
    new Menu( 'discard' );
    Menu.prototype.leftOffset        = 0;
    Menu.prototype.topOffset         = 0;
    Menu.prototype.padding           = 0;
    Menu.prototype.delay             = 0;
    Menu.prototype.rollover          = false;
    Menu.prototype.leftimage         = null;
    Menu.prototype.leftimagewidth    = 0;
    Menu.prototype.leftimagecolor    = '';
    Menu.prototype.addMenuItem       = Menu_addMenuItem;
    Menu.prototype.addMenuItemHeader = Menu_addMenuItemHeader;
    Menu.prototype.addMenuSeparator  = Menu_addMenuSeparator;
    Menu.prototype.getHeight         = Menu_getHeight;
    Menu.prototype.print             = Menu_print;
}

/* **********************************************************************
 * Create a function to print all menus.
 * **********************************************************************/

function printMenus() {
    var i = 0;
    for ( ; i < allmenus.length; i++ ) {
	allmenus[i].print();
    }
    return( i );
}

/* **********************************************************************
 * The following functions operate the menus.
 * **********************************************************************/


var timers     = new Object();

function highlightLink( menuName, itemidx, highlight ) {
    if ( ver4 ) {
	var anchor = getImage( menuName + itemidx + "link" );
	if ( anchor && IE4 ) {
	    anchor.className = ( highlight ? 'menu' : 'menu' );
	}
    }
    return( false );
}

function showMenu( menuName ) {
    var imgName = getMenuImage( menuName );
    if ( imgName )
	setImage( imgName, "active" );
    if ( NS4 || ( IE4 && ! MAC ) ) {
	// Move the menu to a location near the image
	var layer = getLayer( menuName );
	if ( imgName && isHidden(layer) ) {
	    var img = getImage( imgName );
	    var x   = getImageWidth(img) + getImageLeft(img) + allmenus[menuName].leftOffset;
	    var y   = getImageTop(img) + allmenus[menuName].topOffset;
	    moveObjTo( layer, x, y, true );
	    // Now, adjust the bottom of the menu with respect to the bottom
	    // of the window to make sure the entire menu is displayed.
	    // This is done after the initial move so the height of the
	    // object can be properly determined.
	    var lbottom = getObjTop( layer ) + getObjHeight( layer );
	    var wbottom = getInsideWindowHeight();
	    var wtop    = getWindowTop();
	    if ( lbottom > ( wbottom + wtop )) {
		y -= ( lbottom - ( wbottom + wtop ) );
		if ( y < wtop ) y = wtop;
		moveObjTo( layer, x, y, true );
		
	    }
	}
	// Display the menu
	showLayer( layer );
	clearTimeout( timers[menuName] );
    }
}

function hideMenu( menuName ){
    var cmd = 'hideMenu_delayed("' + menuName + '")';
    var delay = 50;
    if ( allmenus[menuName] )
	delay = allmenus[menuName].delay;
    if ( ver4 )
	timers[menuName] = setTimeout( cmd, delay );
    else
	eval( cmd );
}

function hideMenu_delayed( menuName ) {
    var imgName = getMenuImage( menuName );
    if ( imgName )
	setImage( imgName, "inactive" );
    if ( NS4 || ( IE4 && ! MAC ) )
	hideLayer( getLayer(menuName) );
}

if ( ! versions_loaded ) {

    // Determine Browser Version
    var bV   = parseInt( navigator.appVersion );
    var NS4  = (document.layers)         ? true : false;
    var NS3  = (document.images)         ? true : false;
    var IE4  = ((document.all)&&(bV>=4)) ? true : false;
    var ver4 = (NS4 || IE4)              ? true : false;

    // Determine Browser Platform
    var MAC   = (navigator.userAgent.indexOf("Mac")      != -1) ? true : false;
    var Opera = (navigator.userAgent.indexOf("Opera")    != -1) ? true : false;
    var IE5   = (navigator.userAgent.indexOf("MSIE 5.0") != -1) ? true : false;

    var versions_loaded = true;
}


var cached_images = new Object();

function replaceString( string, replacement ) {
    var idx = string.indexOf( "%s" );
    var newstring = string;
    if ( idx >= 0 ) {
	newstring = string.substring( 0, idx ) + replacement + string.substring( idx + 2 );
    }
    return( newstring );
}


/*
 * Outputs necessary JavaScript code to cache images and
 * make them easily retrieved later by rollover code.
 * Form1: cacheImage( name, width, height, directory )
 * Form2: cacheImage( name, width, height, pattern, on_text, off_text )
 * In the former case, the "on" image (the image displayed when
 * the mouse is over the image) will be directory + '/' + name + '2.gif'.
 * The off image, the default state, will be
 * directory + '/' + name + '1.gif'.
 * In the latter case, the pattern should contain %s (for example,
 * /images/product_menu%s.gif).  The %s will then be replaced with the
 * value of on_text when the mouse is over the image, or will be
 * replaced with the value of off_text when the mouse is not.
 */
function cacheImage( name, w, h, directory_or_pattern, on_text, off_text ) {
    if ( NS3 ) {
	if ( directory_or_pattern.indexOf("%s") != -1  ) {
	    var pattern = directory_or_pattern;
	    cached_images[name]            = new Object();
	    cached_images[name].imgon      = new Image( w, h );
	    cached_images[name].imgon.src  = replaceString( pattern, on_text );
	    cached_images[name].imgoff     = new Image( w, h );
	    cached_images[name].imgoff.src = replaceString( pattern, off_text );
	}
	else {
	    var directory = directory_or_pattern;
	    cached_images[name]            = new Object();
	    cached_images[name].imgon      = new Image( w, h );
	    cached_images[name].imgon.src  = directory + "/" + name + "2.gif";
	    cached_images[name].imgoff     = new Image( w, h );
	    cached_images[name].imgoff.src = directory + "/" + name + "1.gif";
	}
    }
}


/*
 * Retrieve an image src from the cache
 */
function getImageSource( name, state ) {
    var imgSrc = null;
    if ( NS3 ) {
	if ( cached_images[name] ) {
	    if ( state == "active" ) {
		imgSrc = cached_images[name].imgon.src;
	    } else if ( state == "inactive" ) {
		imgSrc = cached_images[name].imgoff.src;
	    }
	}
    }
    return( imgSrc );
}

function setImage( imgName, state ) {
    if ( NS3 ) {
	var newimg = getImageSource( imgName, state );
	if ( newimg )
	    document.images[imgName].src = getImageSource( imgName, state );
    }
}

if ( ! versions_loaded ) {

    // Determine Browser Version
    var bV   = parseInt( navigator.appVersion );
    var NS4  = (document.layers)         ? true : false;
    var NS3  = (document.images)         ? true : false;
    var IE4  = ((document.all)&&(bV>=4)) ? true : false;
    var ver4 = (NS4 || IE4)              ? true : false;

    // Determine Browser Platform
    var MAC   = (navigator.userAgent.indexOf("Mac")      != -1) ? true : false;
    var Opera = (navigator.userAgent.indexOf("Opera")    != -1) ? true : false;
    var IE5   = (navigator.userAgent.indexOf("MSIE 5.0") != -1) ? true : false;

    var versions_loaded = true;
}

/* **********************************************************************
 * WINDOW METHODS
 * **********************************************************************/

function getInsideWindowWidth() {
    var width = -1;
    if ( NS4 )
	width = window.innerWidth;
    else if ( IE4 )
	width = document.body.clientWidth;
    return( width );
}

function getInsideWindowHeight() {
    var height = -1;
    if ( NS4 )
	height = window.innerHeight;
    else if ( IE4 )
	height = document.body.clientHeight;
    return( height );
}

function getWindowLeft() {
    var x = -1;
    if ( NS4 )
	x = window.pageXOffset;
    else if ( IE4 )
	x = document.body.scrollLeft;
    return( x );
}

function getWindowTop() {
    var y = -1;
    if ( NS4 )
	y = window.pageYOffset;
    else if ( IE4 )
	y = document.body.scrollTop;
    return( y );
}

/* **********************************************************************
 * GENERIC OBJECT LOCATOR METHODS
 * **********************************************************************/

function getObject( objectName, container ) {
    var object = null;
    if ( typeof(objectName) != "string" ) {
	object = objectName;
    } else if ( ver4 ) {
	if ( ! container )
	    container = document;
	if ( IE4 ) {
	    if ( container.all[objectName] )
		object = container.all[objectName];
	} else if ( NS4 ) {
	    if ( container.anchors[objectName] )
		object = container.anchors[objectName];
	    else if ( container.forms[objectName] )
		object = container.forms[objectName];
	    else if ( container.images[objectName] )
		object = container.images[objectName];
	    else if ( container.layers[objectName] )
		object = container.layers[objectName];
	}
    }
    return( object );
}
		 
function findObjectContainer( objectName, container ) {
    var objectContainer = null;
    if ( NS4 ) {
	if ( ! container ) container = window.document;
	if ( getObject(objectName,container) ) {
	    objectContainer = container;
	} else {
	    var layers = getLayers( new RegExp(".*"), container );
	    for ( var i = 0; i < layers.length; i++ ) {
		objectContainer = findObjectContainer( objectName, layers[i].document );
		if ( objectContainer ) break;
	    }
	}
    }
    else if ( IE4 ) {
	objectContainer = getObject(objectName,document) ? document : null;
    }
    return( objectContainer );
}

function findObject( objectName ) {
    var object = null;
    if ( ver4 ) {
	var container = findObjectContainer( objectName );
	if ( container ) object = getObject( objectName, container );
    }
    return( object );
}

/* **********************************************************************
 * LAYER METHODS
 * **********************************************************************/

function getLayer( name ) {
    var obj = null;
    if ( IE4 ) {
	obj = document.all[name];
    } else if ( NS4 ) {
	obj = document.layers[name];
    }
    return( obj );
}

function getLayers( regex, doc ) {
    var layers = new Array();
    layers.length = 0;
    if ( ver4 ) {
	if ( ! doc ) doc = document;
	if ( NS4 ) {
	    for ( var i = 0; i < doc.layers.length; i++ ) {
		var obj = doc.layers[i];
		if ( ! regex || regex.exec(obj.id) ) {
		    layers[layers.length] = obj;
		}
	    }
	} else if ( IE4 ) {
	    var divColl = doc.all.tags("DIV");
	    for ( i = 0; i < divColl.length; i++ ) {
		if ( ! regex || regex.exec(divColl[i].id) ) {
		    layers[layers.length] = divColl[i];
		}
	    }
	}
    }
    return( layers );
}

function isHidden( obj ) {
    if ( IE4 ) {
	return( obj.style.visibility == "hidden" );
    } else if ( NS4 ) {
	return( obj.visibility == "hide" );
    } else {
	return( false );
    }
}

function hideLayer( obj ) {
    if ( IE4 )
	obj.style.visibility = "hidden";
    else if ( NS4 )
	obj.visibility = "hide";
}

function showLayer( obj ) {
    if ( IE4 ) {
	obj.style.visibility = "visible";
    } else if ( NS4 ) {
	obj.visibility = "show";
    }
}

function getObjTop( obj ) {
    if ( ver4 )
	return( IE4 ? obj.style.pixelTop  : obj.top );
    else
	return( 0 );
}

function getObjLeft( obj ) {
    if ( ver4 )
	return( IE4 ? obj.style.pixelLeft : obj.left );
    else
	return( 0 );
}

function getObjHeight( obj ) {
    if ( ver4 )
	return( IE4 ? obj.clientHeight : (obj.clip ? obj.clip.height : -1 ) );
    else
	return( 0 );
}

function getObjWidth( obj ) {
    if ( ver4 )
	return( IE4 ? obj.clientWidth  : (obj.clip ? obj.clip.width : -1 ) );
    else
	return( 0 );
}

function moveObjTo( obj, x, y, yesIfHidden ) {
    if ( ! isHidden(obj) || yesIfHidden ) {
	if ( IE4 ) {
	    if ( x >= 0 ) obj.style.pixelLeft = x;
	    if ( y >= 0 ) obj.style.pixelTop  = y;
	} else if ( NS4 ) {
	    if ( x < 0 ) x = getObjLeft( obj );
	    if ( y < 0 ) y = getObjTop( obj );
	    obj.moveTo( x, y );
	}
    }
    return( 1 );
}

/* **********************************************************************
 * IMAGE METHODS
 * **********************************************************************/

function getImage( imgNm ) {
    return( findObject(imgNm) );
}

function getImageContainer( imgNm ) {
    return( findObjectContainer(imgNm) );
}

function getParentObject( obj ) {
    var parent = null;
    if ( IE4 ) {
	if ( obj.offsetParent )
	    parent = obj.offsetParent;
    } else if ( NS4 ) {
	// If we're looking at a layer object (or a window), get
	// the parentWindow value, otherwise search for the container
	if ( obj.parentLayer ) {
	    parent = obj.parentLayer || null;
	} else {
	    parent = findObjectContainer( obj );
	    if ( parent ) parent = parent.parentWindow;
	}
    }
    return( parent );
}

function findOffsetValue( obj, value ) {
    var offset = 0;
    if ( ver4 ) {
	// Requested value is specified as an MSIE offset value.
	// Perform any translations necessary for other browsers.
	if ( NS4 ) {
	    if ( value == "offsetLeft" )
		value = "pageX";
	    else if ( value == "offsetTop" )
		value = "pageY";
	}
	var parent = getParentObject( obj );
	while ( parent ) {
	    offset += ( parent[value] || 0 );
	    parent = getParentObject( parent );
	}
    }
    return( offset || 0 );
}

function getImageLeft( img ) {
    if ( typeof(img) == "string" ) img = getImage( img );
    var left   = 0;
    var offset = findOffsetValue( img, "offsetLeft" );
    if ( NS4 ) {
	left = img.x;
    } else if ( IE4 ) {
	left = img.offsetLeft;
    }
    return( left + offset );
}

function getImageTop( img ) {
    if ( typeof(img) == "string" ) img = getImage( img );
    var top    = 0;
    var offset = findOffsetValue( img, "offsetTop" );
    if ( NS4 ) {
	top = img.y;
    } else if ( IE4 ) {
	top = img.offsetTop;
    }
    return( top + offset );
}

function getImageHeight( img ) {
    if ( typeof(img) == "string" ) img = getImage( img );
    return( img.height );
}

function getImageWidth( img ) {
    if ( typeof(img) == "string" ) img = getImage( img );
    return( img.width );
}
