//global variable to hold menu objects as they need to access themselves globally
menu.objects = new Array();

function menu(config)
{
	if (config[3] == null)
	{
		throw "The first entry in the menu configuration array may not be null.";
	}
	this.id = menu.objects.length;
	menu.objects[this.id] = this;

	this.showDelay = 100;
	this.hideDelay = 1000;
	this.left = '0';				//left and top position of menu if it is absolute
	this.top = '0';
	this.parentElement;			//element the menu is sitting under if it is relative
	this.imageBorders = false;	//use image borders on sub menus
	this.useIframes = true;		//use iframes behind each menu item, this prevent select problem in IE
	this.mouseOutPadding = 40; 	//used to capture mouseout events if over iframes in Mozilla
								//useIframes must be turned on
	this.mainTableClass = '';

	
	
	//dgb 20080610 Add horizontal and vertical sub menu offsets as well as
	//level 2+ submenu show delay and show pointer
	this.subMenuVertOffset = 0;			//Additional Vert offset to be used for sub menus
	this.subMenuHorzOffset = 0;			//Additional Horz offset to be used for sub menus
	this.subMenuShowDelay = 0; 			//Seperate delay to be used for submenus of level 2 or greater
	this.subMenuShowPointer = false;	//Used to automatically display a pointer if a submenu exists
	this.minSubMenuPointerLevel = 2;	//Minimum menu level that show pointer appears
	this.highlightParents = true;		//if set, automatically highlight parents 
						
	this.isRelative;
	this.isFixed = false;
	this.activeItem;
	this.showTimer;
	this.hideTimer;
	this.isIE = !!document.all;	//wacky way to check for document.all as per Forefox 1.0
	this.baseItem;
	this.minWidth;
	
	//this.imageURL = "images/";
	this.expandImage = "";
	this.expandImageOver = "";

	this.config = config;
}

var divTest;

menu.prototype.generate = function()
{
	var self = this;
	
	if (! document.body)
	{
		alert("Menu must be called after page has loaded!!");
		return;
	}

	this.isRelative = Boolean(this.parentElement);
	
	this.top = this.top + "px";
	this.left = this.left + "px";

	this.baseItem = new menuItem(this.config, null, this.id, this.subMenuVertOffset, this.subMenuHorzOffset);
	this.baseItem.generate();

	//if we have a relative menu, append to the parent element
	if (this.isRelative) {
		//if we have element id, get the element
		if (typeof(this.parentElement) == "string"){
			this.parentElement = utilities.getElement(this.parentElement);
		}
		this.parentElement.appendChild(this.baseItem.childShell);
	
		//fix for problem where IE does not move the menu up or down when window is resized, stupid IE
		if (this.baseItem.isIE)
		{
			utilities.addEvent(window, "resize", function(){
				self.baseItem.hide();
				self.baseItem.show();
			});
		}
	}
	else {
		this.baseItem.move(this.left.replace(/px/g,"")+'px', this.top.replace(/px/g,"")+'px');
	}
	
	this.baseItem.show();
}

menu.prototype.hideAll = function()
{
	this.activeItem = null;
	this.baseItem.hideChildren();
}

menu.prototype.showItem = function()
{
	if (this.activeItem){
		this.activeItem.show();
		//highlight parent
		//if(this.activeItem.parent){
		//	this.activeItem.parent.setClass(menuItem.CLASS_OVER);
		//}
	}
}

//intercepts the focus for any child frames so we know when the menu should be hidden
//hopefully doesn't slow the browser down..
menu.captureMouseOutOld = function()
{
	for (var i = 0; i < window.frames.length; i++)
	{
		utilities.addEvent(window.frames[i], 'mouseover', function(){parent.menu.onMouseOut()});
	}
}

//intercepts the focus for any child frames so we know when the menu should be hidden
//now does it recursively to capture all child windows
//could do it recursively on parents but that could get whack
//hopefully doesn't slow the browser down..
menu.captureMouseOut = function()
{
	menu.captureFrames(window, 'mouseover', 'parent.menu.onMouseOut()', true);
}

//performs the given action on the given event on all childframes of frame 
menu.captureFrames = function(frame, event, action, recursive)
{
	for (var i = 0; i < frame.frames.length; i++)
	{
		utilities.addEvent(frame.frames[i], event, function(){eval(action)});
		
		if (recursive)
			menu.captureFrames(frame.frames[i], event, 'parent.' + action, recursive);
	}
}

//allows other windows to initiate the onMouseOut method as there are problems with
//it not working with iframes in Mozilla
menu.onMouseOut = function()
{
	//call onmouseout on all menus
	for (var i in menu.objects)
		menu.objects[i].onMouseOut();
}

menu.prototype.onMouseOut = function()
{
	//call mouseout on activeItem if we have one and it hasn't already been called
	if (this.activeItem)// && ! this.hideTimer)
		this.activeItem._onmouseout();
}

//menuItem defines
menuItem.CLASS_OUT = 1;
menuItem.CLASS_OVER = 2;
menuItem.CLASS_DOWN = 3;
menuItem.CLASS_OUT_EXPAND = 4;
menuItem.CLASS_OVER_EXPAND = 5;
menuItem.CLASS_DOWN_EXPAND = 6;

function menuItem(config, parent, menuId, subMenuVertOffset, subMenuHorzOffset)
{
	this.title = config[0] ? config[0] : '';
	this.url = config[1] ? config[1] : '';
	this.target = config[2] ? config[2] : '_self';
	this.type = config[3] ? config[3] : 'vert';
	
	this.styleOut = config[5] ? config[5][0] ? config[5][0] : '' : '';
	this.styleOver = config[5] ? config[5][1] ? config[5][1] : '' : '';
	this.styleDown = config[5] ? config[5][2] ? config[5][2] : '' : '';

	this.styleOutExpand = this.styleOut + "_expand";
	this.styleOverExpand = this.styleOver + "_expand";
	this.styleDownExpand = this.styleDown + "_expand";
	
	this.styleChildShell = config[5] ? config[5][3] ? config[5][3] : '' : '';
	
	this.parent = null;
	this.level = 0;
	this.menuId = menuId;
	
	if (parent)
	{
		this.parent = parent;
		this.menuId = parent.menuId;
		this.level = parent.level + 1;
	}
		
	this.width;
	this.height;
	this.top;
	this.left;
	
	//dgb 20080610 Add horizontal and vertical sub menu offsets as well as
	//level 2+ submenu show delay and show pointer
	this.subMenuVertOffset = subMenuVertOffset;
	this.subMenuHorzOffset = subMenuHorzOffset;
	if (parent){
		this.subMenuVertOffset = parent.subMenuVertOffset;			//Additional Vert offset to be used for sub menus
		this.subMenuHorzOffset = parent.subMenuHorzOffset;			//Additional Horz offset to be used for sub menus
	}
	
	
	this.titleObj;
	this.childShell;
	
	this.children = new Array();
	this.activeChild;

	//loop through child menu items
	var childItems = config[4];
	for (var i in childItems)
	{
		//generate child menu item and store link to it
		this.children[i] = new menuItem(childItems[i], this);
		
	}
}

menuItem.prototype.generate = function()
{
	var self = this;
	var baseMenu = menu.objects[this.menuId];
	
	this.titleObj = document.createElement("td");
	this.titleObj.unselectable = "on";
	/* we now want to be able to put html in the title */
	
	//#dgb 20080610
	//if the menu has a submenu and is a vertical menu,
	this.titleObj.innerHTML = this.title;
	if(baseMenu.subMenuShowPointer && this.type == 'vert'
		&& this.level >= baseMenu.minSubMenuPointerLevel && this.children.length > 0){
		//this.titleObj.innerHTML = this.title + " <img src='" + baseMenu.expandImage + "' border='0'>"; //<span class='menu_pointer'>&#9658;</span>";
		//this.titleObj.innerHTML = this.title + " <span class='" + this.parent.styleOutExpand + "'> </span>"		
		this.setClass(menuItem.CLASS_OUT_EXPAND);
		if(baseMenu.expandImageOver){
			this.expandImageOver = baseMenu.expandImageOver;
		}
	}else{
	this.setClass(menuItem.CLASS_OUT);
		this.expandImage = false;
	}
	
	//this.titleObj.appendChild(document.createTextNode(this.title));
	//this.titleObj.noWrap = true;
	this.titleObj.style.cursor = "default";
	
	//this.setClass(menuItem.CLASS_OUT);
	if (! this.isBaseItem())
	{
		this.titleObj.onmouseover = function(){self._onmouseover()}
		this.titleObj.onmouseout = function(e){self._onmouseout(e ? e : window.event)}
		this.titleObj.onmousedown = function(){self.setClass(menuItem.CLASS_DOWN)}
		this.titleObj.onmouseup = function(){self.setClass(menuItem.CLASS_OVER)}
		
		if (this.url)
		{
			this.titleObj.onclick = function(){self._onclick()}
			this.titleObj.style.cursor = baseMenu.isIE ? "hand" : "pointer";
		}
	}
	
	if (this.children.length > 0)
	{			
		var table = document.createElement("table");
		this.childShell = table;
		table.className = this.styleChildShell;
		table.cellPadding = 0;
		table.cellSpacing = 0;
		//table.border = 0;
		table.style.display = "none";
		if(baseMenu.isRelative && this.isBaseItem()){
				table.style.position = "relative";
		}else if (baseMenu.isFixed){
			table.style.position = "fixed";
		}else{
			table.style.position = "absolute";
		}

		if(this.level==0)
		{
			table.style.zIndex = 1;
		} else
		{
			table.style.zIndex = this.level + 2000;	//iframe will be on the desired level with menu above that
		}
		
		var tbody = document.createElement("tbody");
		table.appendChild(tbody);
		var tr;
		var td;
		var img;
		
		//hack so first level doesn't have border
		if (this.level > 0 && baseMenu.imageBorders)
		{	
			//top left corner
			tr = document.createElement("tr");
			tbody.appendChild(tr);
			
			img = document.createElement("img");
			img.src = baseMenu.imageURL + "nav_topleft.gif";
			td = document.createElement("td");
			td.appendChild(img);
			tr.appendChild(td);
			
			//top
			td = document.createElement("td");
			td.style.backgroundImage = "url(" + baseMenu.imageURL + "nav_top.gif)";
			tr.appendChild(td);
			
			//top right corner
			img = document.createElement("img");
			img.src = baseMenu.imageURL + "nav_topright.gif";
			td = document.createElement("td");
			td.appendChild(img);
			tr.appendChild(td);
			
			//left
			tr = document.createElement("tr");
			tbody.appendChild(tr);
			
			td = document.createElement("td");
			td.style.backgroundImage = "url(" + baseMenu.imageURL + "nav_left.gif)";
			tr.appendChild(td);
		}
		else
		{
			tr = document.createElement("tr");
			tbody.appendChild(tr);
		}
		
		//content
		var _childShell = document.createElement("td");
		tr.appendChild(_childShell);
		
		if (this.level > 0 && baseMenu.imageBorders)
		{	
			//right
			td = document.createElement("td");
			td.style.backgroundImage = "url(" + baseMenu.imageURL + "nav_right.gif)";
			tr.appendChild(td);
			
			//bottom left corner
			tr = document.createElement("tr");
			tbody.appendChild(tr);
			
			img = document.createElement("img");
			img.src = baseMenu.imageURL + "nav_bottomleft.gif";
			td = document.createElement("td");
			td.appendChild(img);
			tr.appendChild(td);
			
			//bottom
			td = document.createElement("td");
			td.style.backgroundImage = "url(" + baseMenu.imageURL + "nav_bottom.gif)";
			tr.appendChild(td);
			
			//bottom right corner
			img = document.createElement("img");
			img.src = baseMenu.imageURL + "nav_bottomright.gif";
			td = document.createElement("td");
			td.appendChild(img);
			tr.appendChild(td);
		}
		
		var childCell;
		
		table = document.createElement("table");
		table.className = baseMenu.mainTableClass;
		table.cellPadding = 0;
		table.cellSpacing = 0;
		table.border = 0;
		if(baseMenu.minWidth>0) table.width=baseMenu.minWidth;
		var tbody = document.createElement("tbody");
		table.appendChild(tbody);
		_childShell.appendChild(table);
		
		if (this.type == 'horz')
		{
			tr = document.createElement("tr");
			tbody.appendChild(tr);
		}
		
		for (var i in this.children)
		{
			if (this.type == 'vert')
			{
				tr = document.createElement("tr");
				tbody.appendChild(tr);
			}
		
			childCell = this.children[i].generate();
			tr.appendChild(childCell);
		}
				
		//document.body.appendChild(this.childShell);
		if(!divTest)
		{
			divTest = document.createElement("div");
			document.body.appendChild(divTest);
		}

		divTest.appendChild(this.childShell);
			
		//iframe below each menu item so they will show over select boxes
		if (baseMenu.useIframes && ! this.isBaseItem())
		{
			var iframe = document.createElement("iframe");
			this.childIframeShell = iframe;
			iframe.style.display = "none";
			iframe.style.position = "absolute";
			iframe.border = 0;
			iframe.frameBorder = 0;
			iframe.style.border = 0;
			iframe.scrolling = "no";
			//iframe.allowTransparency = true;	//only works in IE 5.5 >, Moz 1.? > is on by default
			iframe.style.zIndex = this.level;	//iframe will be on the desired level with menu above that
			iframe.onmouseover = function(){baseMenu.onMouseOut()}
			
			divTest.appendChild(iframe);
		}
	}
	
	return this.titleObj;
}

menuItem.prototype._onmouseover = function()
{
	var baseMenu = menu.objects[this.menuId];

	//not sure what happened here...
	if (! baseMenu)
		return;
		
	/*
	second half of fix for mouseout event firing in mozilla when over actual menu item!
	if we have a previously active item, call mouseout on it as we may have stopped 
	it's only mouseout event (which was called when mouse was still over the menu item)
	only a problem in mozilla when using iframes
	*/
	if ((! baseMenu.isIE) && baseMenu.useIframes && baseMenu.activeItem)
		baseMenu.activeItem._onmouseout();
		
	if(this.expandImageOver){
		//this.titleObj.innerHTML = this.title + " <img src='" + baseMenu.expandImageOver + "' border='0'>"; //<span class='menu_pointer'>&#9658;</span>";
		this.setClass(menuItem.CLASS_OVER_EXPAND);
	}else{
		this.setClass(menuItem.CLASS_OVER);
	}
			
	clearTimeout(baseMenu.showTimer);
	clearTimeout(baseMenu.hideTimer);
	
	baseMenu.showTimer = null;
	baseMenu.hideTimer = null;
	
	baseMenu.activeItem = this;

	//#dgb 20080610 when displaying submenus greater than level 1,
	//use subMenuShowDelay if set  
	if(this.level > 1 && baseMenu.subMenuShowDelay > 0 ){
		var showDelay = baseMenu.subMenuShowDelay;
	}else{
		var showDelay = baseMenu.showDelay;
	}

	baseMenu.showTimer = setTimeout("menu.objects["+this.menuId+"].showItem()", showDelay);
	
	//#dgb 20080610
	//highlight parent
	if(baseMenu.highlightParents && this.parent){
		if(this.parent.expandImageOver){
			//this.parent.titleObj.innerHTML = this.parent.title + " <img src='" + baseMenu.expandImageOver + "' border='0'>"; //<span class='menu_pointer'>&#9658;</span>";
			this.parent.setClass(menuItem.CLASS_OVER_EXPAND);
		}else{
			this.parent.setClass(menuItem.CLASS_OVER);
		}
		if(this.parent.parent){
			if(this.parent.parent.expandImageOver){
				//this.parent.parent.titleObj.innerHTML = this.parent.parent.title + " <img src='" + baseMenu.expandImageOver + "' border='0'>"; //<span class='menu_pointer'>&#9658;</span>";
				this.parent.parent.setClass(menuItem.CLASS_OVER_EXPAND);
			}else{
				this.parent.parent.setClass(menuItem.CLASS_OVER);				
			}
			if(this.parent.parent.parent){
				if(this.parent.parent.parent.expandImageOver){
					//this.parent.parent.parent.titleObj.innerHTML = this.parent.parent.parent.title + " <img src='" + baseMenu.expandImageOver + "' border='0'>"; //<span class='menu_pointer'>&#9658;</span>";
					this.parent.parent.parent.setClass(menuItem.CLASS_OVER_EXPAND);
				}else{
					this.parent.parent.parent.setClass(menuItem.CLASS_OVER);
				}
			}
		}
	}
	
}

menuItem.prototype._onmouseout = function(event)
{
	var baseMenu = menu.objects[this.menuId];

	//not sure what happened here...
	if (! baseMenu)
		return;
		
	//first half of fix for mouseout event firing in mozilla when over actual menu item!
	//make sure mouse is not over current menu item
	//only a problem in mozilla when using iframes
	if ((! baseMenu.isIE) && baseMenu.useIframes && event && 
		event.clientX > this._offsetLeft() && 
		event.clientX < this._offsetLeft() + this.titleObj.offsetWidth &&
		event.clientY > this._offsetTop() && 
		event.clientY < this._offsetTop() + this.titleObj.offsetHeight) {
		return;
	}
	if(this.expandImageOver){
		//this.titleObj.innerHTML = this.title + " <img src='" + baseMenu.expandImage + "' border='0'>"; //<span class='menu_pointer'>&#9658;</span>";
		this.setClass(menuItem.CLASS_OUT_EXPAND);
	}else{	
		this.setClass(menuItem.CLASS_OUT);
	}
	
	clearTimeout(baseMenu.hideTimer);
	baseMenu.hideTimer = setTimeout("menu.objects["+this.menuId+"].hideAll()", baseMenu.hideDelay);
	
	//#dgb 20080610
	//un-highlight parent
	if(baseMenu.highlightParents && this.parent){
		if(this.parent.expandImageOver){
			//this.parent.titleObj.innerHTML = this.parent.title + " <img src='" + baseMenu.expandImage + "' border='0'>"; //<span class='menu_pointer'>&#9658;</span>";
			this.parent.setClass(menuItem.CLASS_OUT_EXPAND);
		}else{
			this.parent.setClass(menuItem.CLASS_OUT);
		}
		if(this.parent.parent){
			if(this.parent.parent.expandImageOver){
				//this.parent.parent.titleObj.innerHTML = this.parent.parent.title + " <img src='" + baseMenu.expandImage + "' border='0'>"; //<span class='menu_pointer'>&#9658;</span>";
				this.parent.parent.setClass(menuItem.CLASS_OUT_EXPAND);
			}else{
				this.parent.parent.setClass(menuItem.CLASS_OUT);
			}
			if(this.parent.parent.parent){
				if(this.parent.parent.parent.expandImageOver){
					//this.parent.parent.parent.titleObj.innerHTML = this.parent.parent.parent.title + " <img src='" + baseMenu.expandImage + "' border='0'>"; //<span class='menu_pointer'>&#9658;</span>";
					this.parent.parent.parent.setClass(menuItem.CLASS_OUT_EXPAND);	
				}else{
					this.parent.parent.parent.setClass(menuItem.CLASS_OUT);	
				}
			}		
		}
	}
}

menuItem.prototype._onclick = function()
{
	/*
	NOTE: linking to the same target from different browser instances will still open in the same
	window, in IE this is not true for iframes, but in Mozilla this is true for iframes which means
	that if we for example open 2 instances of web admin in Mozilla both instances will try to
	open the following url in the first window's iframe rather than their own.
	Could potentially have target as an element rather than a string an set element.location instead
	*/
	if(this.target=='javascript')
	{
		//Oooo!
		eval(this.url);
	} else if (this.url)
	{

		//#dgb 20090722 make the name of the popup definable by using popup=popupName
		if(this.target.substr(0,5)=='popup')
		{
			if(this.target.substr(0,6)=='popup='){
				var popupTarget = this.target.substr(6,this.target.length-6);
			}else{
				var popupTarget = 'PopupWindow';
			}
			PopupWindow = window.open ('', popupTarget, 'toolbar=0,location=0,resizable=1,scrollbars=1,menubar=1,height=480,width=640')
			PopupWindow.focus()
			PopupWindow.location.href = this.url
		} else
		{
			window.open(this.url, this.target);
		}
	}
}

menuItem.prototype.show = function()
{
	var baseMenu = menu.objects[this.menuId];
	
	this.setAsActive();
	
	if (this.hasChildren())
	{
		if (! this.isBaseItem() && (baseMenu.isRelative || ! this.childShell.style.left))
		{
			if(baseMenu.isRelative && this.level == 1){		
				this.childShell.style.top = (this.childShellOffsetTop() * 1 + baseMenu.top.replace(/px/g,"") * 1) + "px";
				this.childShell.style.left = (this.childShellOffsetLeft() * 1 + baseMenu.left.replace(/px/g,"") * 1) + "px";
			}else{
				this.childShell.style.left = this.childShellOffsetLeft()+"px";
				this.childShell.style.top = this.childShellOffsetTop()+"px";
			}
		}
		this.childShell.style.display = "inline-block";
		
		if (baseMenu.useIframes && ! this.isBaseItem())
		{
	 		//move the iframe behind the menu
			if (baseMenu.isRelative || ! this.childIframeShell.style.left)
			{
				this.childIframeShell.style.left = this.childShell.style.left;
				this.childIframeShell.style.top = this.childShell.style.top;
				
				this.childIframeShell.style.width = this.childShell.offsetWidth;
				this.childIframeShell.style.height = this.childShell.offsetHeight;
	
				//if we are using Moz we should also add the mouseout padding as specified
				this.childIframeShell.style.left = parseInt(this.childShell.style.left) - (baseMenu.isIE ? 0 : baseMenu.mouseOutPadding);
				this.childIframeShell.style.top = parseInt(this.childShell.style.top) - (baseMenu.isIE ? 0 : baseMenu.mouseOutPadding);
	
				this.childIframeShell.style.width = parseInt(this.childShell.offsetWidth) + (baseMenu.isIE ? 0 : baseMenu.mouseOutPadding * 2);
				this.childIframeShell.style.height = parseInt(this.childShell.offsetHeight) + (baseMenu.isIE ? 0 : baseMenu.mouseOutPadding * 2);
			}
			
			this.childIframeShell.style.display = "inline-block";
		}
	}
}

menuItem.prototype.setAsActive = function()
{
	if (this.isBaseItem())
		return;
	
	var baseMenu = menu.objects[this.menuId];
		
	this.parent.hideChildren();

	if (this.parent)
		this.parent.activeChild = this;
}

menuItem.prototype.hideChildren = function()
{
	var _activeChild;
	if (_activeChild = this.activeChild)
	{
		this.activeChild = null;
		_activeChild.hide();
		_activeChild.hideChildren();
	}
	
}

menuItem.prototype.hide = function()
{
	var baseMenu = menu.objects[this.menuId];

	if (this.childShell && this != baseMenu.activeItem)
	{
		this.childShell.style.display = "none";
		
		if (baseMenu.useIframes && ! this.isBaseItem())
			this.childIframeShell.style.display = "none";
	}
	
}

menuItem.prototype.isBaseItem = function()
{
	var baseMenu = menu.objects[this.menuId];
	
	return (baseMenu.baseItem == this);
}

menuItem.prototype.hasChildren = function()
{
	return (this.children.length > 0);
}

menuItem.prototype.setClass = function(type)
{
	if (this.isBaseItem())
		return;

	//set the style depending on class type if it exists
	switch(type)
	{
		case menuItem.CLASS_OUT:
			(this.parent) && (this.parent.styleOut) && (this.titleObj.className = this.parent.styleOut);
			break;

		case menuItem.CLASS_OVER:
			(this.parent) && (this.parent.styleOver) && (this.titleObj.className = this.parent.styleOver);
			break;

		case menuItem.CLASS_DOWN:
			(this.parent) && (this.parent.styleDown) && (this.titleObj.className = this.parent.styleDown);
			break;
		case menuItem.CLASS_OUT_EXPAND:
			(this.parent) && (this.parent.styleOutExpand) && (this.titleObj.className = this.parent.styleOutExpand);
			break;

		case menuItem.CLASS_OVER_EXPAND:
			(this.parent) && (this.parent.styleOverExpand) && (this.titleObj.className = this.parent.styleOverExpand);
			break;

		case menuItem.CLASS_DOWN_EXPAND:
			(this.parent) && (this.parent.styleDownExpand) && (this.titleObj.className = this.parent.styleDownExpand);
			break;
		default:
			break;
	}
}

menuItem.prototype.move = function(left, top)
{
	this.childShell.style.left = left ? left : 0;
	this.childShell.style.top = top ? top : 0;
//	this.childIframeShell.style.left = this.childShell.style.left;
//	this.childIframeShell.style.top = this.childShell.style.top;
}

/**
* @return integer
* @desc Gets the position of the menu item's childShell from the top of the screen
*/
menuItem.prototype.childShellOffsetTop = function()
{
	if (this.isBaseItem())
		return;

	var totalOffset = this._offsetTop();
	
	/* if parent is horizontal menu, add parent's height */
	if (this.parent.type == 'horz')
	/*dgb 20080610 add -ve subMenuVertOffset if set so that menus overlap */
	totalOffset += (this.parent.childShell.offsetHeight + this.subMenuVertOffset );
		
	return totalOffset;
}

/**
* @return integer
* @desc Gets the position of the menu item from the top of the screen
*/
menuItem.prototype._offsetTop = function()
{
	if (this.isBaseItem())
		return;

	//if menu is relative, then calc the total left offset and add
	var baseMenu = menu.objects[this.menuId];
	if(baseMenu.isRelative && this.level == 1){
		var totalOffset = findTopPos(baseMenu.baseItem.childShell)
	}else{
		var totalOffset = this.parent.childShell.offsetTop;
	}
		
	/* if parent is not horizontal menu, add current item's titleObj top offset (relative to parent) */
	if (this.parent.type != 'horz')
		totalOffset += this.titleObj.offsetTop;
	
	return totalOffset;
}

/**
* @return integer
* @desc Gets the position of the menu item's childShell from the left of the screen
*/
menuItem.prototype.childShellOffsetLeft = function()
{
	if (this.isBaseItem())
		return;

	var totalOffset = this._offsetLeft();
	
	/* if parent is vertical menu, add parent's width */
	if (this.parent.type == 'vert'){
		/*dgb 20080610 add -ve subMenuVertOffset if set so that menus overlap */
		totalOffset += (this.parent.childShell.offsetWidth + this.subMenuHorzOffset );
	}

	return totalOffset;
}

/**
* @return integer
* @desc Gets the position of the menu item from the left of the screen
*/
menuItem.prototype._offsetLeft = function()
{
	if (this.isBaseItem())
		return;

	//if menu is relative, then calc the total left offset and add
	var baseMenu = menu.objects[this.menuId];
	if(baseMenu.isRelative && this.level == 1){
		var totalOffset = findLeftPos(baseMenu.baseItem.childShell)
	}else{
		var totalOffset = this.parent.childShell.offsetLeft;
	}
	
	/* if parent is not vertical menu, add current item's titleObj left offset (relative to parent) */
	if (this.parent.type != 'vert')
		totalOffset += this.titleObj.offsetLeft;


	return totalOffset;
}

function findLeftPos(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
		} while (obj = obj.offsetParent);
		return curleft;
	}
}

function findTopPos(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		do {
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
		return curtop;
	}
}
