var gMenuTimer=-1;

function initMenu()
{
	var enhancements = {
		'#menubar a' : function(p) {
			p.onmouseover = function() { showSubmenu(this); overAnchor(this); }
			p.onmouseout = function() { outAnchor(this); }
		},
		'.submenu a' : function(p) {
			p.onmouseover = function() { overAnchor(this); }
			p.onmouseout = function() { outAnchor(this); }
		}
	};
	
	Behaviour.register(enhancements);
}
function getPosition(obj) {
	var pos = { x:0, y:0 };
	
	do {
		pos.x += obj.offsetLeft;
		pos.y += obj.offsetTop;
	} while(obj = obj.offsetParent);
	
	return pos;
}
function showSubmenu(pAnchor) {
	var submenu_name = pAnchor.getAttribute('rel');
	var submenu = document.getElementById(submenu_name);
	//var pos = getPosition(pAnchor);
	
	hideAllSubmenus();
	
	submenu.style.display = 'block';
	
	//submenu.style.left = pos.x+'px';
	//submenu.style.top = pos.y+pAnchor.offsetHeight+'px';

	submenu.style.left = pAnchor.offsetLeft+'px';
	submenu.style.top = pAnchor.offsetTop+pAnchor.offsetHeight+'px';
}
function hideSubmenu(pSubmenu) {
	pSubmenu.style.display = 'none';
}
function overAnchor(pAnchor) {
	if(gMenuTimer != -1) {
		clearTimeout(gMenuTimer);
	}
}
function outAnchor(pAnchor) {
	gMenuTimer = setTimeout("hideAllSubmenus()", 750);
}
function hideAllSubmenus() {
	var divs = document.getElementsByTagName('div');
	var p;
	var i;
	for(i=0; i<divs.length; i++) {
		p = divs[i];
		if(p.className == 'submenu') {
			hideSubmenu(p);
		}
	}
}

initMenu();
