function setLyrPos(which, x, y) {
    document.getElementById(which).style.left = x+'px';
    document.getElementById(which).style.top = y+'px';
}

function elPos(el) {
    var posx = el.offsetLeft;
    var posy = el.offsetTop;
    while (el.offsetParent != null && el.style.position != 'absolute') {
        el = el.offsetParent;
        posx += el.offsetLeft;
        posy += el.offsetTop;
    }
    if (el.style.position == 'absolute')    {
        posx -= el.offsetLeft;
        posy -= el.offsetTop;
    }
    this.x = posx;
    this.y = posy;
    return this;
}

var tmr=0;
var lastMenuId='';

function showM1(menuId, posElement) {
	if (lastMenuId != menuId)
		hideM1();
	lastMenuId = menuId;
	var pos = elPos(posElement);
	if (document.getElementById(menuId)) {
		setLyrPos(menuId, pos.x, pos.y+posElement.clientHeight);
		document.getElementById(menuId).style.visibility="visible";
		if (document.getElementById('p'+menuId)) {
			document.getElementById('p'+menuId).className='curr';
		}
		overM1();
	}
}

function overM1() {
	if (tmr) clearTimeout(tmr);
}

function outM1() {
	overM1();
	tmr = setTimeout('hideM1()', 500);
}

function hideM1() {
	overM1();
	if (document.getElementById(lastMenuId)) {
		document.getElementById(lastMenuId).style.visibility="hidden";
	}
	if (document.getElementById('p'+lastMenuId)) {
		document.getElementById('p'+lastMenuId).className='none';
	}
}
