$(document).ready(function()
{
	$(function()
	{
		$("a[rel]").overlay(
		{
			expose: '#002448',
			start:
			{
				top: 0
			},
			finish:
			{
				top: 0,
				left: 'center'
			}
		});
	});

//	$("div#container").ready(function()
//	{
//		$.ajax({
//			 type: "GET",
//			 url: "/number.php?d=l",
//			 dataType: "xml",
//			 timeout: 15000,
//			 cache: false,
//			 success: function(xml)
//			 {
//				doRes(xml);
//			 },
//			 error: function(XMLHttpRequest,textStatus,errorThrown)
//			 {
//				errorHandler(textStatus);
//			 }
//		 });
//	});

	$("a.loadLink").click(function()
	{
		var loadLoc;
		loadLoc = $(this).attr("href");

		$.ajax({
			 type: "GET",
			 url: loadLoc,
			 dataType: "xml",
			 timeout: 15000,
			 cache: false,
			 success: function(xml)
			 {
				doRes(xml);
			 },
			 error: function(XMLHttpRequest,textStatus,errorThrown)
			 {
				errorHandler(textStatus);
			 }
		 });
		return false;
	});

	function doRes(data)
	{
		$(data).find("photo").each(function()
		{
			var pid = $(this).find("pid").text();
			var dir = $(this).find("dir").text();
			var prev = $(this).find("prev").text();
			var next = $(this).find("next").text();
			var name = $(this).find("alt").text();
			var height = $(this).find("height").text();
			var width = $(this).find("width").text();
			var pglnk = $(this).find("pglnk").text();
			var imgnum = $(this).find("imgnum").text();
			$("#galImg").attr("src","/photo-gallery/images/"+dir+"/"+pid+".jpg");
			$("#galImg").attr("title",name+" - Whitcliffe Mount Photo Number: "+pid);
			$("#galImg").attr("height",height);
			$("#galImg").attr("width",width);
			$("#galImgNext").attr("href","/photo-gallery/photo/?p="+next);
			$("#galPrevImg").attr("href","/photo-gallery/photo/?p="+prev);
			$("#galPrevImg").attr("title","Previous Photo");
			$("#galNextImg").attr("href","/photo-gallery/photo/?p="+next);
			$("#galNextImg").attr("title","Next Photo");
			$("#galImgStat").html(imgnum);
			$("#galInOwnTab").attr("href","/photo-gallery/photo/?p="+pid);
			$("#galInOwnTab").attr("title","Load Whitcliffe Mount Photo "+pid+" in its own Window/Tab");
		});
	}

	function errorHandler(data)
	{
		$("div#container").html("<p>An error occured while processing the request.<br /><br />Please try again shortly.</p>");
		$("div#container").append("<p>The error was: "+data+"</p>");
	}

});