var isNav, isIE, isNN6;

if(parseInt(navigator.appVersion)>=4)
{
	if(navigator.appName=="Netscape")
	{
		isNav=true;
		if(document.getElementById) isNN6=true;
		else isNN6=false;
		
	}
	else isIE=true;
}
var menuItems=new Array();
var menuItemProps=new Array();

var rootMenu=null;	// rootMenu
var timer;			// Timer.  Gives a pause before collapsing all menus.
var holdtime=0;		// Pause time before collapsing all menus.
var image;
var imageName;

function collapseRootMenu()
{

	if(rootMenu)
	{
		rootMenu.hide();
		rootMenu=null;
		collapseRootMenu()
		showStatus('')
	}
}
function openRootMenu(menu,left,top,z_index,image)
{
	if(rootMenu) collapseRootMenu();
	if(timer) clearTimeout(timer);

	if(menu)
	{
		rootMenu=menu;
		rootMenu.expand(left,top,z_index,image);
		rootMenu.show(image);
		imageName=image	
	}
}
function menuItemProp(width,bgcolor,highlightcolor,borderwidth,imagesrc,css_attributes)
{

	var id=menuItemProps.length;
	this.id=id;
	this.className="menuProp" + id;
	this.width=width;
	this.bgcolor=bgcolor;
	this.highlightcolor=highlightcolor;
	this.borderwidth=borderwidth;
	this.imagesrc=imagesrc;

	var styleStr="<STYLE TYPE='text/css'>";
	styleStr += "." + this.className + "{";
	for(var i in css_attributes)
	{
		styleStr += i + ":" + css_attributes[i] + ";";
	}
	styleStr += "}";
	styleStr += "</STYLE>";
 
	document.write(styleStr);
	
	menuItemProps[id]=this;//Add to global list of menuItemProps.
	
	return this;
}
function menuItem(label,onclick,props,sub_menu)
{
	var id=menuItems.length;
	var objTag="";

	if(isIE || isNN6)
	{
		objTag += "<div id='" + id + "'";
		objTag += " class='" + props.className + "'";
		objTag += " style='";
		objTag += " position:absolute;";
		objTag += " visibility:hidden;";
		objTag += " left:0;";
		objTag += " top:0;";
		objTag += " width:" + props.width + ";";
		objTag += " background-color:" + props.bgcolor +";";
		objTag += " filter:alpha(opacity=90)";
		objTag += " z-index:0;";
		objTag += "'";
		objTag += " onmouseover=\"menuItem_mouseover('" + id + "');\"";
		objTag += " onmouseout=\"menuItem_mouseout('" + id + "');\"";
		if(onclick)
		{
			objTag += " onclick=\"collapseRootMenu();" + onclick + "\"";
		}
		objTag += ">";
		if(sub_menu)
		{
			 objTag += "<img src='" + props.imagesrc + "' border=0 align=right>";
		}
		objTag += label
		objTag += "</nobr></div>";
	}
	else
	if(isNav)
	{
		objTag += "<layer id='" + id + "'";
		objTag += " class='" + props.className + "'";
		objTag += " visibility=hidden";
		objTag += " left=0";
		objTag += " top=0";
		objTag += " width=" + props.width;
		objTag += " bgcolor=" + props.bgcolor;
		objTag += " z-index=0";
		objTag += " onmouseover=\"menuItem_mouseover('" + id + "');\"";
		objTag += " onmouseout=\"menuItem_mouseout('" + id + "');\"";
		if(onclick)
		{
			objTag += " onfocus=\"collapseRootMenu();" + onclick + "\"";
		}
		objTag += ">";
		if(sub_menu)
		{
			 objTag += "<img src='" + props.imagesrc + "' border=0 align=right>";
		}
		objTag += label
		objTag += "</layer>";
	}
	
	// Create object.
	document.write(objTag);

	this.obj=getMenuItem(id);	// Store a handle to the object we just created.
	this.id =id;
	this.menu=null;				// The menu that the menuItem belongs to.
	this.subMenu=sub_menu;		// A subMenu to display beneath the menuItem.
	
	// Save the display properties that we need.
	this.bgcolor=props.bgcolor;
	this.highlightcolor=props.highlightcolor;
	this.borderwidth=props.borderwidth;

	menuItems[id]=this;			// Add to global list of menuItems.
	return this;
}
function getMenuItem(id)
{
	if(isIE) return eval("document.all('" + id + "')");
	else
	if(isNav)
	{
		if(isNN6) return document.getElementById(''.concat(id));
		else return eval("document.layers['" + id + "']");
	}
	return null;
}
function menuItem_mouseover(id)
{
	clearTimeout(timer);

	var currMenuItem=menuItems[id];
	var currMenu=currMenuItem.menu;
	var obj=currMenuItem.obj;

	currMenu.setActiveMenuItem(currMenuItem);
	// If another subMenu is open for the current menu, close it.
	if(currMenu.openSubMenu)
	{
		currMenu.openSubMenu.hide();
		currMenu.openSubMenu=null;
	}
	// If there is a subMenu associated with this menuItem, open it.
	if(currMenuItem.subMenu)
	{
		if(currMenuItem.subMenu.width <= 0 || currMenuItem.subMenu.height <= 0)
		{
			currMenuItem.subMenu.calculateDimensions();
		}
		// Determine position for subMenu based on position of menuItem and current menu's direction.
		var left, top, z_index;
		var objLeft, objTop, objWidth, objHeight, objZIndex;
		var pageLeft, pageRight, pageTop, pageBottom;
		if(isIE)
		{
			objLeft=obj.style.pixelLeft;
			objTop=obj.style.pixelTop;
			objWidth=obj.offsetWidth;
			objHeight=obj.offsetHeight;
			objZIndex=obj.style.zIndex;
			pageLeft=document.body.scrollLeft;
			pageRight=document.body.clientWidth + document.body.scrollLeft;
			pageTop=document.body.scrollTop;
			pageBottom=document.body.clientHeight + document.body.scrollTop;
		}
		else
		if(isNav)
		{
			objLeft=obj.left;
			objTop=obj.top;
			objWidth=obj.clip.width;
			objHeight=obj.clip.height;
			objZIndex=obj.zIndex;
			pageLeft=pageXOffset;
			pageRight=window.innerWidth + pageXOffset;
			pageTop=pageYOffset;
			pageBottom=window.innerHeight + pageYOffset;
		}
		//if (currMenu.direction == "right" && (objLeft + objWidth - 4 + currMenuItem.subMenu.width > pageRight)) {
		if(currMenu.direction == "right" && (objLeft + 80 + currMenuItem.subMenu.width > pageRight) && (objLeft - 80 + objWidth - currMenuItem.subMenu.width >= pageLeft))
		{
			currMenu.direction="left";
		}
		else
		if(currMenu.direction == "left" && (objLeft -80 < pageLeft) && (objLeft + 80 + currMenuItem.subMenu.width <= pageRight))
		{
			currMenu.direction="right";
		}
		currMenuItem.subMenu.direction=currMenu.direction;
		if(currMenu.direction == "right")
		{
			left=objLeft + 80;
		}
		else
		{
			left=objLeft - 80 + objWidth - currMenuItem.subMenu.width;
		}
		
		top=objTop + 20;
		while (top + currMenuItem.subMenu.height > pageBottom && top - objHeight + currMenuItem.borderwidth > pageTop) {
			top -= objHeight - currMenuItem.borderwidth;
		}
		z_index=objZIndex + 1;
		currMenuItem.subMenu.expand(left, top, z_index);
		currMenuItem.subMenu.show();
		currMenu.openSubMenu=currMenuItem.subMenu;
	}
}
function menuItem_mouseout()
{
	timer=setTimeout("collapseRootMenu();", holdtime);
}
function menu()
{
	this.menuItems=new Array();
	for(var i=0; i < menu.arguments.length; i++)
	{
		this.menuItems[i]=menu.arguments[i];
		menu.arguments[i].menu=this;
	}
	this.width=0;				// Overall width of menu.
	this.height=0;				// Overall height of menu.
	this.direction="right";		// Initially, all menus should go to the right.
	this.openSubMenu=null;		// Handle to any open subMenus.
	this.activeMenuItem=null;	// Handle to menuItem under cursor.
	this.show=menu_show;		// Method to display the menu.
	this.hide=menu_hide;		// Method to hide the menu.
	this.expand=menu_expand;	// Method to place menu at a specific position.
	
	this.calculateDimensions=menu_calculateDimensions;
	this.setActiveMenuItem=menu_setActiveMenuItem;

	return this;
}
function menu_calculateDimensions()
{
	var menuItemWidth=0;
	var menuItemHeight=0;
	
	for(var i=0; i < this.menuItems.length; i++)
	{
		var borderwidth=this.menuItems[i].borderwidth;
		var obj=this.menuItems[i].obj;
		if(isIE)
		{
			menuItemWidth=obj.offsetWidth;
			menuItemHeight=obj.offsetHeight - borderwidth;
		}
		else
		if(isNav)
		{
			if(isNN6)
			{
				var obj=document.getElementById(''.concat(this.menuItems[i].id));
				menuItemWidth=obj.offsetWidth;
				menuItemHeight=obj.offsetHeight - borderwidth;
			}
			else
			{
				menuItemWidth=obj.clip.width;
				menuItemHeight=obj.clip.height - borderwidth;
			}
		}
		this.width=menuItemWidth > this.width ? menuItemWidth : this.width;
		this.height += menuItemHeight;
	}
	if(isIE)
	{
		for(var i=0; i < this.menuItems.length; i++)
		{
			this.menuItems[i].obj.style.width=this.width;
		}	
	}
}
function menu_setActiveMenuItem(menuItem)
{
	if(this.activeMenuItem)
	{
		var obj=this.activeMenuItem.obj;
		var bgcolor=this.activeMenuItem.bgcolor;
		if(isIE)
		{
			obj.style.backgroundColor=bgcolor;
		}
		else
		if(isNav)
		{
			if(isNN6)
			{
				var obj= document.getElementById(''.concat(this.activeMenuItem.id));
				obj.style.backgroundColor=bgcolor;
			}
			else
			{
				obj.bgColor=bgcolor;
			}
		}
		this.activeMenuItem=null;
	}
	if(menuItem)
	{
		var obj=menuItem.obj;
		var highlightcolor=menuItem.highlightcolor
		if(isIE)
		{
			obj.style.backgroundColor=highlightcolor;
		}
		else
		if(isNav)
		{
			if(isNN6)
			{
				var obj= document.getElementById(''.concat(menuItem.id));
				obj.style.backgroundColor=highlightcolor;
			}
			else
			{
				obj.bgColor=highlightcolor;
			}
		}
		this.activeMenuItem=menuItem;
	}
}
function menu_expand(left, top, z_index)
{
	if(this.width <= 0 || this.height <= 0)
	{
		this.calculateDimensions();
	}
	for(var i=0; i < this.menuItems.length; i++)
	{
		var obj=this.menuItems[i].obj;
		var borderwidth=this.menuItems[i].borderwidth
		if(isIE)
		{
			obj.style.zIndex=z_index;
			obj.style.pixelLeft=left;
			obj.style.pixelTop=top;

			top += obj.offsetHeight - borderwidth;
		}
		else
		if(isNav)
		{
			if(isNN6)
			{
				var obj=document.getElementById(''.concat(this.menuItems[i].id));
				obj.style.zIndex=z_index;
				obj.style.left=left;
				obj.style.top=top;
				top += obj.offsetHeight - borderwidth;
			}
			else
			{
				obj.zIndex=z_index;
				obj.moveTo(left, top);
				top += obj.clip.height - borderwidth;
			}
		}
	}
}
function menu_show()
{
	for(var i=0; i < this.menuItems.length; i++)
	{
		var obj=this.menuItems[i].obj;
		if(isIE)
		{
			obj.style.visibility="visible";
		}
		else
		if(isNav)
		{
			if(isNN6)
			{
				var obj=document.getElementById(''.concat(this.menuItems[i].id));
				obj.style.visibility="visible";
			}
			else
			{
				obj.visibility="visible";
			}
		}
	}
}
function menu_hide()
{
	if(this.openSubMenu)
	{
		this.openSubMenu.hide();
		this.openSubMenu=null;
	}
	this.setActiveMenuItem(null);
	this.direction="right";
	for(var i=0; i < this.menuItems.length; i++)
	{
		var obj=this.menuItems[i].obj;
		if(isIE)
		{
			obj.style.visibility="hidden";
		}
		else
		if(isNav)
		{
			if(isNN6)
			{
				var obj=document.getElementById(''.concat(this.menuItems[i].id));
				obj.style.visibility="hidden";
			}
			else
			{
				obj.visibility="hidden";
			}
		}
	}
}
function showStatus(msg)
{
	window.status = msg;
	return true;
}
