var root = 'http://www.gnivc.ru';

$(document).ready(function () {
	$('.menu_t table td a').each(function () {
		var this_url = root + $(this).attr('href');
		var current_url = document.URL;
		if (this_url == current_url) {
			$(this).addClass('active');
		}
	});
	$('.menu_t table td ul li').each(function () {
		if ($(this).find('a').hasClass('active')) { $(this).parent().parent().children('a').addClass('active'); }
	});
	$('.menu_t table td ul li a').each(function () {
		$(this).removeClass('active');
	});

	$('.menu_l ul li a').each(function () {
		var this_url = root + $(this).attr('href');
		var current_url = document.URL;
		if (this_url == current_url) {
			$(this).addClass('active');
		}
	});
	$('.menu_l ul li').each(function () {
		if ($(this).find('a').hasClass('active')) { $(this).children('a').addClass('active'); }
	});
	$('.menu_l ul li ul li a').each(function () {
		$(this).removeClass('active');
	});


	$('.menu_t table td').children('a').find('span').each(function () {
		if ($(this).height() < 20) {
			$(this).parent().css({ paddingTop: '13px', height: '26px' });
		}
	});
	$('.menu_t table td ul li').each(function () {
		$(this).has('ul').children('a').addClass('lev_i');
	});
	$('.menu_t table td ul').each(function () {
		$(this).wrap('<div class="lev_iw" />');
	});
	if ($.browser.msie) {
		$('.menu_t table td .lev_iw').each(function () {
			$(this).prepend('<!--[if lt IE 10]><div class="lev_iw_sh"></div><![endif]-->');
		});
	}
	$('.menu_t table td li:last-child').children('a').addClass('last');
	$('.menu_t table td ul').each(function () {
		var bg_offset = ($(this).parent().parent().width() / 2) - 7;
		$(this).css({ backgroundPosition: bg_offset + 'px 0px' })
	})

	$('.menu_t table td').hover(function () {
		$(this).children('a').addClass('show');
		$(this).children('.lev_iw').css({ display: 'block' });
		$(this).find('ul li .lev_iw').css({ display: 'none' });
	}, function () {
		$(this).find('.lev_iw').css({ display: 'none' });
		$(this).find('a').removeClass('show');
	});
	$('.menu_t table td ul li').hover(function () {
		$(this).children('.lev_iw').css({ display: 'block' });
	}, function () {
		$(this).find('.lev_iw').css({ display: 'none' });
	});


	$('.menu_l ul li').each(function () {
		$(this).has('ul').children('a').addClass('lev_i');
	});
	$('.menu_l ul li ul').each(function () {
		$(this).wrap('<div class="lev_iw" />');
	});
	if ($.browser.msie) {
		$('.menu_l ul li .lev_iw').each(function () {
			$(this).prepend('<!--[if lt IE 10]><div class="lev_iw_sh"></div><![endif]-->');
		});
	}
	$('.menu_l ul li:last-child').children('a').addClass('last');

	$('.menu_l ul li').hover(function () {
		$(this).find('a').addClass('show');
		$(this).find('ul li a').removeClass('show');
		$(this).children('.lev_iw').css({ display: 'block' });
		$(this).find('ul li .lev_iw').css({ display: 'none' });
	}, function () {
		$(this).find('.lev_iw').css({ display: 'none' });
		$(this).find('a').removeClass('show');
	});
	$('.menu_l ul li ul li').hover(function () {
		$(this).children('.lev_iw').css({ display: 'block' });
	}, function () {
		$(this).find('.lev_iw').css({ display: 'none' });
	});
})
