function showLB(imageUrl) {
	if (isInt(imageUrl)) {
		pid = imageUrl;
		imageUrl = "showPhoto.php?pid=" + imageUrl + "&width=600&height=500";
	}
	else pid = null;
	
	imageUrl += "&random=" + Math.round(100*Math.random());
	
	
	$("#overlay").css('height', $(document).height());
	$("#overlay").show();
	$("#lightboxloader").fadeIn("fast");
	$("#lightboxloader").html('<div class=loader></div>');
	centerLightbox("lightboxloader");
	var img = new Image();
	$(img)
		.attr('src', imageUrl)
		.load(function() {
			$(this).attr('id', 'bigpicture');
			loadLbData(pid,this);
		})
}

function loadLbData(pid,imgobj) {	
	$("#lightbox").html('<div class="closer"><a href="javascript:closeLightbox();">close</a></div>');
	$("#lightbox").append(imgobj);
	$("#lightbox").html($("#lightbox").html() + '<div id="navi"></div>');

	$("#navi").load("includes/getLbData.php", {pid: pid}, function() {
		centerLightbox("lightbox");
		$("#lightboxloader").hide();
		$("#lightbox").fadeIn("fast");
	});
}

function closeLightbox() {
	$("#overlay").hide();
	$("#lightbox").hide();
}

function centerLightbox(whichbox) {
	var newx = $(document).scrollLeft() + $(window).width()/2 - $("#"+whichbox).outerWidth(true)/2;
	var newy = $(document).scrollTop() + $(window).height()/2 - $("#"+whichbox).outerHeight(true)/2;
	$("#"+whichbox).css('left', newx);
	$("#"+whichbox).css('top', newy);
}

$(function () {
	$("#overlay").click(function() {
		closeLightbox();
	});
});
