var rmWaiting = 400;
var rmXDelta  = 0;
var rmYDelta	  = 5;

function rmShow(object) {
	var type = object.nodeName;
	//console.log('show: '+object.nodeName);
	if (type=='UL') {		
		$(object).attr({ showed: 'yes'});	
		$(object).fadeIn("normal");
		$(object).parentsUntil('#main_menu').attr({showed:'yes'});
	}
	else if (type=='A') {
		//console.log(object);
		$('#main_menu UL:visible').each(function() {
			if ($(this)!=$(object).next('UL')) $(this).attr({showed:''});
		});
		$(object).next('UL').attr({ showed: 'yes'});			
		$(object).parentsUntil('#main_menu').attr({showed:'yes'});
		
		rmHideDefinitely();
		$(object).next('UL').css({
			top: $(object).position().top + rmYDelta ,
			left: $(object).position().left + rmXDelta + $(object).width()
		});
		$(object).next('UL').fadeIn("normal");
	}
}
function rmHide(object) {
	//console.log('hide: '+object.nodeName);
	var type = object.nodeName;
	if (type=='A') $(object).next('UL').attr({ showed: ''});	
	else if (type=='UL') $(object).attr({ showed: ''});	
	setTimeout('rmHideDefinitely()', rmWaiting);
}
function rmHideDefinitely() {
	$('#main_menu UL[showed!="yes"]').fadeOut("fast");
}

function rmInit(menu_id) {
	$('#'+menu_id+' A').each(function() {
		var submenu = $(this).next('UL');
		$(submenu).hover(
			function () {
				rmShow(this);
			}, 
			function () {
				rmHide(this);
			}
		);
		if (submenu[0]) $(this).addClass('linked');
		$(submenu).css({width: $(submenu).width()*1.2});
		$(this).hover(
			function () {
				rmShow(this);
			}, 
			function () {
				rmHide(this);
			}
		);
	});
}

