$(document).ready(function(){
  if ($.browser.msie && $.browser.version == "6.0") {
    $(".content").wrapInner("<div class='content-inner'><\/div>");
  }
  $(".header .menu > ul > li:last").addClass("last");
  $(".header .menu > ul > li").hover(function(){
    $(this).addClass("hovered");
    $(this).children("ul").css("min-width", $(this).width());
  }, function(){
    $(this).removeClass("hovered");
  });
  var menuWidth = 0;
  $(".header .menu > ul > li").each(function(){
    menuWidth = menuWidth + $(this).width() + 1;
  });
  $(".header .menu > ul").css("width", menuWidth);
  $("table.table tr:last").addClass("last");
  
/*  var leftHeight = $(".left.column").height();
  var rightHeight = $(".right.column").height();
  var centerHeight = $(".center").height()

  if (centerHeight < leftHeight || centerHeight < rightHeight) {
    centerHeight = (leftHeight < rightHeight) ? rightHeight: leftHeight;
    $(".center .content-text").height(centerHeight);
  }
  
  if (!$.browser.msie && $.browser.version != "6.0") {
    $(".content .column").each(function(){
      $(this).css("min-height", $(".content").height());
      $(this).width(($(".content").width() - $(".content .center").width())/2);
    });
    $(window).resize(function(){
      $(".content .column").each(function(){
          $(this).width(($(".content").width() - $(".content .center").width())/2);
        });
    });
  }
 */

  var height = $(".content").height();
  $(".content .column").each(function(){
    $(this).css("min-height", height);
    if (!$.browser.msie && $.browser.version != "6.0") {
      $(this).width(Math.round(($(".content").width() - $(".content .center").width())/2));
    } else if (($.browser.msie && parseInt($.browser.version) > 6)) {
      $(this).width(Math.round(($(".content").width() - $(".content .center").width())/2));
    }
  });
  $(window).resize(function(){
    $(".content .column").each(function(){
      if (!$.browser.msie && $.browser.version != "6.0") {
        $(this).width(Math.round(($(".content").width() - $(".content .center").width())/2));
      } else if (($.browser.msie && parseInt($.browser.version) > 6)) {
        $(this).width(Math.round(($(".content").width() - $(".content .center").width())/2));
      }
    });
  }); 


  $('a.lightbox').lightBox();
  var subsectionh = 0;
  $(".subsection").each(function(i){
	var remainder = (i + 1) % 3;
	if(remainder === 0){
		$(this).addClass("last");
	}

	if( $(this).height() > subsectionh ){
		subsectionh = $(this).height();
	}
  });

  $(".subsection").each(function(i){
		$(this).height(subsectionh);
  });

//Скрываем разделы каталога
/*  if($("li.here").length >0 ){
	$("div.item > ul").each(function(){
		$(this).hide();
  	});
  }
  
  $("li.here").parentsUntil(".item").show();

  $("div.item > div.title > a").each(function(){
  	$(this).click(function(){
		$("ul",$(this).parents(".item")).toggle(400);
	});
  });
*/

  $("div.item > ul","body.privod").each(function(){
	  $(this).hide();
  });
  $("div.item > ul","body.prom").each(function(){
	  $(this).hide();
  });
  $("div.item > ul","body.master").each(function(){
	  $(this).hide();
  });

  if($("body.privod").length > 0 ){
	$("div.privod > ul","body.privod").show();
  }
  if($("body.prom").length > 0 ){
  	$("div.prom > ul","body.prom").show();
  }
  if($("body.master").length > 0 ){
	  $("div.master > ul","body.master").show();
  }


  $("div.item > div.title > a").each(function(){
  	$(this).click(function(){
		$("ul",$(this).parents(".item")).toggle(400);
	});
  });

  if($(".subsection").length == 1){
  	$(".subsection:first").css("margin-left",200);
  }

  if($(".subsection").length == 2){
  	$(".subsection:first").css("margin-left",100);
  }
});

