var Menu = {
	timer : null,
	currentSubMenu : null,
	
	init : function() {
		$(function() {
			Menu._init_();
		});
	},
	_init_: function() {
		$("#mainMenu ul li a").each(function(index) {
			var obj = $(this);
			var subMenuName = obj.attr('rel');
			
			if (($.browser.mozilla) && (navigator.userAgent.toLowerCase().match(/mac/))) {
				if (parseInt($(obj).parent().css('padding-right')) > 0) 
					$(obj).parent().css({paddingRight:18});
				else 
					$(obj).parent().css({paddingLeft:18});
			}
			
			if ($(this).attr('href') == '#') {
				$(this).css({cursor: 'text'}).click(function() {return false;});
			}
			if (subMenuName != '') {
				obj.parent().mouseenter(function() {
					obj.stopTime('hidemenu');
					
					Menu.currentSubMenu = $('#' + subMenuName);
					
					$(Menu.currentSubMenu).css({display: 'block'})
				});
				
				obj.parent().mouseleave(function() {
					$('#' + subMenuName).mouseenter(function() {
						obj.stopTime('hidemenu');
						
						$(this).unbind('mouseenter');
						
						$(this).mouseleave(function() {
							Menu.timer = obj.oneTime(400,'hidemenu',function() {
								$('#' + subMenuName).css({display: 'none'})
							});
						});
					});
					
					Menu.timer = obj.oneTime(200,'hidemenu',function() {
						$('#' + subMenuName).css({display: 'none'})
					});
				});
			}
		});
	},
	
	hideSubMenu : function() {
		$(Menu.currentSubMenu).css({display: 'none'})
	}
}

Menu.init();
