function photoClick(e)
{
    var el = (e.target || e.srcElement);
	var id = (urlRewrite == "on") ? el.src.replace(/\D+/g, "") : parseUrl(el.src)["i"];
	window.open(urls["info"] + id, '_self');
	//$.get("getdetail.php", {id:pid}, photoDetail);
}

function createPreviewImage(id)
{
	$("#photoPreview").fadeOut("slow");
	$("#photoViewerClose").hide();

	var pCounter;
	var pTitle;
	var pP = $("#photoPrevious");
	var pN = $("#photoNext");
	
	pP.hide();
	pN.hide();
		
	for(var x=0; x < photos.length; x++)
	{
		if(photos[x].ID == id)
		{
			pCounter = x;
			pTitle = photos[x].Description;
			break;
		}
	}

	var pD = $("#photoDescription");
	pD.text("");
	$("#overlay").fadeIn("slow").bind("click", closeDetail);
	$("#photoViewerContainer").show();

	$("#loading").show();
	var img = new Image();
	$(img).bind("load", function()
	{
		var height = parseInt(img.height) + 20;
		var width = (parseInt(img.width) / 2) + "px";

		$("#photoViewer").animate({ height:height, width:img.width }, 1000, "swing", function()
		{
			$("#loading").hide();
			$("#photoPreview").html(img).css({width :img.width, height: img.height}).addClass("photoPreview").fadeIn("slow");
			pD.text(pTitle);
			if(pCounter < photos.length - 1)
				pN.unbind("click").bind("click", function() { createPreviewImage(photos[pCounter + 1].ID); });
			else
				pN.unbind("click").bind("click", function() { createPreviewImage(photos[0].ID); });

			pN.bind("mouseover", function() { $("#photoNextButton").show(); }).bind("mouseout", function() { $("#photoNextButton").hide(); });
			pN.css({height: img.height, width: width });
			pN.show();
			
			if(pCounter > 0)
				pP.unbind("click").bind("click", function() { createPreviewImage(photos[pCounter - 1].ID); });
			else
				pP.unbind("click").bind("click", function() { createPreviewImage(photos[photos.length - 1].ID); });

			pP.bind("mouseover", function() { $("#photoPreviousButton").show(); }).bind("mouseout", function() { $("#photoPreviousButton").hide(); });
			pP.css({height: img.height, width: width });
			pP.show();
			
			$("#photoViewerClose").show();

		});
    });
	img.src = urls["photo"] + id;
}

function closeDetail()
{
	$("#overlay").fadeOut("slow").unbind("click");
	$("#photoViewerContainer").hide();
}

function detailClick(e)
{
    var el = (e.target || e.srcElement);
	var p = (urlRewrite == "on") ? el.src.replace(/\D+/g, "") : parseUrl(el.src)["i"];
	$("#photoDescription").text("");
	createPreviewImage(p);
}
