//
// swap photos on project pages
//


//
// photo displayed (1 based)
//
var xphoto = 1;
//
// number of photos (set in projectsetup())
//
var nphotos = 1;
//
// path to photos (set in projectsetup())
//
var photopath = "";
//
// path to dummy image to fix Safari bug
//
var dummyimg = "../img/spacer.gif";

//
// set parameters
//
function projectsetup (path, n) {
  // save number of photos and path to photos
  nphotos = n;
  photopath = path;
}
//
// preload project photos
//
function projectphotopreload () {
  var i;
  // preload second, third, etc.
  for (i = 2; i <= nphotos; i++) {
    MM_preloadImages(photopath+'photo'+i+'.jpg');
  }
}


//
// show a certain photo
//
function showphoto(n) {

  // get image object
  var pobj = MM_findObj("projectphoto");

  // construct filename
  var imgfile = photopath+'photo'+n+'.jpg';

  // Safari currently has a bug - the newly loaded image will stretch to the
	// size of the previous image unless the size differs in both width and height.
	// Loading a dummy image of a different size circumvents the problem.
  if (navigator.userAgent.indexOf('Safari') != -1 ) {
    pobj.src = dummyimg;
	}
  // set src of img
  pobj.src = imgfile;


  // record which photo is displayed
  xphoto = n;

  // scroll to top of screen
	window.scrollTo(0,0);


  return false;
}


//
// show previous/next photo
//
function showpreviousphoto() {

  xphoto = (xphoto == 1 ? nphotos : --xphoto);
  showphoto(xphoto);
}
function shownextphoto() {

  xphoto = (xphoto == nphotos ? 1 : ++xphoto);
  showphoto(xphoto);
}


