//
// preload photos
//   base is the path to the photo directory
//   n is the number of photos
//
function preloadphotos (base, n) {
  var i;
  for (i = 1; i <= n; i++) {
    if (i == 1) {
      // preload unhighlighted version of first thumbnail
      MM_preloadImages(base+'1_thumb.jpg');
    }
    else {
      // preload photo
      MM_preloadImages(base+i+'.jpg');
      // preload highlighted version of thumbnail
      MM_preloadImages(base+i+'_thumb_hi.jpg');
    }
  }
}


//
// swap photo when thumbnail is clicked
// NOTE: this code assumes x = 0 to 9
//
var lastphotoshown = 1;

function showphoto(x) {
  // check if this photo already shown
  if (x == lastphotoshown)
    return false;

  // get image objects
  var pobj = MM_findObj("projectphoto");    // get project photo
  var tobj = MM_findObj("thumbnail"+x);     // get thumbnail photo

  if (pobj && tobj) {
    // dissect image source, change digit to x, and reapply
    var src = pobj.src;
    var i = src.lastIndexOf(".jpg");
    if (i >= 0) {
      src = src.substring(0,i-1)+x+".jpg";
    }
    pobj.src = src;

    // change thumbnail to highlighted version
    src = tobj.src;
    i = src.lastIndexOf(".jpg");
    if (i >= 0) {
      src = src.substring(0,i)+"_hi.jpg";
    }
    tobj.src = src;

    // change old thumbnail to unhighlighted version
    tobj = MM_findObj("thumbnail"+lastphotoshown);
    if (tobj) {
      src = tobj.src;
      i = src.lastIndexOf("_hi.jpg");
      if (i >= 0) {
        src = src.substring(0,i)+".jpg";
      }
      tobj.src = src;
    }

    // save record of which photo is shown
    lastphotoshown = x;

    return false;
  }

  return  true;
}
