$(function(){
	var projectImage = $("#sale-image img");
	var galleryThumbs = $("ul#gallery-thumbs li a");
	//hide the loading gif
	$('#image-loading').hide();
	galleryThumbs.each(function (i){
		$(this).bind("click", function (event){
			event.preventDefault();	
			//show the loading gif
			$('#image-loading').show();
			//get the pic ref
			var loadPic = $(this).attr("href");
			var picAlt = $(this).attr("title");	
			//reset all boxes to non selected
			resetSelected();
			//select the clicked box
			$(this).parent().addClass("selected");			
			//finaly add the image
			var objImagePreloader = new Image();
			objImagePreloader.onload = function() {				
				projectImage.attr({ 
				  src: loadPic,
				  title: picAlt,
				  alt: picAlt
				});				
				//	clear onLoad, IE behaves irratically with animated gifs otherwise
				objImagePreloader.onload=function(){};
				//hide the loading gif
				$('#image-loading').hide();
			};
			objImagePreloader.src = loadPic;
		});
	});
});
function resetSelected(){
	var galleryThumbs = $("ul#gallery-thumbs li");
	galleryThumbs.each(function (i){
		$(this).removeClass("selected");
	});
}