function img_setMainImage() {
   /* Replace the title bar */
   var title = document.getElementById('gallery_title');
   if (title) {
      title.innerHTML = this.title;
   }
   /* Replace the caption */
   var caption = document.getElementById('gallery_caption');
   if (caption) {
      var img = this.firstChild;
      caption.innerHTML = img.alt;
   }
   /* Replace the main image */
   var img = document.getElementById('gallery_mainimg');
   if (img) {
      img.src = this.href;
   }

   /* Unhighlight the previous image */
   document.thumbImages[document.currentImage].unHighlight();
   /* Highlight this image */
   this.showHighlight();
   /* Set it as the current image */
   document.currentImage = this.imgidx;

   return false;
}

function img_showHighlight() {
    this.firstChild.style.margin = "0";
    this.firstChild.style.border = "1px solid";
    return false;
}

function img_unHighlight() {
    this.firstChild.style.margin = "1px";
    this.firstChild.style.border = "none";
    return false;
}

function prevImage() {
  if (document.currentImage > 0) {
      document.thumbImages[document.currentImage - 1].onclick();
  }
}

function nextImage() {
  if (document.currentImage < document.thumbImages.length - 1) {
      document.thumbImages[document.currentImage + 1].onclick();
  }
}

if (document.getElementById)
{
 window.onload = function() {
   document.thumbImages = document.getElementById('gallery_thumbdiv').getElementsByTagName('a');
   document.currentImage = 0;
   for (var i = 0; i < document.thumbImages.length; i++)
   {
     document.thumbImages[i].imgidx = i;
     document.thumbImages[i].onclick = img_setMainImage;
     document.thumbImages[i].showHighlight = img_showHighlight;
     document.thumbImages[i].unHighlight = img_unHighlight;
   }
   document.thumbImages[0].showHighlight();
 }
}
