$(function() {
	// разворачиваем главный пункт меню
	$('#menu > ul > li.unfold > a').click(function(){
		if ( $(this).parent().children('ul')[0] ) {
			if ( !$(this).parent().hasClass('on') ) {
				$(this).parent().parent().find('li.on').removeClass('on').children('ul').slideUp(200);
				$(this).parent().addClass('on').children('ul').slideDown(200);
			} else {
				$(this).parent().children('ul').slideUp(200, function(){
					$(this).parent().removeClass('on');
				});
			}
			return false;
		}
	});
	
	// разворачиваем вложенный пункт меню
	$("#menu > ul > li > ul > li.unfold").hover(function(){
		var foo = this;
		clearTimeout(this.timer);
		this.timer = setTimeout(function(){
			$(foo).siblings('li').children('ul:visible').hide();
			$(foo).children('ul').slideDown(200);
		}, 150);
	}, function(){
		var foo = this;
		clearTimeout(this.timer);
		this.timer = setTimeout(function(){$(foo).children('ul').slideUp(200)}, 150);
	});
	
	// сворачиваем развернутые пункты по клику за пределами меню
	$('html').click(function(){
		$('#menu > ul > li.on').removeClass('on').children('ul').slideUp(200);
	});
});

