function autohideMenu() {
	$('.menu-first').each(function () {
		if($(this).next().hasClass('opened')) {
			$(this).click();
		}
	});
}

$(document).ready(function(){
	$('.block-title h1 a').mouseover(function () {
		$(this).css(
			'text-decoration', 'none'
		);
	});
	
	document.onclick = function () {
		autohideMenu();
	}

	$('.down-list li').hover(
		function () {
			$(this).addClass('current');
		},
		function () {
			$(this).removeClass('current');
		}
	);
	
	$('.menu-first').toggle(
		function () {
			autohideMenu();
			$(this).next().slideDown(100);
			$(this).next().addClass('opened');
			//$(this).children('.down-list').slideDown(100);
			//$(this).children('.menu-first').addClass('opened');
		},
		function () {
			$(this).next().hide();
			$(this).next().removeClass('opened');
			//$(this).children('.down-list').hide();
			//$(this).children('.menu-first').removeClass('opened');
		}
	);
	
	$('.down-list li').click(function (e) {
		var select = $(this).parent().prev();
		
		select.click();
		select.text($(this).text());
		
		e.preventDefault();
		
		document.location.href = $(this).children('a').attr('href');
	});
});
