var images = new Array();
var titles = new Array();
var currentIndex = 1;
var total;
var imagePrefix = 'admin-resources/image-tools.php?w=652&h=391&p=1&c=0&src=';

$(document).ready(function() { 

	$('.photoSetList li').each(function() {
		titles.push($('a', $(this)).attr('title'));
		images.push($('a', $(this)).attr('href'));
	});
	
	//Get the total amount of photo's in this set, and populate
	$('#currentPhoto').html(currentIndex);
	$('#photosTotal').html(images.length); 	
	
	$('.prevBtn').click(function(e) {
		$('.photoDynamicWrapper').stop(true, true);
		e.preventDefault();
		if(currentIndex > 1) {
			// Set the index of the current photo
			currentIndex = currentIndex - 1;
			//Update the photo index in the appropriate region
			showProject(currentIndex, titles, images);
		}
	});
	
	$('.nextBtn').click(function(e) {
		$('.photoDynamicWrapper').stop(true, true);
		e.preventDefault();
		if(currentIndex < images.length) {
			// Set the index of the current photo
			currentIndex = currentIndex + 1;
			//Update the photo index in the appropriate region
			showProject(currentIndex, titles, images);
		}
	});
	
});

function showProject(index, titles, images) {
	$('#currentPhoto').html(index);
	$('.photoDynamicWrapper').animate({opacity: 0.0}, 300, "swing", function() {
		$('.photoSetCaption em').html(titles[index-1])
		$('#mainImage').css({'margin-top' : '0'})
		$('#mainImage').attr('src', imagePrefix+images[index-1])
			.load(function() {
				if($('#mainImage').height() < 391) {
					var shortImage = $('#mainImage').height()
					shortImage = 195 - (shortImage / 2);
					$('#mainImage').css({'margin-top' : shortImage})
				}
				$('.photoDynamicWrapper').animate({opacity: 1.0 }, 750, "swing")
			});
	});
}
