// JavaScript Document

// initialize StartingPhoto
var currentPhoto = 0;

// Here come the Photos: this needs to be written by the CMS for each gallery page
var largePhoto = new Array();

// text - alttext to be displayed
// image - image source
// caption - caption beneath photo
//

// THE FUNCTIONS

function galleryOpen(photo)
{
  photo = (typeof photo == 'undefined') ? 0 : photo;

  document.getElementById('galleryFadeOut').style.visibility = 'visible';
  document.getElementById('galleryLargePhoto').style.visibility = 'visible';

  // document.getElementById('galleryPhoto').width= largePhoto[photo].width;

  document.getElementById('galleryPhoto').src = largePhoto[photo].image;
  document.getElementById('galleryPhoto').alt = largePhoto[photo].text;

  document.getElementById('galleryCaption').innerHTML = largePhoto[photo].caption;
  document.getElementById('galleryCounter').innerHTML = "Foto " + (photo + 1) + " van " + largePhoto.length;
  document.getElementById('galleryCopyright').innerHTML = largePhoto[photo].copyright;

  currentPhoto = photo;
}

function galleryClose()
{
  document.getElementById('galleryFadeOut').style.visibility = 'hidden';
  document.getElementById('galleryLargePhoto').style.visibility = 'hidden';
}

function galleryForward()
{
  currentPhoto++;

  if (currentPhoto > (largePhoto.length - 1))
  {
    if(confirm("Dit is de laatste foto van deze pagina. Wilt u terug naar de eerste foto?"))
    {
      currentPhoto = 0;
    }
    else
    {
      document.getElementById('galleryFadeOut').style.visibility = 'hidden';
      document.getElementById('galleryLargePhoto').style.visibility = 'hidden';
      return;
    }
  }

  // document.getElementById('galleryPhoto').width= largePhoto[currentPhoto].width;
  document.getElementById('galleryPhoto').src = largePhoto[currentPhoto].image;
  document.getElementById('galleryPhoto').alt = largePhoto[currentPhoto].text;

  document.getElementById('galleryCaption').innerHTML = largePhoto[currentPhoto].caption;
  document.getElementById('galleryCounter').innerHTML = "Foto " + (currentPhoto + 1) + " van " + largePhoto.length;
  document.getElementById('galleryCopyright').innerHTML = largePhoto[currentPhoto].copyright;

}

function galleryRewind()
{
  currentPhoto--;

  if (currentPhoto < 0)
  {
    if(confirm("Dit is de eerste foto van deze pagina. Wilt u verder gaan naar de laatste foto van de pagina?"))
    {
      currentPhoto = largePhoto.length - 1;
    }
    else
    {
      document.getElementById('galleryFadeOut').style.visibility = 'hidden';
      document.getElementById('galleryLargePhoto').style.visibility = 'hidden';
      return;
    }
  }

  // document.getElementById('galleryPhoto').width= largePhoto[currentPhoto].width;
  document.getElementById('galleryPhoto').src = largePhoto[currentPhoto].image;
  document.getElementById('galleryPhoto').alt = largePhoto[currentPhoto].text;

  document.getElementById('galleryCaption').innerHTML = largePhoto[currentPhoto].caption;
  document.getElementById('galleryCounter').innerHTML = "Foto " + (currentPhoto + 1) + " van " + largePhoto.length;
  document.getElementById('galleryCopyright').innerHTML = largePhoto[currentPhoto].copyright;

}

function galleryInit()
{
  if (largePhoto.length>0) {
  for(x=0;x<largePhoto.length;x++)
  {
    whichOne = "smallPhoto_" + x;
    document.getElementById(whichOne).href = "javascript:galleryOpen(" + x + ");";
  }
  }
}
