var pic = 0;

function onLoad() {
	max = 3;
	min = 1;
	i = Math.floor(Math.random() * ( max - min + 1)) + min;
	var img = document.getElementById("background_image");
	img.src = "../lib/background/" + i + ".png";

	carousel();
}

function carousel() {
	if(pic == 0) {
		pic++;
		var thumb = document.getElementById("t_" + pic);
		var hero = document.getElementById("h_" + pic);

		$(hero).fadeIn(500, function() {
			// Animation complete
		});
		$(thumb).animate({
			opacity : 1,
		}, 200, function() {
			// Animation complete.
		});
		var t = window.setTimeout("carousel()", 5000);
	} else {
		var last = document.getElementById("t_" + pic);
		var h_last = document.getElementById("h_" + pic);
		if(pic == 4) {
			pic = 0;
		}
		pic++;
		var thumb = document.getElementById("t_" + pic);
		var hero = document.getElementById("h_" + pic);

		$(h_last).fadeOut(500, function() {
			// Animation complete
			$(hero).fadeIn(500, function() {
				// Animation complete
			});
		});
		$(last).animate({
			opacity : .6,
		}, 200, function() {
			// Animation complete.
		});
		$(thumb).animate({
			opacity : 1,
		}, 200, function() {
			// Animation complete.
		});
		var t = window.setTimeout("carousel()", 5000);
	}
}
