// Setup the photo box if it exists
if ((document.getElementById('photobox')) && (photo.length > 0))
{
  // Make the photobox visible
  document.getElementById('photobox').style.display = 'block';

  document.onload = setup();
  current = 0;
  
  // Preload the photos for the photo box
  for(var x = 0; x < photo.length; x++)
  {
    photoLoaderScaled[x] = new Image();
    photoLoaderScaled[x].src = photo[x];
    photoLoaderFull[x] = new Image();
    photoLoaderFull[x].src = link[x];
  }
}

// Setup the initial image
function setup()
{
  document.getElementById('photobox-photo').onclick = function () { overlib( '',
                                                                             WIDTH, photoLoaderFull[0].width,
                                                                             HEIGHT, photoLoaderFull[0].height,
                                                                             FGBACKGROUND, link[0],
                                                                             FGCOLOR, '',
                                                                             CAPTION, 'Photo Viewer',
                                                                             STICKY, CLOSECLICK, CENTERPOPUP, EXCLUSIVE, SHADOW, DRAGGABLE, ALTCUT); }
  document.getElementById('photobox-photo').onmouseout = nd;
  document.getElementById('photobox-photo').src = photo[0];
  document.getElementById('photobox-credit').innerHTML = credit[0];
  document.getElementById('photobox-caption').innerHTML = caption[0];
  document.getElementById('photobox').style.display='none';
  document.getElementById('photobox').style.display='block';
}


// Display the next photo
function nextPhoto()
{
  if (current < photo.length-1)
  {
    current++;
    document.getElementById('photobox-photo').onclick = function () { overlib( '',
                                                                               WIDTH, photoLoaderFull[current].width,
                                                                               HEIGHT, photoLoaderFull[current].height,
                                                                               FGBACKGROUND, link[current],
                                                                               FGCOLOR, '',
                                                                               CAPTION, 'Photo Viewer',
                                                                               STICKY, CLOSECLICK, CENTERPOPUP, EXCLUSIVE, SHADOW, DRAGGABLE, ALTCUT); }
    document.getElementById('photobox-photo').src = photo[current];
    document.getElementById('photobox-credit').innerHTML = credit[current];
    document.getElementById('photobox-caption').innerHTML = caption[current];
  }
  else
  {
    document.getElementById('photobox-photo').onclick = function () { overlib( '',
                                                                               WIDTH, photoLoaderFull[0].width,
                                                                               HEIGHT, photoLoaderFull[0].height,
                                                                               FGBACKGROUND, link[0],
                                                                               FGCOLOR, '',
                                                                               CAPTION, 'Photo Viewer',
                                                                               STICKY, CLOSECLICK, CENTERPOPUP, EXCLUSIVE, SHADOW, DRAGGABLE, ALTCUT); }
    document.getElementById('photobox-photo').src = photo[0];
    document.getElementById('photobox-credit').innerHTML = credit[0];
    document.getElementById('photobox-caption').innerHTML = caption[0];
    current = 0;
  }
}

// Display the previous photo
function prevPhoto()
{
  if (current > 0 )
  {
    current--;
    document.getElementById('photobox-photo').onclick = function () { overlib( '',
                                                                               WIDTH, photoLoaderFull[current].width,
                                                                               HEIGHT, photoLoaderFull[current].height,
                                                                               FGBACKGROUND, link[current],
                                                                               FGCOLOR, '',
                                                                               CAPTION, 'Photo Viewer',
                                                                               STICKY, CLOSECLICK, CENTERPOPUP, EXCLUSIVE, SHADOW, DRAGGABLE, ALTCUT); }

    document.getElementById('photobox-photo').src = photo[current];
    document.getElementById('photobox-credit').innerHTML = credit[current];
    document.getElementById('photobox-caption').innerHTML = caption[current];
  }
  else
  {
    document.getElementById('photobox-photo').onclick = function () { overlib( '',
                                                                               WIDTH, photoLoaderFull[photo.length-1].width,
                                                                               HEIGHT, photoLoaderFull[photo.length-1].height,
                                                                               FGBACKGROUND, link[photo.length-1],
                                                                               FGCOLOR, '',
                                                                               CAPTION, 'Photo Viewer',
                                                                               STICKY, CLOSECLICK, CENTERPOPUP, EXCLUSIVE, SHADOW, DRAGGABLE, ALTCUT); }
    document.getElementById('photobox-photo').src = photo[photo.length-1];
    document.getElementById('photobox-credit').innerHTML = credit[photo.length-1];
    document.getElementById('photobox-caption').innerHTML = caption[photo.length-1];
    current = photo.length-1
  }
}

// Display the first photo
function start()
{
  document.getElementById('photobox-photo').onclick = function () { overlib( '',
                                                                             WIDTH, photoLoaderFull[0].width,
                                                                             HEIGHT, photoLoaderFull[0].height,
                                                                             FGBACKGROUND, link[0],
                                                                             FGCOLOR, '',
                                                                             CAPTION, 'Photo Viewer',
                                                                             STICKY, CLOSECLICK, CENTERPOPUP, EXCLUSIVE, SHADOW, DRAGGABLE, ALTCUT); }
  document.getElementById('photobox-photo').src = photo[0];
  document.getElementById('photobox-credit').innerHTML = credit[0];
  document.getElementById('photobox-caption').innerHTML = caption[0];
  current = 0;
}

// Display the last photo
function end()
{
  document.getElementById('photobox-photo').onclick = function () { overlib( '',
                                                                             WIDTH, photoLoader[photo.length-1,1].width,
                                                                             HEIGHT, photoLoader[photo.length-1,1].height,
                                                                             FGBACKGROUND, link[photo.length-1],
                                                                             FGCOLOR, '',
                                                                             CAPTION, 'Photo Viewer',
                                                                             STICKY, CLOSECLICK, CENTERPOPUP, EXCLUSIVE, SHADOW, DRAGGABLE, ALTCUT); }
  document.getElementById('photobox-photo').src = photo[photo.length-1];
  document.getElementById('photobox-credit').innerHTML = credit[photo.length-1];
  document.getElementById('photobox-caption').innerHTML = caption[photo.length-1];
  current = photo.length-1
}
