var atimer = null;
$(document).ready(function () {
	$('#menu a').hover(function () {
		$('div.submenu').hide();
		$('#menu td').removeClass('hover');
		shHideCancel(item_id);
		
		var item_id = $(this).attr('rel');
		var width = $(this).width() + 33;
		var top = $(this).offset().top + 37;
		var left = $(this).offset().left-1;
		
		$('#sm-' + item_id).css({
			//width: width,
			top: top,
			left: left
		}).show().hover(function () {
			shHideCancel(item_id);
		}, function () {
			smHide(item_id);
		});
		if ($('#sm-' + item_id).width() < width) {
			$('#sm-' + item_id).css({
				width: width
			});
		}
	}, function () {
		smHide($(this).attr('rel'));
	});
});

function smHide(item_id)
{
	atimer = setTimeout(function () {
		$('#sm-' + item_id).hide();
		$('#menu td[rel=' + item_id + ']').removeClass('hover');
	}, 1000);
}
function shHideCancel(item_id)
{
	$('#menu td[rel=' + item_id + ']').addClass('hover');
	clearTimeout(atimer);
}
