/*	gallery.js v1.3 25/11/11 */
function gallery() {
  // bind function to thumbnail links
  $(".thumb a").click(function() {
	// variables for full_img, med_img, title, year, artist, artist_url, media, size, price, sold, archive, purchaser, photo
	var img = $(this).attr("rev"); // use link "rev" attribute to hold the actual image path to allow phpThumb output of med_img and full_img
	var med_img = "/resources/phpthumb/phpThumb.php?src="+img+"&w=400&aoe=1";
	var full_img = "/resources/phpthumb/phpThumb.php?src="+img+"&w=700&h=700&aoe=1";
	var title = $(this).attr("title");
	var year = $(this).children("span.year").text();
	var artist = $(this).children("span.artist").text();
	var artist_url = $(this).children("span.artist_url").text();
	var media = $(this).children("span.media").text();
	var size = $(this).children("span.size").text();
	var price = $(this).children("span.price").text()
	// if price isn't empty, prepend a pound character ready for output below
	if (price.length) {
		price = "\&pound;" + price;
	}
	var archive = $(this).children("span.archive").text()
	var purchaser = $(this).children("span.purchaser").text();
	var photo = $(this).children("span.photo").text();
	// if photo isn't empty, prepend "Photograph: " ready for output below
	if (photo.length) {
		photo = "Photograph: " + photo;
	}
	var sold = $(this).children("span.sold").text();
	// hide current image, change src and alt attributes to values passed from clicked link
	$("#med_img img").attr({style:"display:none",src:med_img,alt:title});
	// fade in image
	$("#med_img img").fadeIn();
	// change href attribute of .work (used to open full-size image in colorbox)
	$("#med_img .work").attr("href",full_img);
	// change title attribute of .work
	$("#med_img .work").attr("title",title);
	// change contents of .title
	$("#med_img .title").html(title);
	// change contents of .year
	$("#med_img .year").html(year);
	// change contents of .artist
	$("#med_img .artist").html(artist);
	// change href attribute of .artist_url
	$("#med_img .artist_url").attr("href",artist_url);
	// change contents of .media
	$("#med_img .media").html(media);
	//change contents of .size
	$("#med_img .size").html(size);
	// change contents of .price
	$("#med_img .price").html(price);
	// change contents of .sold
	$("#med_img .sold").html(sold);
	// change contents of .archive
	$("#med_img .archive").html(archive);
	// change contents of .purchaser
	$("#med_img .purchaser").html(purchaser);
	// change contents of .photo
	$("#med_img .photo").html(photo);
	// prevent browser from following clicked link
	return false;
  });
}
