$(document).ready(function(){
	
	// Setup slideshow
	var slideshowButtons = $("#slideshow-buttons").html();
	$("#slideshow").prepend("<div id='slideshow-buttons-wrap'></div>");
	$("#slideshow-buttons").appendTo("#slideshow-buttons-wrap");
	$("#slideshow-buttons-wrap").prepend("<ul id='slideshow-buttons-animated'></ul>");
	$("#slideshow-buttons-animated").html(slideshowButtons);
	
	// Hide slideshow buttons
	$.each($("#slideshow-buttons-animated li a"), function() {
		$(this).hide();
	});

	// Initial view on page load
	$("#slideshow-buttons-animated li:eq(0) a").show().parent().delay(500).animate({left: "302px"}, 200);
	$("#slideshow-images a img").hide();
	$("#slideshow-images a img:eq(0)").fadeIn(800);
	$("#slideshow-images #slideshow-captions p").hide();
	$("#slideshow-captions p:eq(0) a").show();
	
	// Hover over button
	if(navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod') {
		$("#slideshow-buttons li a").live('touchstart', function(event){
			var touchNum = 1;
			$("#slideshow-buttons li").live('touchstart', function(){
				touchNum + 1;	
			});
			if(touchNum = 1) {
				event.preventDefault();	
			}
			var buttonIndex = $(this).parent("li").index();
			$("#slideshow-buttons-animated li").children("a").hide().parent().stop().animate({left: "0"}, 200);
			$("#slideshow-buttons-animated li:eq(" + buttonIndex + ")").children("a").show().parent().stop().animate({left: "302px"}, 200);
			$("#slideshow-images a img:eq(" + buttonIndex + ")").fadeIn().parent().siblings().children().fadeOut();
			$("#slideshow-captions p:eq(" + buttonIndex + ") a").show().parent().siblings().children().hide();
		});
	} else {
		$("#slideshow-buttons li a").live('hover', function(){
			var buttonIndex = $(this).parent("li").index();
			$("#slideshow-buttons-animated li").children("a").hide().parent().stop().animate({left: "0"}, 200);
			$("#slideshow-buttons-animated li:eq(" + buttonIndex + ")").children("a").show().parent().stop().animate({left: "302px"}, 200);
			$("#slideshow-images a img:eq(" + buttonIndex + ")").fadeIn().parent().siblings().children().fadeOut();
			$("#slideshow-captions p:eq(" + buttonIndex + ") a").show().parent().siblings().children().hide();
		})
	}
	
	// Hover over image
	/*if(navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod') {
		$("#slideshow-images a img").click(function(){
			var imageIndex = $(this).parent("a").index();
			var imageIndexClass = imageIndex + 1;
			$("#slideshow-captions p a").removeClass();
			$("#slideshow-captions p:eq(" + imageIndex + ") a").addClass("slideshow-caption-"+imageIndexClass+"-hover");
		}, function(){
			$("#slideshow-captions p a").removeClass();
		});
	} else {
		$("#slideshow-images a img").hover(function(){
			var imageIndex = $(this).parent("a").index();
			var imageIndexClass = imageIndex + 1;
			$("#slideshow-captions p a").removeClass();
			$("#slideshow-captions p:eq(" + imageIndex + ") a").addClass("slideshow-caption-"+imageIndexClass+"-hover");
		}, function(){
			$("#slideshow-captions p a").removeClass();
		});
	}*/

});
