
(function($){

	$(document).ready(function(){
		// setup image gallery.
		$('#thumbnails ul a')
			.each(function(){
				// preload image.
				var img = new Image();
				img.src = this.href;

				// add large photo to image container.
				$('#image').append('<img src="'+ img.src +'" />');

				$(this)
					// thumbnail click handler.
					.click(function(){
						if (!$(this).hasClass('current')) {
							var thumbnailList = $(this).closest('ul');
							$('a.current', thumbnailList).removeClass('current');

							// get clicked index.
							var index = $('a', thumbnailList).index(this);

							// switch large photo.
							$(this).addClass('current');
							$('#image img')
								.hide()
								.eq(index)
									.fadeIn()
								.end()
							;
						}

						return false;
					})
				;
			})
			// show first photo.
			.eq(0)
				.trigger('click')
			.end()
		;
	});

})(jQuery);
