var photoArray= [];
for (var i=1; i<totalPics+1; i++)   //leave element 0 empty   
  {
    var num = (i<10) ? "0" + i: i;
    photoArray[i]= baseFilename + num + ".jpg";
  }
var currentIndex=1;
function show(direction)
{
  if (currentIndex<totalPics && direction=="next")
    {currentIndex++;}
  else if (currentIndex>1  && direction=="previous")
    {currentIndex--;}
  else
     {currentIndex = (direction=="next") ? 1: totalPics;}
  //else currentIndex=1;  
  document.images[0].src=photoArray[currentIndex];
  var span=document.getElementById("picNumber");
  if (span) {span.innerHTML="(" + currentIndex + " of " + totalPics + ")";}
  var span=document.getElementById("caption");
  if (span)  {span.innerHTML=captionArray[currentIndex];}   
}

function checkKey(event)
{
  var e=event;
  if (e.ctrlKey || e.altKey || e.shiftKey) {return;}
  if (e.keyCode==39) {show("next")}  
  else if (e.keyCode==37) {show("previous")}
  return;        
}    
