
var galleryPhotos = gallery_gallery;

// Global values
var galleryPhoto = document.getElementById("galleryImg_gallery");
//var galleryIndex = 1;
var fadeValue = 100;
var fadeInc = 10;
var fadeDelay = 50;
var photoSwitched = false;
var photoTransitioning = true;

galleryPrev_gallery = function () {
  if (!photoTransitioning) {
    galleryIndex_gallery = (galleryIndex_gallery == 0) ? gallery_gallery.length - 1 : galleryIndex_gallery - 1;
    photoTransitioning = true;
    transitionPhoto();
  }
  return false;
}

galleryNext_gallery = function () {
  if (!photoTransitioning) {
    galleryIndex_gallery = (galleryIndex_gallery + 1) % gallery_gallery.length;
    photoTransitioning = true;
    transitionPhoto();
  }
  return false;
}

galleryJump_gallery = function (photoIndex) {
  if (!photoTransitioning) {
    galleryIndex_gallery = photoIndex;
    photoTransitioning = true;
    transitionPhoto();
  }
  return false;
}

function transitionPhoto() {
  // Fade Out
  if (!photoSwitched) {
    if (fadeValue > 0) {
      fadeValue -= fadeInc;
      setImgOpacity();
      setTimeout("transitionPhoto();",fadeDelay);
    }
    else {
      fadeValue = 0;
      photoSwitched = true;
      galleryPhoto.setAttribute("src",gallery_gallery[galleryIndex_gallery].src);
      setTimeout("transitionPhoto();",fadeDelay);
    }
  }
  // Fade In
  else {
    if (fadeValue < 100) {
      fadeValue += fadeInc;
      setImgOpacity();
      setTimeout("transitionPhoto();",fadeDelay);
    }
    else {
      fadeValue = 100;
      updateCaption_gallery();
      photoSwitched = false;
      photoTransitioning = false;
    }
  }
}

// function setImgOpacity()
if (document.all) { // IE
  setImgOpacity = function () {
    galleryPhoto.style.filter = "alpha(opacity="+fadeValue+")";
  }
}
else { // Other
  setImgOpacity = function () {
    galleryPhoto.style.opacity = fadeValue/100;
  }
}

// Allow transitions now that everything's done!
photoTransitioning = false;

// Reset the event handlers
document.getElementById('galleryPrevLink_gallery').onclick = galleryPrev_gallery;
document.getElementById('galleryNextLink_gallery').onclick = galleryNext_gallery;

