// XMLMenuObject
function XMLMenu() {
	// Init Properties
	this.OpenMenus = new Array;

	// Methods
	this.showSubMenu = showSubMenu;
	this.hideSubMenu = hideSubMenu;
	this.show = show;
	this.hide = hide;
}


// Methods

// show: Overrideable function used to show an object
function show(DomObject) {
	// Default is to use visibility
	DomObject.style.visibility='visible';
}

// hide: Overrideable function used to hide an object
function hide(DomObject) {
	// Default is to use visibility
	DomObject.style.visibility='hidden';
}



// showSubMenu: Reveals the given submenu
function showSubMenu(pID, pParent, pbTop)
{

	// Get the menu object
	if(document.getElementById) {
		oDiv = document.getElementById(pID)
	} else {
		oDiv = document.all(pID);
	}

	// Position...
	if(pbTop == 1) {
		nLeft = pParent.offsetLeft - 6;
		nTop = pParent.offsetHeight + getRealTop(pParent) - 2;
	} else if(pbTop==2) {
		nLeft = pParent.offsetWidth + pParent.offsetLeft;
		nTop = getRealTop(pParent) - 2;
	} else {
		nLeft = pParent.offsetWidth + pParent.offsetLeft - 2;
		nTop = getRealTop2(pParent);
		


	}
	
	oDiv.style.left = nLeft;
	oDiv.style.top = nTop;
	this.show(oDiv);

	// Push it onto the array
	this.OpenMenus.push(pID);
}

// hideSubMenu: Hides all submenus or just the passed in submenu
function hideSubMenu(pMenu)
{

	if(!pMenu) {
		
		// Hide all submenus
		if(this.OpenMenus.length) {
			if(document.getElementById) {
				oMenu = document.getElementById(this.OpenMenus.pop());
			} else {
				oMenu = document.all(this.OpenMenus.pop());
			}

			this.hide(oMenu)	;

			// Recurse
			this.hideSubMenu('');
		}

	
	} else {
		if(document.getElementById) {
			oMenu = document.getElementById(this.OpenMenus.pop());
		} else {
			oMenu = document.all(this.OpenMenus.pop());
		}
		
		this.hide(oMenu);
	}

}


// getRealTop: Calculates the "real" top of the given object
function getRealTop(pObj) {
	var iPos = 0;
	var lObj = pObj;

	while(true) {
		iPos += lObj.offsetTop;
		if(lObj.offsetParent == null) break;
		
		lObj = lObj.offsetParent;
		if(lObj.offsetTop == 0) break;
	}

	return iPos;
}

function getRealTop2(pObj) {
	var iPos = 0;
	var lObj = pObj;

	while(true) {
		iPos += lObj.offsetTop;
		if(lObj.offsetParent == null) break;
		
		lObj = lObj.offsetParent;
		if(lObj.style.position == 'absolute') break;
	}

	return iPos;
}