function swapPhoto(image,caption) {
   document['largePhoto'].src =  image;
   document.getElementById('imageCaption').innerHTML=caption;
   return;
}

function backNextPhoto(photos, currentPhoto, pageSize, totalPhotos, pageNumber, url) {

   var mod = currentPhoto % pageSize; 
   var backElem = document.getElementById('backHref');
   var nextElem = document.getElementById('nextHref'); 
   var tableElem = document.getElementById('backNextTable'); 
   var next = (((pageNumber - 1) * pageSize) + currentPhoto == totalPhotos) ? false : true; 
   var back = (currentPhoto == 1 && pageNumber == 1) ? false : true; 

   //alert("current photo = " + currentPhoto + "\n page size = " + pageSize + "\n total photos = " + totalPhotos + "\n mod = " 
   // + ( currentPhoto % pageSize) + "\n pagenumber = " + pageNumber + "\n url = " + url + " \n back = " + back + "\n next = " + next);

   switch(mod) {
      case 0:
         // have reached the max for the page, the next photo 
         // must be a server call for new page if this isn't the end of the photos
         if(back) {
            backElem.style.cssText =  tableElem.style.display + " text-decoration: none;";  
            backElem.setAttribute("href", "javascript:backNextPhoto( photos," + (currentPhoto - 1) + "," + pageSize + "," + totalPhotos + "," + pageNumber + ", " + '"' +  url + '"' + ")");
         }
         else {
            backElem.style.cssText =  "display: none;";  
            backElem.setAttribute("href", "");
         }

         if(next) {
            nextElem.style.cssText = tableElem.style.display + " text-decoration: none;";  
            nextElem.setAttribute("href", url + "&page=" + (pageNumber + 1));
         }
         else {
            nextElem.style.cssText = "display: none;";  
            nextElem.setAttribute("href", "");
         }
         break; 
      case 1:
         // first photo of page, next, if there is one and back which must be a server call
         if(back) {
            backElem.style.cssText =  tableElem.style.display + " text-decoration: none;";  
            backElem.setAttribute("href", url + "&page=" + (pageNumber - 1) + "&imagepos=" + pageSize);
         }
         else {
            backElem.style.cssText =  "display: none;";  
            backElem.setAttribute("href", "");
         }

         if(next) {
            nextElem.style.cssText = tableElem.style.display + " text-decoration: none;";  
            nextElem.setAttribute("href", "javascript:backNextPhoto( photos," +  (currentPhoto + 1) + "," + pageSize + "," +  totalPhotos + "," + pageNumber + ", " + '"' +  url + '"' + ")");
         }
         else {
            nextElem.style.cssText = "display: none;";  
            nextElem.setAttribute("href", "");
         } 
         break;
      default:
         // not on first or last of page, next and back buttons, if needed,
         // are not server calls 
         if(back) {
            backElem.style.cssText =  tableElem.style.display + " text-decoration: none;";  
            backElem.setAttribute("href", "javascript:backNextPhoto( photos," +  (currentPhoto - 1) + "," + pageSize + "," +  totalPhotos + "," + pageNumber + ", " + '"' + url + '"' + ")");
         }
         else {
            backElem.style.cssText =  "display: none;";  
            backElem.setAttribute("href", "");
         }
   
         if(next) {
            nextElem.style.cssText = tableElem.style.display + " text-decoration: none;";  
            nextElem.setAttribute("href", "javascript:backNextPhoto( photos," +  (currentPhoto + 1) + "," + pageSize + "," +  totalPhotos + "," + pageNumber + ", " + '"' + url + '"' + ")");
         }
         else {
            nextElem.style.cssText = "display: none;";  
            nextElem.setAttribute("href", ""); 
         } 
   }

   swapPhoto(photos[currentPhoto - 1][0], photos[currentPhoto - 1][1]);

   return; 
}




