var img_start = "0001";
var img_end = "0231";

function get_image_num(src) {
  // Stupid IE does not recognize using a negative offset,
  // so use the string length minus the chars to backup
  // How I hate Internet Explorer...
  return src.substr((src.length - 8),4);
}


function onclick_nav(dir) {
  var elem = document.getElementById("imagepane");
  var imgnum = get_image_num(elem.src);
  if(dir) {
    if (imgnum >= img_end) {
      return; // no change to image src on last image
    }
    imgnum++;
  } else {
    if (imgnum == img_start) {
        return; // on the first image
    }
    imgnum--;
  }
  var newimg = pad_image_name(imgnum,4);
  elem.src = "images/ifgs_" + newimg + ".JPG";
  //elem = document.getElementById("image_name");
  //elem.innerHTML = "Image file is ifgs_" + newimg + ".JPG";
}

function pad_image_name(str, len, pad) {
  if (typeof(len) == "undefined") {var len = 0; }
  if (typeof(pad) == "undefined") {var pad = "0"; }
  if (typeof(str) == "number") {var str = str+''; }
  if (len + 1 > str.length) {
    str = Array(len + 1 - str.length).join(pad) + str;
  }
  return str;
}
