
// MENUS

	// find the screen position of the given DOM object
	// (used to position drop-down menus
	
	function findPosX(obj) {
		var curleft = 0;
		if(obj.offsetParent)
			while(1) {
				curleft += obj.offsetLeft;
				if(!obj.offsetParent)
					break;
				obj = obj.offsetParent;
			}
		else if(obj.x)
			curleft += obj.x;
		return curleft;
	}
		
	function findPosY(obj) {
		var curtop = 0;
		if(obj.offsetParent)
			while(1) {
				curtop += obj.offsetTop;
				if(!obj.offsetParent)
					break;
				obj = obj.offsetParent;
			}
		else if(obj.x)
			curtop += obj.x;
		return curtop;
	}
	
	// Show and hide the dropdown menu

	var gMenuID = '';

	function MenuLeft(pThis) {
	    xLeft = findPosX(pThis);
	    alert(pThis.offsetWidth);
	    xPaper = document.getElementById('Paper');
	    xPaperLeft = findPosX(xPaper);
	    if ((xLeft + pThis.offsetWidth) >= (xPaperLeft + xPaper.offsetWidth + 20)) {
	        xLeft = xPaperLeft + xPaper.offsetWidth + 20 - pThis.offsetWidth;
	    }
	    return xLeft;
	}

	function MenuOver(e) {
		
		// find the target of the event
		var xTarget;
		if (!e) var e = window.event;
		if (e.target) xTarget = e.target;
		else if (e.srcElement) xTarget = e.srcElement;
			
		// if the event hasn't bubbled, act on it
		if (this.id == xTarget.id) {
			if (this.nodeName == 'P') {
				if (!(gMenuID == this.id)) {
					MenuOut();
				}
				xMenuSub = document.getElementById(this.id + 's');
				xLeft = findPosX(this);
				xPaper = document.getElementById('Paper');
				xPaperLeft = findPosX(xPaper);
				if ((xLeft + xMenuSub.offsetWidth) >= (xPaperLeft + xPaper.offsetWidth + 20)) {
				    xLeft = xPaperLeft + xPaper.offsetWidth + 20 - xMenuSub.offsetWidth;
				}
				xMenuSub.style.top = (findPosY(this) + this.offsetHeight + 1) + 'px';
				xMenuSub.style.left = (xLeft - 1) + 'px';
				xMenuSub.style.visibility = 'visible';
				gMenuID = this.id;
			}
		}

		e.cancelBubble = true;
		if (e.stopPropagation) e.stopPropagation();
	
	}

	function MenuOut(e) {
		if (!(gMenuID == '')) {
			document.getElementById(gMenuID + 's').style.visibility = 'hidden';
			gMenuID = '';
		}
	}
	
	function SetMenuOver(pThis) {
	    pThis.onmouseover = MenuOver;
	}

	//	$('span.Menu').mouseover(function () {MenuOver() });

	$.each($('p.Menu'), function(index, value) { SetMenuOver(value) });
	$.each($('div.Menu'), function(index, value) { SetMenuOver(value) });
	