$(function () {

	var set_caption_text = function (obj) {
	
		var caption_text = obj.children("span.caption").html();
	
		$("#caption_holder").html(caption_text);
	
	}

	$("#photo_gallery > li").add("#photo_gallery > li > span").hide();
	$("#photo_gallery > li:first").each(function () {
	
		$(this).show();
		set_caption_text($(this));
	
	});

	$("#photo_gallery_nav_left").css("cursor", "pointer").click(function () {
	
		var current = $("#photo_gallery > li:visible");
		
		var previous = current.prev();
		
		if (previous.length) {
		
			previous.show();
			
			set_caption_text(previous);
			
			current.hide();
		
		}
	
	});

	$("#photo_gallery_nav_right").css("cursor", "pointer").click(function () {
	
		var current = $("#photo_gallery > li:visible");
		
		var next = current.next();
		
		if (next.length) {
		
			next.show();
			
			set_caption_text(next);
			
			current.hide();
		
		}
	});
	
});
