function title_seo(){
	winHeight=$(window).height();
	$("#title_seo").css("padding-top", winHeight);
}

function runEffect() { 
    setTimeout('$("#sm").fadeOut();', 5000)
} 

function equalHeight(group) { //одинаковые колонки
  tallest = 0;
  group.each(function() {
    thisHeight = $(this).height();
    if(thisHeight > tallest) {
      tallest = thisHeight;
    }
  });
  group.height(tallest);
  group.find(".abs_b").height(tallest);
  group.find(".int_bl").height(tallest-8);
  heightPic=group.find(".int_bl").find("div:first").height();
  intHeigth=tallest-8;
  
  group.find(".int_bl").find(".sh_cap").css("height",intHeigth-heightPic);
}



function smartColumns() { //функция, подсчитывающая ширину колонок

  var countBl = $(".block").size();
	
	switch(countBl)
	{
	case 2:
	  widthBl=375;
	  break;
	case 3:
	case 6:
	  widthBl=219;
	  break;
	  
	case 4:
	case 8:
	  widthBl=178;
	  break; 
	  
	default:
	  widthBl=146;
	}	
  
  //сброс ширины строки до 100% после изменения размера экрана
  $("ul.column").css({ 'width' : "100%"});

  var colWrap = $("ul.column").width(); //определяем ширину строки
  var colNum = Math.floor(colWrap / widthBl); //определяем, сколько столбцов в 200px вместится в строку и округляем число до целого
  var colFixed = Math.floor(colWrap / colNum); //ширину строки делим на количество столбцов, округляем до целого числа, в результате получаем точную скорректированную ширину колонки

  $("ul.column").css({ 'width' : colWrap}); //ставим точную ширину строки в пикселях вместо использования % - это предотвратит возможные баги в разных браузерах при различных разрешениях экрана
  $("ul.column li").css({ 'width' : widthBl}); //ставим точную ширину измененным столбцам

}

$(document).ready(function() {

	equalHeight($(".bl5")); //одинаковые колонки
	equalHeight($(".bl4"));
	equalHeight($(".bl3"));
	equalHeight($(".bl2"));

	/*Слайдер*/
	//$(".menu-content").css("width", $(".menu-td").length * parseInt($(".menu-td").css("width")));
	$(".menu-td:last").find(".menu-item").css("margin-right", "0");
	$(".menu-content").css("width", $(".menu-content").find("table").width());
	var menuContWidth=$(".menu-content").width();

	if (menuContWidth>680) {
			menuOverflow=614;
			$(".viewer").css("width", menuOverflow);
			$(".menu_next").show();
			$(".menu_prev").show();
		} else {
			menuOverflow=680;
			$(".wrap_slide").remove();
			/*$(".menu_next").remove();
			$(".menu_prev").remove();*/
		}
	width_slide = ($(".menu-content").find("table").width()) - parseInt($(".viewer").css("width"));
	/**/

	smartColumns(); 
	title_seo();
	
	$(window).resize(function(){
		
		smartColumns();
		title_seo();
	});
	
		
	
	$("#show_nav").hover(function() {
		$(this).hide();
	
		$('#lmenu').animate({
			height: 'show'
		  }, {
			duration: 1000,
			specialEasing: {
			  height: 'easeOutExpo'
			}
		  });
	});
	
	$("#lmenu").hover(function() {
		$(this).show();
		
	}, function() {  
		$("#lmenu").hide(300);  
		$("#show_nav").show();
	});
	
	$("#close_af").click(function() {
		$(".bg_af").hide();
	});
	
	$(".click_af").click(function(){
		$(".bg_af").show();
	});
	
	$(".click_af_title").click(function(){
		$(".bg_af").show();

		af_id=$("#title_af_id").val();
		ns=$("#ns").val();
		//alert(af_id);
		$("#af_container").empty();
		
		$.post('/templates/inc/pop_af.php', { id: af_id, ns: ns}, function(data){
			$("#af_container").html(data);
			});
		});
		
	//$(".af_item").wrapAll('<div class="wrap_af" />');	
	
	$(".cl_af").each(function(){
		$(this).click(function(){
			doc = $(document).height();
			$(".bg_af").css("height",doc);
			$(".bg_af").show();
			af_id=$(this).find(".int_af_id").val();
			ns=$("#ns").val();
	
			$("#af_container").empty();
		
			$.post('/templates/inc/pop_af.php', { id: af_id, ns: ns}, function(data){
				$("#af_container").html(data);
				});
			});
		});
		
	$(".cl_af_sh").each(function(){
		$(this).click(function(){
			doc = $(document).height();
			$(".bg_af").css("height",doc);
			$(".bg_af").show();
			af_id=$(this).find(".int_af_id").val();
			ns=$("#ns").val();
			$("#af_container").empty();
		
			$.post('/templates/inc/pop_af.php', { id_sh: af_id, ns: ns}, function(data){
				$("#af_container").html(data);
				});
			});
		});	
		
	$(".sl_af").jCarouselLite({ //переключатель афиш
		btnNext: ".next_af",
		btnPrev: ".prev_af",
		circular: false,
		visible: 1
	});
	
	$(".next_af").click(function(){ // подсказка у афиш
		coor=$(".sl_af").find("ul").css("left");
		coor=parseInt(coor);
		coor=Math.abs(coor);
		
		
		if((coor+680)<1360)
			$("#note_af").hide();
			else
			$("#note_af").show();
	});
	
	$(".prev_af").click(function(){
		coor=$(".sl_af").find("ul").css("left");
		
		coor=parseInt(coor);
		coor=Math.abs(coor);
		
		//alert(coor-680);
		if((coor-680)<1360)
			$("#note_af").hide();
			else
			$("#note_af").show();
	});
	
	szHidden=$(".show10:hidden").size(); // скрываем показать 10 новостей
		if (szHidden==0)
			$("#sh10").hide();
	
	$("#sh10").click(function(){
		$(".show10:hidden").first().fadeIn();
		szHidden=$(".show10:hidden").size();
		if (szHidden==0)
			$(this).hide();
	});
	
	$(".viewer").find(".menu-item").each(function(){
		$(this).click(function(){
			$(".viewer").find(".menu-item").removeClass("act");
			$(this).addClass("act");
			
			var className =$(this).find("a").attr("class");
			$(".bcc").hide();
			$("."+className+"").fadeIn();
		});
	});
	

	
	$("#from").change(function(){
		otvet=$("#from option:selected").val();
		 if(otvet==1) {
			$(this).before('<input id="from" class="inp req" type="text" name="from" style="width: 306px;" />');
			$(this).remove();
		 }
	});	
	
	
	
});
