$(document).ready(function() {
	
	$(".slideshow").each(function() {
	
		$(this).find("b.total").html($(this).find("ul").children().size());
		
		$(this).find("a.next").click(function() {
			
			
			// if we're at the end, hide the next link
			if($(this).parent().parent().find("li.activeImage").next("li").is(":last-child")) { 
				$(this).hide();
			} else {
				$(this).show();
			}
			
			// make sure the prev button is visible
			$(this).parent().find("a.prev").show();
			
			// display the next image, hide the current one
			$(this).parent().parent().find("li.activeImage").next("li").addClass("test");
			$(this).parent().parent().find("li.activeImage").removeClass("activeImage");
			$(this).parent().parent().find("li.test").addClass("activeImage");
			$(this).parent().parent().find("li.test").removeClass("test");
			
			$(this).parent().parent().find("b.current").html($(this).parent().parent().find("li.activeImage").prevAll().size() + 1);
			
			return false;
		});
		
		$(this).find("a.prev").click(function() {
		
			// if we're at the beginning, hide the prev link
			if($(this).parent().parent().find("li.activeImage").prev("li").is(":first-child")) {
				$(this).hide();
			} else {
				$(this).show();
			}
			
			// make sure the next link is visible
			$(this).parent().find("a.next").show();
			
			// display the prev image, hide the current one
			$(this).parent().parent().find("li.activeImage").prev("li").addClass("test");
			$(this).parent().parent().find("li.activeImage").removeClass("activeImage");
			$(this).parent().parent().find("li.test").addClass("activeImage");
			$(this).parent().parent().find("li.test").removeClass("test");
			
			$(this).parent().parent().find("b.current").html($(this).parent().parent().find("li.activeImage").prevAll().size() + 1);
			
			return false;
		});
		
		// make the first image the current one in each section
		$(this).find("li:first").addClass("activeImage");
		$(this).find("a.prev").hide();
		
	});
	
	$("#contactForm").validate();
	
});