$.fn.center = function() {
	var w=$(window);
	return this.css({
		top:(w.height()-this.height())/2+w.scrollTop(),
		left:(w.width()-this.width())/2+w.scrollLeft()
	});
}

$(function() {
	var main = $("#main");

	var preview = $("<img class='album' style='position:absolute'>")
		.hide()
		.appendTo("body");

	$("a[href$='jpg']").click(function() {
		main.addClass("loading");
		preview.attr("src",$(this).attr("href"))
			.load(function() {
				main.stop().fadeTo(200,0.5);
				preview.center().show();
				main.removeClass("loading");
			});
		return false;
	});

	$("body").click(function() {
		if( preview.is(":visible" )) {
			preview.hide();
			main.stop().fadeTo(200,1);
			return false;
		}
	});

	$(window).scroll(function(){preview.center()});
})