function galleryInit() {galleryBuild();
	gallery();
}function galleryBuild(){	$('.image_def').each(function(){		var fileName = $(this).attr('imageFileName');		var imageTitle = $(this).attr('imageTitle');				var html=[];		html.push("<a href=\"");		html.push(fileName);		html.push("\"><img src=\"");		html.push(fileName);		html.push("\" alt=\"");		html.push(imageTitle);		//html.push("\" style=\"clip:rect(10px,50px,132px,10px);\"");		html.push("\"/></a>");			$(this).html(html.join(''));	});}

function gallery() {
	$('.thumb img').each(function(i) {
		var imgFile = $(this).attr('src');
		var preloadImage = new Image();
		var imgExt = /(\.\w{3,4})$/;
		preloadImage.src = imgFile.replace(imgExt,'.png');

		$(this).hover(
			function() {
			$(this).attr('src', preloadImage.src);
			},
			function () {
				var currentSource=$(this).attr('src');
				$(this).attr('src', imgFile);
			}
		); // end hover
	}); // end each
	
	function loadArtistInfo(container) {
		var imageTitle = container.attr('imageTitle');
		var imageSize = container.attr('imageSize');
		var imageMedia = container.attr('imageMedia');
		imageMedia = (imageMedia==null)? "":imageMedia;
		var imageSold = container.attr('imageSold');
		imageSold = (imageSold==null)? "":imageSold;
		$('#imageTitle').html(imageTitle);
		$('#imageSize').html(imageSize);
		$('#imageMedia').html(imageMedia);
		$('#imageSold').html(imageSold);
	}

/*
 * 		$('#imageTitle').html("");
		$('#imageSize').html("");
		$('#imageMedia').html("");
		$('#imageSold').html("");

 */
	function showStatement() {		
		$('#gallery_photo').fadeOut('slow', function(){
			$('#gallery_statement').fadeIn('slow');
		});		
	}

	$('#thumb_footer').click(function(evt) {
		//don't follow link
		evt.preventDefault();
		showStatement();
	})	
	
	$('.thumbDiv div a').click(function(evt) {
		//don't follow link
		evt.preventDefault();
		$('#gallery_statement').fadeOut('slow', function(){
			$('#gallery_photo').fadeIn('slow');
		});		

		//get path to new image
		var imgPath = $(this).attr('href');
		// Get the first element in $(this) and go up to its parent. Create a jQuery object with the parent
		var container = $($(this)[0].parentNode);
		// Expected html format will wrap $(this) in a div with attributes to be used to create content
		//get reference to old image
		loadArtistInfo(container);
		var oldImage = $('#photo img');
		//check to see if they're the same image
		//if (imgPath == oldImage.attr('src')) { 
			//if they are then you're done
		//	return;
		//} else {
			//remove highglight from previously clicked thumbnail
			$('.selectedThumb').removeClass('selectedThumb');		
			$('.selectedThumb').css('cursor','pointer');
			//add highlight to this thumbnail
			$(this).addClass('selectedThumb');
			$(this).css('cursor','arrow');
			//create HTML for new image
			var newImage = $('<img src="' + imgPath +'">');
			
			//make new image invisible
			newImage.hide();
			//add to the #photo div
			$('#photo').prepend(newImage);
			//fade out old image and remove from DOM
			oldImage.fadeOut(1000,function(){
				$(this).remove();
			});
			//fade in new image
			newImage.fadeIn(1000);	
/*
 * 
 			var w = newImage.outerWidth();
			var h = newImage.outerHeight();
			var photodiv = $('#photo');
			w = (w>500) ? w: 500;
			photodiv.animate({
				width: w,
				height: h
			},{duration:1000});
			*/
//			photodiv.width(w);
//			photodiv.height(h);
			
		//}
	}); // end click
		
	//$('.thumb a:first').click();
	$('#gallery_photo').hide();
$('#gallery_statement').show();
}
