$(document).ready(function() {
	var current_photo = 1; //always display photo with DisplayOrder 1 first on load.
	photoArray = photos.split(",");
	var num_photos = photoArray.length;
	$("#next_photo").click(function() {
		if (current_photo == num_photos) {
			var new_photo_filename = photoArray[0]; //so, go back to first image
			current_photo = 1;
		} else {
			var new_photo_filename = photoArray[current_photo]; //since array are zero indexed, current_photo number associates to next photo when called in array
			current_photo++;
		}
		SetNewPhoto(new_photo_filename);
		return false;
	});
	
	$("#previous_photo").click(function() {
		if (current_photo == 1) {
			var new_photo_filename = photoArray[num_photos - 1]; //so, go to last image. Must subtract 1 from num photos due to 0 = first in array.
			current_photo = num_photos;
		} else {
			var new_photo_filename = photoArray[current_photo - 2]; //must go back 2 since current photo is always 1 higher than index, and want to go back 1.
			current_photo--;
		}
		SetNewPhoto(new_photo_filename);
		return false;
	});

	function SetNewPhoto(filename) {
		$("#current_photo").attr("src",'images/buildings/'+filename+'_m.jpg');
		$("#current_photo").attr("rel","prettyphoto");
		$(".large_photo_link").attr("href",'images/buildings/'+filename+'.jpg');
		$(".large_photo_link").attr("rel","prettyphoto");
	}
});