// Add click gallery behavior
var aGalImages = [];
var iGalIndex = 0;
(function($){
    $(function(){

// Capture the click event
        $(".gallery").bind("mousedown",function(e){
												
			// cycle through the gallery items
			$(".gallery").fadeOut("fast", function(){
				iGalIndex++;
				if (iGalIndex == aGalImages.length){
					iGalIndex = 0;
				}
				$(".gallery").html(aGalImages[iGalIndex]);
				$(".gallery img").attr("title","Click for Next Photo");
				$(".gallery").fadeIn("def");
			});
        });
		
		// Go through each image element found in the gallery and store it
		$(".gallery-icon").each(function(i){
			aGalImages.push($(this).html());
		});
		
		// Set the first image in the gallery
		if (aGalImages.length > 0){
			$(".gallery").fadeOut("slow", function(){
				$(".gallery").html(aGalImages[iGalIndex]);
				$(".gallery img").attr("title","Click for Next Photo");
				$(".gallery").fadeIn("fast");
			});
		}

		// Sticky footer
		positionFooter(); 
		function positionFooter(){
			$("#footer").css("top",$(window).scrollTop()+$(window).height()-$("#footer").height()+"px");
			$("#footer").css("visibility","visible");
		}
		$(window).scroll(positionFooter).resize(positionFooter);
		
		// Fade 'click to view additional photos' prompt
		
	});
})(jQuery);

