function load_number(number){
	$.get(images[number].url, function(data){
		test = '<div id="image_and_caption">';
		inner = data.substring(data.lastIndexOf(test), data.lastIndexOf('</div>'));
		img = inner.substring(inner.lastIndexOf('<img'), inner.lastIndexOf('</a>'));
		$("#image a").html(img);
		cp_text = '<p id="caption">';
		cd_text = '<div id="caption">';
		if(inner.indexOf(cp_text)!=-1){
		    c_text = cp_text;
		    last = "</p>"
		}else{
		    c_text=cd_text;
		    last= "</div>"
		}
		caption = inner.substring(inner.lastIndexOf(c_text)+c_text.length, inner.lastIndexOf(last));
		$("#caption").html(caption);
	  	// $("#image_and_caption").html(inner);
	});
	$("#image_counter").text(number);
	
	if(number>1){
		$("#last_image").attr('href', images[number-1].url);
	}else{
		$("#last_image").attr('href', images[images.length-1].url);	
	}
	if(number<images.length-1){
		$("#next_image").attr('href', images[number+1].url);
	}else{
		$("#next_image").attr('href', images[1].url);
	}
	$("#image a").attr('href', $("#next_image").attr('href'));
	//window.location.hash = number;
	//document.location = document.location.href.substring(0,document.location.href.indexOf("#")-1)+"#"+number;
	
}
$(document).ready(function(){
	if(document.location.href.indexOf("#")!=-1){
		number = parseInt(window.location.hash.substring(1));
		load_number(number);
	}
	$("#exhibition_nav a:first-child, #next_image, #last_image, #image a").click(function(){
		number = parseInt($(this).attr('href').substring($(this).attr('href').lastIndexOf("/")+1));
		load_number(number);
		return false;
	});
});