var isDHTML = 0;
var isLayers = 0;
var isAll = 0;
var isID = 0;

if (document.getElementById) {
  isID = 1; isDHTML = 1;
} else {
  if (document.all) {
    isAll = 1; isDHTML = 1;
  } else {
    browserVersion = parseInt(navigator.appVersion);
    if ((navigator.appName.indexOf('Netscape') != -1) && (browserVersion == 4)) {
      isLayers = 1; isDHTML = 1;
    }
  }
}

function findDOM(objectID,withStyle) {
  if (withStyle == 1) {
    if (isID) {
      return (document.getElementById(objectID).style) ;
    } else { 
      if (isAll) {
        return (document.all[objectID].style); 
      } else {
        if (isLayers) {
          return (document.layers[objectID]); 
        }
      }
    }
  } else {
    if (isID) {
      return (document.getElementById(objectID)) ; 
    } else { 
      if (isAll) {
        return (document.all[objectID]); 
      } else {
        if (isLayers) {
          return (document.layers[objectID]); 
        }
      }
    }
  }
}

function nextPage() {
  if (((currentPage + 1) * 5) < picArray.length) {
    showPic((currentPage + 1) * 5);
  }
}

function previousPage() {
  if (currentPage > 0) {
    showPic((currentPage) * 5 - 1);
  }
}


function nextPic() {
  if (currentPic != (picArray.length - 1) && picArray.length > 1) {
    showPic(currentPic + 1);
  } else {
    showPic(0);  
  }
}

function previousPic() {
  if (currentPic > 0) {
    showPic(currentPic - 1);
  } else {
    showPic(picArray.length - 1);  
  }
}

function showPic (whichPic) { 
  var picIndex = currentPic % 5;
  var thumbStyle = findDOM("thumb" + picIndex, 1);
  thumbStyle.backgroundColor="#F0F0F0"; 
  if (whichPic == -1) {
    currentPic = 0;
  } else {
    currentPic = whichPic;
  }
  picIndex = currentPic % 5;
  showThumbs();

  var theImage = findDOM("theImage", 0);
  theImage.src = "../../Photos/" + picArray[currentPic];

  var theTitle = findDOM("title", 0);
  theTitle.innerHTML = titleArray[currentPic];

  var theCaption = findDOM("caption", 0);
  theCaption.innerHTML = captionArray[currentPic];

  var theCredits = findDOM("credits", 0);
  theCredits.innerHTML = photoCreditArray[currentPic];

  thumbStyle = findDOM("thumb" + picIndex, 1);
  thumbStyle.backgroundColor="#C0C0F8"; 

  return false;
}  

function showThumbs() {
  currentPage = Math.floor(currentPic / 5);
  var startPic = currentPage * 5;
  var tempHTML = "";
  var xToyOfz = findDOM("xToyOfz", 0);
  if (startPic + 5 > picArray.length - 1) {
    xToyOfz.innerHTML = (startPic + 1) + "-" + picArray.length + " of " + picArray.length;
  } else {
    xToyOfz.innerHTML = (startPic + 1) + "-" + (startPic + 5) + " of " + picArray.length;
  }
  for (var i = 0; i < 5; i++) {
    var thumb = findDOM("thumb" + i, 0);
    var thumbStyle = findDOM("thumb" + i, 1);
    thumbStyle.backgroundColor="#F0F0F0"; 
    if (startPic + i < picArray.length) {
      thumb.innerHTML = "<a onclick='javascript:return showPic(" + (startPic + i) + ")' " + 
                        "href='../../Photos/" + picArray[startPic + i] + "' " +
                        "title='" + captionArray[startPic + i] + "'>" +
                        "<img src='../../Thumbnails/" + picArray[startPic + i] + "' border='0' />" +
                        "</a>";
    } else {
      thumb.innerHTML = "<img src='../../pictures/spacer.gif' alt='' height='113' width='113' border='0'>"; 
    }                                                   
  }
}

