$(function(){
	var menubox;
	$("#menunav").find("a").hover(function(){
		var pthis = $(this);
		var oldclassname = $(this).attr('class');
		var offset = $(this).offset();
		menubox = $("#menu" + $(this).attr("rel"));
		if(menubox == null) return false;

		menubox.css({
			position:'absolute',
			top:offset.top + 32 + 'px', 
			left:offset.left + 'px'
		});
		if (menubox.css('display') != 'block')
		{
			$(".menu").hide('fast');
			menubox.show("slow");
		}
		menubox.unbind("mouseenter mouseleave");
		menubox.hover(function(){
			if($(this).css('display') != 'blick')
			{
				$(this).show();
			}
			pthis.addClass('onselected');
			menubox.find('a').unbind("mouseenter mouseleave");
			menubox.find('a').hover(function(){
				$(this).parent().parent().find("ul").hide('fast');
				if($(this).next("ul") != null)
				{
					var alinkoffset = $(this).offset();
					$(this).next("ul").css({
						position:'absolute',
						top:'-15px',
						left: menubox.width() + 'px'
					});
					$(this).next("ul").show("slow");
					$(this).next("ul").hover(function(){
					}, function(){
						$(this).hide("fast");
					});
				}
			}, function(){
				$(this).next("ul").css(top, '-15px');
				return true;
			});
		},function(){
			menubox.hide("fast");
			if(oldclassname != 'onselected')
			{
				pthis.removeClass();
			}
			return false;
		});

	},function(){
		menubox.hide();
	});
})