jQuery(document).ready(function () {

    var timer;
    var delay = 300;
    var offset_left = 150;

	jQuery("a[id^='mm_']")
		.mouseover(function () { // при наведении на основное меню
			// узнаем id для блока подменю
			a = 'sub' + jQuery(this).attr("id");

			// закрываем все подменю
			hideAll();

			clearTimeout(timer);

			showSub(a, jQuery(this).offset(), offset_left);
		})
		.mouseout(function () { // при отведении с основного меню
			timer = setTimeout("hideSub('"+a+"')", delay);
		});

	// для подменю
	jQuery("div[id^='submm_']")
		.mouseover(function () {
			clearTimeout(timer);
		})
		.mouseout(function () {
			timer = setTimeout("hideAll()", delay);
		});
});

function showSub(a, pos, offset_left) {
	if (jQuery("div#"+a).text()) {
		jQuery("div#"+a)
			.css("top", pos.top)
			.css("left", pos.left+offset_left)
			.show();
	}
}

function hideSub(a) {
	jQuery("div#"+a).hide();
}

function hideAll() {
	jQuery("div[id^='submm_']").hide();
}

