/**
 * Функции для сайта
 */
$(document).ready(function(){

	prettyPhotoInit();
	tabsInit();

	// Инициализация prettyPhoto
	function prettyPhotoInit(){
		$("a[rel^='prettyPhoto']").prettyPhoto({
			opacity: 0.5,
			theme: 'facebook'
		});
	}
	
	// Инициализация и работа с вкладками
	function tabsInit(){
	    $('#tabBody div[id^=tab]').hide().css("opacity", 0);
	    $('#tabBody div:first').show().css("opacity", 1);
	    $('#tabNavigation li:first').addClass("active");
	    $('#tabNavigation li a').click(function(){
			$("#tabNavigation li.active").removeClass("active");
			$(this).parent().addClass("active");
			var currentTab = $(this).attr('href');
			$("#tabBody div:visible").animate({opacity: 0}, "fast", function(){
				$("#tabBody div:visible").hide();
				$(currentTab).show();
				var currentHeight = $(currentTab).css("height");
				$(currentTab).animate({opacity: 1}, "slow");
				$("#tabBody").css("height", currentHeight);
			});
			return false;
	    });
	}

	// Курсор над ссылкой для смены языка
	$("#language").hover(function(){
		$(this).css("opacity", 1)
			   .animate({top:"0px"},"fast");
	},
	function(){
		$(this).css("opacity", 0.2)
			   .animate({top:"-20px"},"fast");
	})

	// Нажатие на кнопку изменения размера контейнера с превьюшками
	$("#thumbsContResize").live("click", function(){
		if($(this).hasClass("expanded")){
			$("#thumbsContainer").animate({height:"86px"}, "normal");
			$(this).removeClass("expanded");
		}else{
			var thumb = $(".thumbsSubContainer .thumb:first");
			var thumbHeight = parseInt(thumb.css("height")) + 2 * (parseInt(thumb.css("padding-top")) + parseInt(thumb.css("border-top-width")) + parseInt(thumb.css("margin-top")));
			var rowsNumber = 1 + Math.floor($(".thumbsSubContainer .thumb").length / 9);
			var newHeight = (rowsNumber * thumbHeight) + "px";
			$("#thumbsContainer").animate({height:newHeight}, "normal");
			$(this).addClass("expanded");
		}
	})

	// Функции для работы меню
	$("#navi ul li").hover(function(e){
		$(this).children("ul").slideDown("fast");
	},
	function(e){
		$(this).children("ul").slideUp("fast");
	})

})