/* http://jamesvec.com

   simple thumbs v1

   Written by james vecchio (jamesvec[at]gmail.com) June 2010.

   Feel free to use this on any project. 

   I would love to see what people do with it, so drop me a line

   if you use it.

   */

jQuery(document).ready (function($){	
	$("#large_images li").each(function(index, element){$(element).attr("class", 'hide');});	
	$("#large_images li").each(function(index, element){$(element).attr("id", 'img'+index);});	
	$("#thumb_holder li a").each(function(index, element){$(element).attr("rel", 'img'+index);});	
	

	var mainImg ='img0';	
	var current = 'img0';	
	

	$('#img0').addClass('current').removeClass('hide');

	// When someone clicks one of the thumbnails
	$('#thumb_holder li a').click (function(){		
		// Make sure no images are set to current						   
		
		mainImg = $(this).attr('rel');
		// If the image clicked isnt the same as the image that is already set
		if(mainImg != current){	
			$('.current').fadeOut('slow');	
			$('ul#large_images li').removeClass('current');	
			$('#'+mainImg).fadeIn('slow', function(){
				// Set the clicked image as current
				$(this).addClass('current');	
				$(this).removeClass('hide');
				$('.current').addClass('hide');						
				current = mainImg;	
			});
		}

	});

});
