var initialized = false;
var sourceCacheSize = 0;
var photoCacheSize = 0;
var num = -1;
var photoCache = new Array(sourceCacheSize);
var sourceCache = new Array(sourceCacheSize);
var sourceNumberCache = new Array(sourceCacheSize);

function addToSourceCache(strng)
{
  sourceCache[sourceCacheSize] = strng;
  sourceCacheSize++;
}

function addToPhotoCache(strng)
{
  photoCache[photoCacheSize] = strng;
  photoCacheSize++;
}

function setupSourceCache()
{
  addToSourceCache("http://www.kenleegallery.com/images/still/1.jpg");
  addToSourceCache("http://www.kenleegallery.com/images/still/2.jpg");
  addToSourceCache("http://www.kenleegallery.com/images/still/3.jpg");
 
 
  addToSourceCache("http://www.kenleegallery.com/images/still/6.jpg");
  addToSourceCache("http://www.kenleegallery.com/images/forum/img063.png");
  addToSourceCache("http://www.kenleegallery.com/images/forum/img003azaa.jpg");
  addToSourceCache("http://www.kenleegallery.com/images/forum/img413aba.jpg");

 

}


// Build the list completely random each time.
function initialize()
{
  var howManyDone = 0;
  var x = 0;

  setupSourceCache();

  while (howManyDone < sourceCacheSize)
  {
    // Get a random number
   x = Math.floor(Math.random() * sourceCacheSize);
   // If the number has already been used, then keep looking for another one.
   while (sourceNumberCache[x]!=undefined)
   {
    x = Math.floor(Math.random() * sourceCacheSize);
   }

  	addToPhotoCache(sourceCache[x]);
   // Mark the number as used
   sourceNumberCache[x] = "XXX"; 
   howManyDone++;
  }

}

function getNextPhoto()
{
  if (! initialized)
	{
		initialize();
		initialized = true;
	}
  num++;
  if (num >= photoCacheSize)
  {
    num = 0;
  }
  document.getElementById("myImage").src = photoCache[num];
}

function getPrevPhoto()
{
	if (! initialized)
	{
		initialize();
		initialized = true;
	}
  num--;
  if (num < 0)
  {
    num = photoCacheSize - 1;
  }
  var imgElement = document.getElementById("myImage");
  var naturalHeight = imgElement.naturalHeight;
  var naturalWidth = imgElement.naturalWidth;
  var actualHeight = imgElement.height;
  var actualWidth = imgElement.width;
  imgElement.src = photoCache[num];
}



