$(document).ready(function() {
	
	// Fade in and out loading SIC graphic
	$("#load").pulse({
		speed: 250,
		opacityRange: [0,1]
	});
	
	// Preload images
	//$("ul.grid li a").preload();
	
	$("ul.grid:eq(0)").show();
	
	$("#next").live("click", function() {
		$("ul.grid:eq(0)").hide().next("ul").fadeIn(400);
		$(this).hide();
		$("#prev").show();
	});
	
	$("#prev").live("click", function() {
		$("ul.grid:eq(1)").hide().prev("ul").fadeIn(400);
		$(this).hide();
		$("#next").show();
	});
	
	$("ul.grid li").live("click", function() {
		var b = $(this).children("a").attr("href");
		var biggie = $("<img src='" + b + "' />");
		$("#wrapper").hide();
		$("#inside").css("opacity", 0).append(biggie);
		$("#big").show();
		$("#load").show();
		$(biggie).load(function() {
			$("#load").hide();
			var imgW = $(this).width();
			var imgH = $(this).height();
			$("#inside").css({
				"margin-top" : 0 - imgH/2,
				"margin-left" : 0 - imgW/2,
				"opacity" : 1
			});
		});
		return false;
	});
	
	$("#big").live("click", function() {
		$(this).hide();
		$("#inside").empty();
		$("#wrapper").show();
	});
	
});

$(window).load(function() {
	$("#load").hide();
	$("#wrapper").fadeIn("normal");
});