var images = Array();
var alts = Array();
var captions = Array();
var imageidx = 0;
var imagemax;

function galgetobj(name)
{
  var obj;
  if (document.all) {
    obj = document.all[name];
  } else if (document.layers) {
    obj = getObjNN4(document,name);
  } else {
    obj = document.getElementById(name);
  }
  return obj;
}

function galchange(n)
{
  var direction;
  var obj;

  var lastimage = imageidx;

  obj = galgetobj("galcap");
  if (n<0) {
    if (n==-1) {
      direction = 1;
    } else if (n==-2) {
      direction = -1;
    }
    imageidx += direction;
  } else {
    imageidx = n;
  }

// Below 2 lines allow next of last to roll round to beginning and vice versa
//  if (imageidx < 0) { imageidx = imagemax; }
//  if (imageidx > imagemax) { imageidx = 0; }

// Below 2 lines mean next of last doesn't move, and prev of back doesn't move.
  if (imageidx < 0) { imageidx = 0; }
  if (imageidx > imagemax) { imageidx = imagemax; }

  document.galimage.src = images[imageidx].src;
  document.galimage.alt = alts[imageidx];
  obj.innerHTML = captions[imageidx];

// If image has changed then need to review next/back button class and 
// which image button is selected
  if (lastimage!=imageidx) {
    var but;
    var cls;
    if (imageidx==0) {
      cls = "galbackdis";
    } else {
      cls = "galback";
    }
    but = galgetobj("galbback");
    but.className = cls;

    if (imageidx==imagemax) {
      cls = "galnextdis";
    } else {
      cls = "galnext";
    }
    but = galgetobj("galbnext");
    but.className = cls;

    but = galgetobj("galb" + (lastimage+1));
    but.className = "galbutton";

    but = galgetobj("galb" + (imageidx+1));
    but.className = "galbuttonsel";
  }

}
