$(document).ready(function() {
	// Photo gallery with thumbs
	
	var currentImg = 1;
	
	var containerHeight = '400px' //$('#photoGallery img:visible').height(); <-- this wasn't working b/c the image wasn't loaded on document ready ... might have to rewrite this part
	$('#photoGallery').css('height',containerHeight);
	
	function switchImg(thisOne) {
		var thumbName = 'pic' + thisOne;
		var thumbNameImg = thumbName + 'Img';
		$('#photoGalleryThumbs img').css('border-color','#3b2b2b');
		$('#' + thumbName).css('border-color','#ffffff');
		$('#photoGallery img:visible').fadeOut(200);
		var containerHeight = $('#photoGallery #' + thumbName + 'Img').height();
		$('#photoGallery').css('height',containerHeight);
		$('#photoGallery #' + thumbName + 'Img').fadeIn(200);
		$('#photoGalleryDescriptions div:visible').hide();
		$('#' + thumbName + 'Desc').show();
	}
	
	var numImgs = $('#photoGallery img').length;
	
	$('#galleryPrev').click(function() {
		currentImg--;
		if (currentImg == 0) {
			currentImg = numImgs;
		}
		switchImg(currentImg);
		return false;
	});
	
	$('#galleryNext').click(function() {
		currentImg++;
		if (currentImg > numImgs) {
			currentImg = 1;
		}
		switchImg(currentImg);
		return false;
	});
	
	$('#photoGalleryThumbs img').click(
		function() {
			var thumbName = $(this).attr('id');
			currentImg = thumbName.substr(3);
			parseInt(currentImg);
			var thumbNameImg = thumbName + 'Img';
			var currentName = $('#photoGallery img:visible').attr('id');
			if (thumbNameImg != currentName) {
				$('#photoGalleryThumbs img').css('border-color','#3b2b2b');
				$('#' + thumbName).css('border-color','#ffffff');
				$('#photoGallery img:visible').fadeOut(200);
				var containerHeight = $('#photoGallery #' + thumbName + 'Img').height();
				$('#photoGallery').css('height',containerHeight);				
				$('#photoGallery #' + thumbName + 'Img').fadeIn(200);
				$('#photoGalleryDescriptions div:visible').hide();
				$('#' + thumbName + 'Desc').show();
			}
		},
		function() {
			var nothing = 0;
		}
	);

});
