$(function()
{
	$("#ticks a").click(function()
	{
		loadImage(this);	
		return false;
	});
	
	$("#photoContainer").click(function()
	{
		nextImage();
	});

});

function loadImage(link)
{
	var title = $(link).attr("rel");
	var src = $(link).attr("href");
	var index = $("#ticks a").index(link) + 1;
	var count = $("#ticks a").length;
	var photoTitle = "<em>" + index + " of " + count + "</em> " + title;
	
	$("#photoTitle").html(photoTitle);
	
	$("#ticks a.current").removeClass("current");
	$(link).addClass("current");
		
	$("#photoContainer img").remove();
	
	var newImage = new Image();
	
	var random = new Date().getTime();
	
	$(newImage).attr("src", src+"?random="+random);
	
	$(newImage).load(function()
	{
		$(this).hide();
		$("#photoContainer").append(this);
		$(this).fadeIn("fast");
		
		var hgt = $(this).height();
		$("#photoContainer").height(hgt);
	});
}

function nextImage()
{
	var nextLink = $("#ticks a.current").next();
	
	if(!$(nextLink).attr("href")) nextLink = $("#ticks a").eq(0);
	
	loadImage(nextLink);
}