function animate() {
	// functions
	function px_to_int(s) {
		return s.replace('px', '');
	}
	// constants
	var RANDOM_FIX = 22;
	
	var mouseX = 0;
	var mouseY = 0;
	$().mousemove(function(e) {
		mouseX = e.pageX;
		mouseY = e.pageY;
	});

	
	var pause = false;
	var carousel_interval_id;
	var auto_scroll = function(e) {
		clearInterval(carousel_interval_id);
		carousel_interval_id = setInterval(function(ev) {
			var MOVE = 2;
			if(!pause && 
				-$(".carousel").css("margin-left").replace('px','') <
				($(".carousel table").width()-$(".carousel-container").width())) {
					$(".carousel").animate({'marginLeft': '-='+MOVE+'px'}, 0);
			}
		}, 33);
	};
	
	
	$(".carousel").hover(function(e) {
		clearInterval(carousel_interval_id);
		carousel_interval_id = setInterval(function(ev) {
			var FACTOR = 0.01;
			var DEAD_ZONE = 100;
			var offset = (mouseX - $(".carousel-container").offset().left - $(".carousel-container").width()/2);
			
			if (!pause && Math.abs(offset) > DEAD_ZONE) {
				if((offset > 0 || $(".carousel").css("margin-left").replace('px','') < 0) &&
					(offset < 0 || -$(".carousel").css("margin-left").replace('px','') <
					($(".carousel table").width()-$(".carousel-container").width()))) {
						$(".carousel").animate({'marginLeft': '-='+offset*FACTOR+'px'}, 0);	
				}
			}
			$(".carousel-title h4").hide();
			var carousel_height = $(".carousel").height();
			$(".carousel img").each(function() {
				var elt = $(this);
				var img_offset = elt.offset();
				var img_width = elt.width();
				var img_height = elt.height();
				
				if(mouseX > img_offset.left &&
					mouseY > img_offset.top &&
					mouseX < img_offset.left+img_width &&
					mouseY < img_offset.top+img_height) {
						var title_selector = "#title-"+$(this).attr('id').replace('img-','');
						title_selector = title_selector.substring(0, title_selector.length-2);
						$(title_selector).css({'left':mouseX-$(title_selector).parent().offset().left+RANDOM_FIX, 'top': carousel_height}).show();
				}
			});
		}, 33);
	}, auto_scroll);
	
	$(".carousel").hover(function() {
		if(!pause) {
			$(".carousel-title").show();
		}
	}, function() {
		$(".carousel-title").hide();
	})
	$(".carousel img").click(function() {
		$(".carousel-title").hide();
		
		pause = true;

		$(".carousel").slideUp();
		var detail_selector = "#detail-"+$(this).attr('id').replace('img-', '');
		detail_selector = detail_selector.substring(0, detail_selector.length-2);
		$(detail_selector).slideDown();
		$(".carousel-detail img").click(function() {
			$(detail_selector).slideUp();
			$(".carousel").slideDown();
			pause = false;
		});
	});
	
	var size_carousel = function() {
		$(".carousel-container").css({'width': $(window).width() - $(".carousel-container").offset().left});
	};
	
	$(window).resize(size_carousel);
	
	size_carousel();
	$(".carousel-loading").hide();
	$(".carousel").show();
	$(".carousel").animate({"marginLeft": "-=" + $(".carousel table").width()/4 +"px"}, "slow");
	auto_scroll();
}

