var mainImage = new Image();
mainImage.src = "0.jpg";

var lastThumb;
function initGallery(topThumb) {
  lastThumb = topThumb;
  topThumb.className = "thumbHL";
}
// Takes the clicked thumbnail and replaces the main image with the
// full size version. Also highlights the clicked thumb.
var nThumb;
function swapMain(newThumb) {
  if (lastThumb == newThumb) {
	return;
  }

  nThumb = newThumb
  lastThumb.className = "thumbReg"; // Clear HL.

  lastThumb = newThumb;

  newThumb.className = "thumbHL";

  Effect.Fade($('mainPhoto'), {duration: .3});
  
  setTimeout('doSwap()', 600);
}

function doSwap() {
  $("mainPhoto").src = loadingReference;
  var newImageURI = nThumb.src.replace("/thumbs", "");
  $("mainPhoto").src = newImageURI;
  setTimeout("Effect.Appear($('mainPhoto'))", 500);
}