$(function(){
	$('.menu').each(function(){
		var submenu_selector = $(this).attr('jq-submenu');
		var dir = $(this).attr('jq-menu-direction') || 'bottom';

		$(this).children(':has(' + submenu_selector + ')').hover(
			function(){
				var width_ = $(this).outerWidth();
				var pos = $(this).offset();
				
				if (dir === 'bottom') {
					pos.top += $(this).outerHeight();

					$(submenu_selector, this).children().each(function(){
						$(this).width(width_);
					});
				} else
				if (dir === 'right') {
					pos.left += $(this).outerWidth();
				}

				$(submenu_selector, this).css(pos).show();
			},
			function(){
				$(submenu_selector, this).hide();
			}
		);
	});
});
