function equalHeight(group) {
	tallest = 0;
	group.each(function() {
		thisHeight = $(this).height();
		$(this).addClass(""+thisHeight+"");
		if(thisHeight > tallest) {
			tallest = thisHeight;
			//alert(tallest);
		}
	});
	group.height(tallest);
}
function equalWidth(group , n_w) {
	n = (group.parent().width()-(group.parent().width()%n_w))/n_w;
	width_elem = (group.parent().width()-(group.parent().width()%n))/n;
	group.width(width_elem);
}

$(document).ready(function() {
	w=($(".main-inn .left-inn").width()/3)*2.5+50-270;
	$(".w_con").css("background-position",""+w+"px 0px");
	$(window).resize(function(){
		w=($(".main-inn .left-inn").width()/3)*2.5+50-270;
		$(".w_con").css("background-position",""+w+"px 0px");
	});//Для задания положения бэкграунда (здания ГУВД)

	$('.map').maphilight({strokeColor: 'becad5', fillColor: 'becad5', fillOpacity : 0.9});//Карта


	/*------Для разметки----*/
	i=1;
	$('#Map area').each ( function (e) {
		$(this).addClass("a"+i+"");
		i++;
		$(this).attr('title','');//Нужно для того, чтоб убрать тайтлы
	});

	i=1;
	$('.area_text table').each ( function (e) {
		$(this).addClass("a"+i+"");
		i++;
	});
	/*----------*/

	$('#Map area').hover ( function () {
		return;
	});


	$('#Map area').hover ( function () {
		m = $(this).attr('class');
		$(".area_text ."+m+"").show();
	}, function() {
		m = $(this).attr('class');
		$(".area_text ."+m+"").hide();
	});//Для всплывающих подсказок карты

	var k = false;

	$('.area_text table').hover ( function () {
		$(this).show();
	}, function() {
		$(this).hide();
	});

	$(window).resize(function () {
		equalHeight($(".news_block .news_block_elem h2"));
		equalHeight($(".news_block_elem_inn"));
		$(".personal .elem").show();
		equalWidth($(".personal .elem") , 215);
		equalHeight($(".personal .elem"));
		$(".photoalb_main .elem").show();
		equalWidth($(".photoalb_main .elem"), 215);
		equalHeight($(".photoalb_main .elem"));
		equalWidth($(".photoalb .elem"), 155);
		equalHeight($(".photoalb .elem"));
		equalWidth($(".wanted .elem"), 200);
		equalHeight($(".wanted .elem"));
		$(".select_district table td").not(".no_width").each( function () {
			m=$(this).width();
			$(this).width(m);
		});
		part_win_width=($(".map_site").width())/4;
		$(".map_site .td_left").width(part_win_width);
	});//Для рассчета длины/высоты

	a = $(".calendar-title ul li").length -1;
	if ($(".calendar-title ul li.now_year").length) {
		a = $(".calendar-title ul li.now_year").index();
	}
	if ( a < $(".calendar-title ul li").length-1) {$(".next_c").removeClass("disabled");}
	if ( a == 0 ) {$(".next_c").removeClass("disabled"); $("input.prev_c").addClass("disabled");}
	$(".calendar-title div").jCarouselLite2({
		btnNext2: ".next_c",
		btnPrev2: ".prev_c",
		speed: 400,
		circular: false,
		start:a,
		visible: 1
	});
	$(".calendar-body").jCarouselLite3({
		btnNext2: ".next_c",
		btnPrev2: ".prev_c",
		speed: 400,
		circular: false,
		start:a,
		visible: 1
	});//Календарь

	if ($("a[rel=example_group]").length) {
	$("a[rel=example_group]").fancybox({
				'cyclic'				:	true,
				'transitionIn'		: 'fade',
				'transitionOut'		: 'fade',
				'titlePosition' 	: 'over'
	});//Всплывающее окно
	}
	if ($('.select').length) {
		$("select.select").selectstyle(); //Стиль для селектов
	}
	$(".select_district table td").not(".no_width").each( function () {
		m=$(this).width();
		$(this).width(m);
	});

	$(".text-inn table tr:nth-child(odd)").addClass("second");
	$(".text-inn table tr:last-child").addClass("last-tr");
	$(".text-inn table tr").each(function() {
		$(this).children("td:last").addClass("last_td");
		if (($(this).children("td").length > $(this).next().children("td").length) && (!$(this).hasClass("last-tr")))
		{
			$(this).addClass("tr-dif");
			$(this).next().addClass("tr-dif-next");
		}
	});
	$(".text-inn table:not('.no-header') tr:first-child").addClass("table-head");//Для оформления таблиц

	part_win_width=($(".map_site").width())/4;
	$(".map_site .td_left").width(part_win_width);

	$(".text-inn img").parent("p").css("display" , "block").append("<hr/>");

	$(".text-inn a[href$='.doc']").addClass("url_file doc").parent("p").css("margin-bottom","0px");
	$(".text-inn a[href$='.rtf']").addClass("url_file doc").parent("p").css("margin-bottom","0px");
	$(".text-inn a[href$='.xls']").addClass("url_file exel").parent("p").css("margin-bottom","0px");

	if ($.browser.msie && $.browser.version == 6) {
		DD_belatedPNG.fix('.main');
	}
	if ($.browser.msie && ($.browser.version == 6 || $.browser.version == 7)) {
		$(".text-inn ol li").wrapInner($("<div class='ie_ol'></div>"));
	}


	$(".navig_menu .elem").bind("mouseenter",function(){
		$(this).children(".up_menu_cont").fadeIn(100);
		$(this).children("a").addClass("hovered_menu");
    }).bind("mouseleave",function(){
		$(this).children(".up_menu_cont").fadeOut(100);
		$(this).children("a").removeClass("hovered_menu");
    });//Всплывающее меню

	/*$(".content-inn img").not(".content-inn div img , .content-inn table img ").each(function() {
		$(this).unwrap("*").addClass("inn_img_1");
	});   */

});
$(window).load(function () {
equalHeight($(".news_block .news_block_elem h2"));
equalHeight($(".news_block_elem_inn"));
$(".personal .elem").show();
equalWidth($(".personal .elem") , 215);
equalHeight($(".personal .elem"));
$(".photoalb_main .elem").show();
equalWidth($(".photoalb_main .elem"), 215);
equalHeight($(".photoalb_main .elem"));
$(".photoalb .elem").show();
equalWidth($(".photoalb .elem"), 155);
equalHeight($(".photoalb .elem"));
$(".wanted .elem").show();
equalWidth($(".wanted .elem"), 200);
equalHeight($(".wanted .elem"));
});//Для рассчета длины/высоты
