var menuName = 'sitemenu';
var menuTimer;

Event.observe($(menuName), "mouseover", function(event){
	var item = $(Event.element(event));
	if (!item || !item.descendantOf($(menuName))) return;
	
	clearTimeout(menuTimer);
	menuTimer = 0;
	Event.stop(event);
	
	if (item.nodeName != 'LI') item = item.up('li');
	
	var others = $$('.selected_item').findAll(function(e){
		return (!item.descendantOf(e) && e != item);
	});
	
	others.each(function(e){e.select('ul').invoke('hide')});
	others.invoke('removeClassName','selected_item');
	
	item.addClassName('selected_item');
	
	var subMenu = item.down('ul');
	if (subMenu) {
		subMenu.clonePosition(item, {offsetLeft: -229, offsetTop: 20, setWidth: false, setHeight: false});
		subMenu.setStyle({display: 'block'});
	}		
});

Event.observe(document, 'mouseover', function(event) { 
	var elt = $(Event.element(event));
	if (!elt.descendantOf($(menuName)) && $$('.selected_item').length > 0) {
		if (!menuTimer) {
			menuTimer = setTimeout(function() {
				$(menuName).select('ul').invoke('hide');
				$$('.selected_item').invoke('removeClassName', 'selected_item');
			}, 300);
		}
	}
});