if ( ! versions_loaded ) {

    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;

    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 Menu( mname, _imagename ) {
    // Set up properties for this instance
    this.name         = mname;
    this.imagename    = _imagename;
    this.items        = new Array();
    this.items.length = 0;
    // If the _width parameter isn't supplied, make an attempt
    // to determine the menu width based on the image's width.
    var imgWidth      = null;
    if ( _imagename ) {
	var img  = getImage( _imagename );
	if ( img ) {
	    imgWidth = getImageWidth( img );
	}
    }
    if ( imgWidth ) this.width = imgWidth;
    // If borderstyle is "image", make sure leftimage, leftimagewidth and
    // leftimagecolor are specified
    if ( this.borderstyle && this.borderstyle == "image" ) {
	if ( ! this.leftimagewidth || ! this.leftimage ) {
	    this.borderstyle = "solid";
	    this.leftimage = null;
	}
	else if ( ! this.leftimagecolor ) {
	    this.leftimagecolor = "#000000";
	}
    }
    // 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_createMenuItem( miname, mivalue ) {
    var newitem;
    newitem          = new MenuItem( miname, mivalue );
    newitem.index    = this.items.length;
    newitem.menuname = this.name;
    this.items[this.items.length++] = newitem;
    return( newitem );
}

function Menu_addMenuItem( miname, mivalue ) {
    var newitem;
    if (
	! this.maxitems
	|| this.spilltype == "columns"
	|| this.items.length < this.maxitems
	|| mivalue == "---submenu"
	) {
	newitem = this.createMenuItem( miname, mivalue );
    }
    else {
	if ( ! this.childmenu ) {
	    var cname = this.name + "_child";
	    var cimg  = this.name + "_child_img";
	    var cm = new Menu( cname, cimg );
	    this.childmenu = cm;
	    this.addSubMenu( cm, "more.gif" );
	}
	newitem = this.childmenu.addMenuItem( miname, mivalue );
    }
    return( newitem );
}

function Menu_addMenuItemHeader( miname, mivalue ) {
    var newitem = this.addMenuItem( miname, mivalue );
    if ( newitem ) {
	newitem.bold = true;
    }
    return( newitem );
}

function Menu_addMenuSeparator( hidden ) {
    var newitem = this.addMenuItem( "separator", "---" );
    if ( newitem ) {
	newitem.hidden = hidden;
    }
    return( newitem );
}

function Menu_addSubMenu( menu, mimage ) {
    var newitem    = this.addMenuItem( menu.name, "---submenu" );
    if ( newitem ) {
	newitem.image       = mimage;
	newitem.menu        = menu;
	newitem.menu.parent = this;
    }
    return( newitem );
}

function Menu_setLocation() {
    var img = getImage( this.imagename );
    var x, y;
    if ( this.parent ) {
	var parent_layer = getLayer( this.parent.name );
	x = getObjLeft(parent_layer) + getObjWidth(parent_layer) + 1;
	y = getObjTop(parent_layer)  + getImageTop( img ) + this.topOffset + 1;
    }
    else {
	x = getImageLeft( img );
/*/	if(this.imagename == 'freemail') {
//		x -= 118;
//	}
	if(this.imagename == 'help') {
		x -= 126;
	}
	if(this.imagename == 'news') {
		LeftRef = x;
	}*/
	y = getImageTop( img ) + getImageHeight( img ) + this.topOffset + 1;
    }
    moveObjTo( getLayer(this.name), x, y, true );
    if ( this.childmenu ) {
	this.childmenu.setLocation();
    }
}

function Menu_show() {
    if ( NS4 || ( IE4 && ! MAC ) ) {
	if ( this.parent ) this.parent.show();
	var menuName = this.name;
	if ( this.imagename )
	    setImage( this.imagename, "active" );
	// Move the menu to a location near the image
	var layer = getLayer( menuName );
	if ( this.imagename && isHidden(layer) ) {

		this.setLocation(2);
	    // Now, adjust the bottom of the menu with respect to the bottom
	    // of the window to make sure the entire menu is displayed.
	    var y = getObjTop( layer );
	    var x = getObjLeft( layer );
	    // adjust the top
	    var lbottom = y + getObjHeight( layer );
	    var wbottom = getInsideWindowHeight();
	    var wtop    = getWindowTop();
	    if ( lbottom > ( wbottom + wtop )) {
		y -= ( lbottom - ( wbottom + wtop ) );
	    }
	    if ( y < wtop )
		y = wtop;
	    // adjust the left edge
	    var lright  = getObjLeft( layer ) + getObjWidth( layer );
	    var wright  = getInsideWindowWidth();
	    var wleft   = getWindowLeft();
	    if ( lright > ( wright + wleft ) ) {
		x -= lright - ( wright + wleft );
	    }
	    if ( x < wleft )
		x = wleft;
	    // move the object to the new location
	    moveObjTo( layer, x, y, true );
	}
	// Display the menu
	showLayer( layer );
	clearTimeout( this.timeout );
    }
}

function Menu_hide( now ) {
    if ( NS4 || ( IE4 && ! MAC ) ) {
	if ( now ) {
	    if ( this.imagename )
		setImage( this.imagename, "inactive" );
	    hideLayer( getLayer(this.name) );
	}
	else {
	    var cmd      = 'allmenus["' + this.name + '"].hide(true)';
	    var delay    = this.delay;
	    this.timeout = setTimeout( cmd, delay );
	    if ( this.parent ) {
		this.parent.hide();
	    }
	}
    }
}

function Menu_print() {
    var menu = this;
    // write the header
    var output = "";
if ( NS4 || ( IE4 && ! MAC ) ) {
	// Make sure we haven't already been printed
	if ( getLayer(this.name) ) return;

	if ( this.childmenu ) {
	    this.childmenu.print();
	}

	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 += 'width:' + menu.width + 'px;height:' + menu.height + ';"';
	    output += '>\n';
	    output += '<table border="0" cellpadding="0" cellspacing="0">\n';
	    output += '<tr><td height="0" bgcolor="#333333" colspan="1"><img src="/images/spacer.gif" width="1" height="1" border="0"></td></tr>\n';
	    output += '<tr><td height="0" bgcolor="#000000"><img src="/images/spacer.gif" width="0" height="1" border="0"></td><td>\n';
//	    output += '<table border="0" cellpadding="0" cellspacing="0" background="/img/menubg.gif">\n';
	    output += '<table border="1" cellpadding="0" cellspacing="0" bordercolor="#000000" bgcolor="#333333">\n';
	}
	else {
	    output += '<layer name="' + menu.name + '" ';
	    output += 'onMouseOver="showMenu(\'' + menu.name + '\')" ';
	    output += 'onMouseOut="hideMenu(\'' + menu.name + '\')" ';
	    output += 'width="' + menu.width + '" height="' + menu.height + '" ';
	    output += 'visibility="hidden" zIndex="59000"';
	    output += '>\n';
	    output += '<table border="0" cellpadding="0" cellspacing="0">\n';
	    output += '<tr><td height="0" bgcolor="#000000" colspan="1"><img src="/images/spacer.gif" width="0" height="0" border="0"></td></tr>\n';
	    output += '<tr><td height="0" bgcolor="#000000"><img src="/images/spacer.gif" width="0" height="0" border="0"></td><td>\n';
//	    output += '<table border="0" cellpadding="0" cellspacing="0" background="/img/menubg.gif">\n';
	    output += '<table border="0" cellpadding="0" cellspacing="0" bordercolor="#000000" bgcolor="#333333">\n';
	}

	// now add all the menu items
	var j, c;
	for ( j = 0, c = 0; j < menu.items.length; j++, c++ ) {
	    if ( c > this.maxitems && this.spilltype == "columns" ) {
		output += '</td>\n<td valign="top">';
		c = 0;
		if ( menu.items[0].bold ) {
		    output += '&nbsp;<br>';
		    c++;
		}
	    }
	    var mi = menu.items[j];
	    if ( mi.name == "separator" ) {
		if ( mi.hidden ) {
		    output += "<br>";
		}
		else {
		    output +=  '<hr class="magellan" size="0">' ;
		}
	    }
	    else {
		output += this.makeMenuItem( mi, false );
	    }
	    output += '\n';
	}

	if ( navigator.appName == "Microsoft Internet Explorer" ) {
	    output += '</table>\n';
	    output += '</td><td height="0" bgcolor="#000000"><img src="/images/spacer.gif" width="0" height="0" border="0"></td></tr>\n';
	    output += '<tr><td height="0" bgcolor="#000000" colspan="3"><img src="/images/spacer.gif" width="0" height="0" border="0"></td></tr>\n';
	    output += '</table>\n';
	    output += '</div>\n';
	}
	else {
	    output += '</table>\n';
	    output += '</td><td height="0" bgcolor="#000000"><img src="/images/spacer.gif" width="0" height="0" border="0"></td></tr>\n';
	    output += '<tr><td height="0" bgcolor="#000000" colspan="1"><img src="/images/spacer.gif" width="0" height="0" border="0"></td></tr>\n';
	    output += '</table>\n';
	    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 Menu_makeMenuItem( mi ) {
    var output = "";
    if ( mi.bold ) output += '<b>';
    if ( mi.value == "---submenu" ) {
		output += '<a href="#" onClick="return false"';
		output += ' onMouseOver="showMenu(' + "'" + mi.menu.name + "'" + ')"';
		output += ' onMouseOut="hideMenu('  + "'" + mi.menu.name + "'" + ')"';
		output += '>';
		output += '<img name="' + mi.menu.imagename + '" src="' + mi.image + '" border="0"></a><br>';
    } else {
		var label = mi.name;
		if ( this.nobreaks ) {
		    var t = "";
		    var start, end;
		    for ( start = 0, end = 0; (end = label.indexOf(" ",start)) != -1; ) {
				t += label.substring(start,end) + "&nbsp;";
				start = end + 1;
		    }
		    t += label.substring( start );
		    label = t;
		}
		output += '<tr><td>&nbsp;&nbsp;<a href="' + mi.value + '">' + mi.name + '</a>&nbsp;&nbsp;</td></tr>';
    }
    if ( mi.bold ) output += '</b>';
//    output += '</div>';
    return( output );
}


/* **********************************************************************
 * Initialize the Menu object prototype.
 * **********************************************************************/

if ( ! Opera ) {
    new MenuItem( "", "" );
    new Menu( 'discard' );
    // Properties
    Menu.prototype.maxitems          = 0;
    Menu.prototype.childmenu         = null;
    Menu.prototype.width             = 220
    Menu.prototype.height            = 0;
    Menu.prototype.imagename         = null;
    Menu.prototype.borderstyle       = null;
    Menu.prototype.bordercolor       = "#333333";
    Menu.prototype.bgcolor           = "#000000";
    Menu.prototype.bottomshadow      = "#333333";
    Menu.prototype.topshadow         = "#333333";
    Menu.prototype.leftOffset1        = 0;
    Menu.prototype.leftOffset2        = -50;
    Menu.prototype.leftOffset3        = -50;
    Menu.prototype.topOffset         = 0;
    Menu.prototype.padding           = 0;
    Menu.prototype.delay             = 30;
    Menu.prototype.rollover          = false;
    Menu.prototype.leftimage         = null;
    Menu.prototype.leftimagewidth    = 0;
    Menu.prototype.leftimagecolor    = '';
    Menu.prototype.spilltype         = "child";
    Menu.prototype.nobreaks          = 0;
    // Methods
    Menu.prototype.createMenuItem    = Menu_createMenuItem;
    Menu.prototype.addMenuItem       = Menu_addMenuItem;
    Menu.prototype.addMenuItemHeader = Menu_addMenuItemHeader;
    Menu.prototype.addMenuSeparator  = Menu_addMenuSeparator;
    Menu.prototype.addSubMenu        = Menu_addSubMenu;
    Menu.prototype.makeMenuItem      = Menu_makeMenuItem;
    Menu.prototype.getHeight         = Menu_getHeight;
    Menu.prototype.show              = Menu_show;
    Menu.prototype.GetRefCoords	 = GetRefCoords;
    Menu.prototype.hide              = Menu_hide;
    Menu.prototype.print             = Menu_print;
    Menu.prototype.setLocation       = Menu_setLocation;
}



/* **********************************************************************
 * The following functions operate the menus.
 * **********************************************************************/

function printMenus() {
    var i = 0;
    for ( ; i < allmenus.length; i++ ) {
	allmenus[i].print();
    }
    return( i );
}

function highlightLink( menuName, itemidx, highlight ) {
    if ( ver4 ) {
	var anchor = getImage( menuName + itemidx + "link" );
	if ( anchor && IE4 ) {
	    anchor.className = ( highlight ? 'magellanlinkhi' : 'magellanlink' );
	}
    }
    return( false );
}

function showMenu( menuName ) {
    if ( allmenus[menuName] ) allmenus[menuName].show();
}

function hideMenu( menuName ){
    if ( allmenus[menuName] ) allmenus[menuName].hide();
}

function GetRefCoords() {
    if ( NS4 || ( IE4 && ! MAC ) ) {
	if ( this.parent ) this.parent.show();
	var menuName = this.name;
	if ( this.imagename )
	    setImage( this.imagename, "active" );
	// Move the menu to a location near the image
	var layer = getLayer( menuName );
	if ( this.imagename && isHidden(layer) ) {

		this.setLocation(2);
	    // Now, adjust the bottom of the menu with respect to the bottom
	    // of the window to make sure the entire menu is displayed.
	    var y = getObjTop( layer );
	    var x = getObjLeft( layer );
	    // adjust the top
	    var lbottom = y + getObjHeight( layer );
	    var wbottom = getInsideWindowHeight();
	    var wtop    = getWindowTop();
	    if ( lbottom > ( wbottom + wtop )) {
		y -= ( lbottom - ( wbottom + wtop ) );
	    }
	    if ( y < wtop )
		y = wtop;
	    // adjust the left edge
	    var lright  = getObjLeft( layer ) + getObjWidth( layer );
	    var wright  = getInsideWindowWidth();
	    var wleft   = getWindowLeft();
	    if ( lright > ( wright + wleft ) ) {
		x -= lright - ( wright + wleft );
	    }
	    if ( x < wleft )
		x = wleft;
	    // move the object to the new location
	    moveObjTo( layer, x, y, true );
	}
    }
}
