//menuItem Class Definition

//This function serves as the constructor of the menuitem object
function menuItem( anOwner, sName, sURL )
{
	this.Top = 0;
	this.Left = 0;
	this.Height = 0;
	this.Width = 230;
	this.bIsVisible = false;
	this.bMouseIsOverMenu = false;
	
	//***Class methods
	this.WriteMenu = MenuItem_WriteMenu;
	this.newMenuItem = MenuItem_newMenuItem;

	this.show = MenuItem_show;
	this.hide = MenuItem_hide;
	this.hideIfNotActive = MenuItem_hideIfNotActive;
	//***

	//***Event handling
	this.onMouseOver = MenuItem_OnMouseOver;
	this.onMouseOut = MenuItem_OnMouseOut;
	//***

	this.Id = "Id" + iNewId++;		//The Id needs to be a string for use as an array index
	this.Name = sName;
	this.URL = sURL;
	this.Owner = anOwner;

	this.MenuItems = new Array();
}

function MenuItem_OnMouseOver()
{
	this.bMouseIsOverMenu = true;

	// Also call the mouse over event of the menuContent object
	this.Owner.onMouseOver();

	this.show();
}

function MenuItem_OnMouseOut()
{
	this.bMouseIsOverMenu = false;

	//Set a delay because first order in which mouse events are processed
	setTimeout("document.CA_objects[\'" + this.Id + "\'].hideIfNotActive()",30);
	
	this.Owner.onMouseOut();
}

function MenuItem_newMenuItem(sName, sURL)
{
	var aMenuItem;

	aMenuItem = new menuItem(this, sName, sURL);
	this.MenuItems[aMenuItem.Id] = aMenuItem;
	this.MenuItems[this.MenuItems.length] = aMenuItem;

	//Add to global collection of objects. Through this collection objects with a unique id can be found
	document.CA_objects[aMenuItem.Id] = aMenuItem;

	return aMenuItem
}

function getAbsoluteLeftPosition(anObject)
{
	var iLeft;
	
	iLeft = anObject.offsetLeft;
	if( anObject.offsetParent != null)
		iLeft += getAbsoluteLeftPosition(anObject.offsetParent);

	return iLeft;
}
function getAbsoluteTopPosition(anObject)
{
	var iTop;
	
	iTop = anObject.offsetTop;
	if( anObject.offsetParent != null)
		iTop += getAbsoluteTopPosition(anObject.offsetParent);

	return iTop;
}

function MenuItem_show()
{
	var iTop, positioningObject, iLeft, aLayer, iHeight;

	if( this.MenuItems.length > 0 )
	{
		if(isMinIE4) //IE
		{
			aLayer = findObject(this.Id + 'Content');
	
			positioningObject = findObject(this.Id + "Title", document);
			iLeft = getAbsoluteLeftPosition(positioningObject);
			iTop = getAbsoluteTopPosition(positioningObject);
			if( this.Owner.ExpandLocation == "left" )
			{
				iLeft = iLeft - aLayer.style.pixelWidth;
			}

			aLayer.style.left = iLeft;
			aLayer.style.top = iTop;
		}
		if(isMinNS4)
		{
			aLayer = findObject(this.Id + 'Content');
		}
		setLayerVisibility(this.Id + 'Content', 'show');
			
		this.bIsVisible = true;
	}
}

function MenuItem_hide()
{
	setLayerVisibility(this.Id + 'Content', 'hide');

	this.bMouseIsOverMenu = false;
	this.bIsVisible = false;
}

function MenuItem_hideIfNotActive()
{
	if( this.bIsVisible && !this.bMouseIsOverMenu )
	{
		this.hide();
	}
}

function MenuItem_WriteMenu()
{
	var sId = this.Id + "Content";
	var iWidth = this.Width;
	var iZIndex = 10;
	var sBGColor = '#D5EAF9'
	var sBorderColor = '#007ED7';
	var aLayer = null;
	var aMenuItem = null;

	if(isMinIE4) //IE
	{
		positioningObject = findObject(this.Id + "Title", document);
		iLeft = getAbsoluteLeftPosition(positioningObject);
		iTop = getAbsoluteTopPosition(positioningObject);

		iHeight= this.borderSizeTop + this.MenuItems.length * (this.itemHeight + this.borderSize) + this.borderSizeBottom;
		iWidth= this.Width;

		iHeight=1;
		this.Height = iHeight;

		sOnMouseOver = 'onMouseOver="document.CA_objects[\'' + this.Id + '\'].onMouseOver()"';
		sOnMouseOut = 'onMouseOut="document.CA_objects[\'' + this.Id + '\'].onMouseOut()"';
		document.write('<div ' + sOnMouseOver + ' ' + sOnMouseOut + ' name="' + sId + '" id="'+ sId +'" style="position:absolute; width:' + iWidth + 'px; height:' + iHeight + 'px; z-index:' + iZIndex + '; left: '+ iLeft + 'px; top: ' + iTop + 'px; visibility: hidden; background-color: ' + sBGColor + '">');


		document.write('<TABLE WIDTH="' + iWidth + '" BORDER="0" CELLSPACING="0" CELLPADDING="0" BGCOLOR="#D5EAF9">');
		document.write('<TR>');
		document.write('<TD COLSPAN=3 BGCOLOR="' + sBorderColor + '"><IMG SRC="empty.gif" WIDTH="' + iWidth + '" HEIGHT="1"></TD>');
		document.write('</TR>');
		document.write('<TR>');
		document.write('<TD BGCOLOR="' + sBorderColor + '"><IMG SRC="empty.gif" WIDTH="1" HEIGHT="1"></TD>');

		document.write('<TD>');

		document.write('<TABLE WIDTH="' + (iWidth-2) + '" BORDER="0" CELLSPACING="0" CELLPADDING="0" BGCOLOR="#D5EAF9">');
		for( var iIndex = 0; iIndex < this.MenuItems.length; iIndex++ )
		{
			aMenuItem = this.MenuItems[iIndex]
			document.write('<TR>');
			document.write('<TD>&nbsp;</TD>');
			document.write('<TD>');
			
			sOnMouseOver = 'onMouseOver="document.CA_objects[\'' + aMenuItem.Id + '\'].onMouseOver()"';
			sOnMouseOut = 'onMouseOut="document.CA_objects[\'' + aMenuItem.Id + '\'].onMouseOut()"';

			document.write( '<SPAN CLASS="StandardText">' );
			document.write('<A STYLE="width: 100%" HREF="' + aMenuItem.URL + '" ' + sOnMouseOver + ' ' + sOnMouseOut + '>');
			document.write('<NOBR>');
			document.write( '&gt; &nbsp;' + aMenuItem.Name );
			document.write( '</NOBR>' );
			document.write( '</A>' );
			document.write( '</SPAN>' );
			
			document.write('<SPAN CLASS="StandardText" NAME="' + aMenuItem.Id + 'Title" ID="' + aMenuItem.Id + 'Title">');
			document.write('</SPAN>');
			
			document.write('</TD>');
			document.write('<TD ALIGN=RIGHT>');
			document.write('<BR>');
			document.write('</TD>');
			document.write('</TR>');
		}
		document.write('</TABLE>');

		document.write('<BR>');

		document.write('<TD>');
		document.write('<TD BGCOLOR="' + sBorderColor + '"><IMG SRC="empty.gif" WIDTH="1" HEIGHT="1"></TD>');
		document.write('</TR>');

		document.write('<TR>');
		document.write('<TD COLSPAN=3 BGCOLOR="' + sBorderColor + '"><IMG SRC="empty.gif" WIDTH="' + iWidth + '" HEIGHT="1"></TD>');
		document.write('</TR>');
		document.write('</TABLE>');

		document.write('</div>');
	}
	
	return true;
}




