$(document).ready(function(){
	if ($(window).height() <= $("#left").height()+80 || $(window).height() <= $("#right").height()+80){
		$("#wrap").css("height",($("#left").height() <= $("#right").height())?$("#left").height()+80:$("#right").height()+80);
	};
	
	$(".carousel").each(function(){
		$(this).find(".images img:not(:eq(0))").hide();
		$(this).find(".images img:eq(0)").addClass("active");
	})
	
	$(".carousel .links .back").each(function(){
		$(this).click(function(event){
			carousel_images = $(this).parent().parent();
			if (carousel_images.find(".images img.active").prev().length){
				carousel_images.find(".images img.active").removeClass("active").fadeOut().prev().addClass("active").fadeIn();
			}
			else{
				carousel_images.find(".images img:first").removeClass("active").fadeOut();
				carousel_images.find(".images img:last").addClass("active").fadeIn();
			}
			event.preventDefault();
		});
	})
	$(".carousel .links .next").each(function(){
		$(this).click(function(event){
			carousel_images = $(this).parent().parent();
			if (carousel_images.find(".images img.active").next().length){
				carousel_images.find(".images img.active").removeClass("active").fadeOut().next().addClass("active").fadeIn();
				carousel_images.parent().find(".text .active").removeClass("active").fadeOut().next().addClass("active").fadeIn();
			}
			else{
				carousel_images.find(".images img:last").removeClass("active").fadeOut();
				carousel_images.find(".images img:first").addClass("active").fadeIn();
			}
			event.preventDefault();
		});
	})
});

$(window).resize(function(){
	if (($(window).height() <= $("#left").height()+80) || ($(window).height() <= $("#right").height()+80)){
		$("#wrap").css("height",($("#left").height() <= $("#right").height())?$("#left").height()+80:$("#right").height()+80)
	}
	else $("#wrap").css("height","100%");
});