
var setImage = function(oImg){
	if(!oImg.complete){
		var myPhoto = $("#myPhoto");
		if(myPhoto.attr("src") != "images/ajax-loader.gif"){
			myPhoto.attr("src", "images/ajax-loader.gif").attr("width", 43).attr("height", 11).css({marginLeft: "229px"});
		}
		window.setTimeout("setImage(oImg);", 50);
	}
	else{
		var myPhoto = $("#myPhoto");
		myPhoto.attr("src", oImg.src);
		myPhoto.attr("height", oImg.height);
		myPhoto.attr("width", oImg.width);
		myPhoto.css({marginLeft: ((470-oImg.width)/2)+"px"});
		$("#photoDesc").css({marginLeft: ((470-oImg.width)/2)+"px"}).html(oImg.alt);
	}
};

var oImg;

$(document).ready(function(){
	$("#photoList>ul>li>a").click(function(){
		oImg = new Image();
		oImg.src = $(this).attr("href");
		oImg.alt = $(this).attr("title");
		location.hash = escape($(this).attr("title").replace(" ", "+"));
		$("#photoDesc").html("");
		setImage(oImg);
		
		return false;
	});
	
	oImg = new Image();
	
	var sLocationHash = unescape(location.hash.replace("#", "").replace("+", " "));
	if(sLocationHash=="")
	{
		oImg.src = $("#photoList>ul>li>a:first").attr("href");
		oImg.alt = $("#photoList>ul>li>a:first").attr("title");
	} else{
		var imgSrc = $("#photoList>ul>li>a[title="+sLocationHash+"]").attr("href");
		if(imgSrc==undefined)
		{
			oImg.src = $("#photoList>ul>li>a:first").attr("href");
			oImg.alt = $("#photoList>ul>li>a:first").attr("title");
		}
		else{
			oImg.src = imgSrc;
			oImg.alt = $("#photoList>ul>li>a[title="+sLocationHash+"]").attr("title");
		}
	}
	setImage(oImg);
});
