$(document).ready(function(){

	$("a[rel^='prettyPhoto']").prettyPhoto({
		deeplinking: false,
		social_tools: false/* ,
		changepicturecallback: function(){
			alert();
		} */
	});

	// $("a[rel^='prettyPhoto']").each(function(){
		// var id = $(this).attr('rev');
		// var lang = $("#language > a").hasClass('english') ? '' : 'en/';
		// $(this).prettyPhoto({
			// deeplinking: false,
			// social_tools: '<div class="pp_social">' + lang + id + '</div>'
		// });
	// });
	
	
	
	$("#autoclick").click();
	$("#social-links").appendTo(".pp_pic_holder").show();
	
	// Lang button
	$("#language").hover(function(){
		$(this).css("opacity", 1)
			   .animate({top:"0px"},"fast");
	},
	function(){
		$(this).css("opacity", 0.2)
			   .animate({top:"-20px"},"fast");
	})

	// Menu sliding
	$("#navi ul li").hover(function(){
		$(this).children("ul").slideDown("fast");
	}, function(){
		$(this).children("ul").slideUp("fast");
	})

	// Posters
	function changePoster(left){
		var posterWrapper = $("#posters-wrapper");
		var postersNumber = posterWrapper.find("img").length;
		var newLeft = 0;
		if (parseInt(posterWrapper.css("left")) > (postersNumber - 1) * (-820)){
			newLeft = (left - 820);
		}
		posterWrapper.delay(6000)
					.animate({left: newLeft + "px"}, 500, function(){changePoster(newLeft)});
	}
	changePoster(0);

	// Thumbs container resize
	$("#resize-button").live("click", function(){
		var thumbsContainer = $("#thumbs-container");
		if($(this).hasClass("expanded")){
			thumbsContainer.animate({height:"86px"}, "normal");
			$(this).removeClass("expanded");
		}else{
			var thumb = thumbsContainer.find(".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(thumbsContainer.find(".thumb").length / 9);
			var newHeight = (rowsNumber * thumbHeight) + "px";
			thumbsContainer.animate({height:newHeight}, "normal");
			$(this).addClass("expanded");
		}
	})

	// Tabs handling
	function tabsInit(){
		var tabBody = $('#tab-body');
		var tabNavigation = $('#tab-navigation');
		tabBody.find('div[id^=tab]').hide().css("opacity", 0);
	    tabBody.find('div:first').show().css("opacity", 1);
	    tabNavigation.find('li:first').addClass("active");
	    tabNavigation.find('li a').click(function(){
			var currentTab = $(this).attr('href');
			$('#tab-navigation li.active').removeClass("active");
			$(this).parent().addClass("active");
			tabBody.find('div:visible').animate({opacity: 0}, "fast", function(){
				tabBody.find('div:visible').hide();
				$(currentTab).show();
				var currentHeight = $(currentTab).css("height");
				$(currentTab).animate({opacity: 1}, "slow");
				tabBody.css("height", currentHeight);
			});
			return false;
	    });
	}
	tabsInit();

	// Close button
	$(".close-button").click(function(){
		$(this).parent().fadeOut("normal");
		return false;
	})
	
})
