  var currentPic = 0;

  function renderThumbs()
  {
    var htm = '<table><tr>';
    for (var i=0;i<photos.length;i++)
    {
      if (photos[i] != null) 
        htm = htm + '<td><a href="javascript:showpic(' + i + ');"><img src="' + thumbDir + '/' + photos[i] + '" class="thumbimg" /></a></td>';
      if ((i+1) % rowSize == 0)
        htm = htm + '</tr><tr>';
    }
    htm = htm + '</tr></table>';
    
    document.getElementById('divThumbs').innerHTML = htm;
  }
  
  function showpic(index)
  {
    currentPic = index;
    showArrows(index);
    
    var url = photos[index];
    var tempImg = new Image;
    tempImg.src = photoDir + '/' + url;
    swapfade(document.getElementById('img1'), photoDir + '/' + url, '1', 'Copyright (c) 2006-2009 Greg Reinacker Photography');
  }

  function showArrows(index)
  {
    if (currentPic == 0)
      document.getElementById('leftArrow').style.visibility = 'hidden';
    else
      document.getElementById('leftArrow').style.visibility = 'visible';

    var maxIndex = photos.length - 1;
    if (currentPic == maxIndex)
      document.getElementById('rightArrow').style.visibility = 'hidden';
    else
      document.getElementById('rightArrow').style.visibility = 'visible';
  }

  function showNext()
  {
    var maxIndex = photos.length - 1;
    if (currentPic < maxIndex)
    {
      currentPic = currentPic + 1;
      showpic(currentPic);
    }
  }
  
  function showPrev()
  {
    if (currentPic > 0)
    {
      currentPic--;
      showpic(currentPic);
    }
  }
  
  function init()
  {
    //document.getElementById('img1').src = photoDir + '/' + photos[0];
    document.getElementById('img1').src = '1x1black.gif';
    showpic(0);
    renderThumbs();

    //setTimeout('doCache()',1);
  }

  function doCache()
  {
    var imageCache = [];
    for(var i=0; i<photos.length; i++)
    {
 	imageCache[i] = new Image;
	imageCache[i].src = photoDir + '/' + photos[i];
    }
  }
