var NoPhotosWindow = "NoPhotosWindow";
var ThumbnailWindow = "ThumbnailWindow";
var PhotosFolder = "Photos/";
var fLandscape = "L";
var fPortrait = "P";
var imgPhotoDb = new Array();
var box = {};
var pollTimer;
var downloadAmount = "downloadAmount";
var DownloadWindow = "DownloadWindow";

function loadphotoDb(){
 for (var i=0; i<PhotoDb.length; i++){
   imgPhotoDb[i] = new Image();
   imgPhotoDb[i].src = PhotosFolder + PhotoDb[i].PhotoFileName + ".jpg";
 }
}//

function addGalleryTitle(){
 document.write(strGalleryTitle);
}//

function createBoxes(){
 box = new MultiBox('mb', {descClassName: 'multiBoxDesc', useOverlay: true});
}//

function createPhotoGalleryDisplay(){
   var strPhotoDis = "";
   document.getElementById(DownloadWindow).style.display = "none";  
   strPhotoDis += '<p class="instructions"><strong>Instructions:</strong> click a thumbnail to view a large picture and you can scroll through large pictures</p><br />';
   for (var j=0; j<PhotoDb.length; j++){
    if (PhotoDb[j].PhotoFormat == fLandscape){
   	   strPhotoDis += '<div class="figureTH"><div class="photoTH">';
 	   strPhotoDis += '<a href="#" id="mb' + (j+1) + '" class="mb" title="' + PhotoDb[j].PhotoTitle + '">';
 	   strPhotoDis += '<img id="imgmb' + (j+1) + '" src="" alt="" height="133" width="200" /></a></div>';
 	   strPhotoDis += '<div class="photoTitle">' + PhotoDb[j].PhotoTitle + '</div></div>';
   	   strPhotoDis += '<div class="multiBoxDesc mb' + (j+1) + '"></div>';  
    } else {
   	   strPhotoDis += '<div class="figureTH"><div class="photoTH_p">';
 	   strPhotoDis += '<a href="#" id="mb' + (j+1) + '" class="mb" title="' + PhotoDb[j].PhotoTitle + '">';
 	   strPhotoDis += '<img id="imgmb' + (j+1) + '" src="" alt="" height="200" width="133" /></a></div>';
 	   strPhotoDis += '<div class="photoTitle">' + PhotoDb[j].PhotoTitle + '</div></div>';
   	   strPhotoDis += '<div class="multiBoxDesc mb' + (j+1) + '"></div>';  
	}
   }
   document.getElementById(ThumbnailWindow).innerHTML = strPhotoDis;
   for (var j=0; j<PhotoDb.length; j++){
      document.getElementById("mb" + (j+1)).href = imgPhotoDb[j].src;
      document.getElementById("imgmb" + (j+1)).src = imgPhotoDb[j].src;
   }      
   createBoxes();
}//

function numberFormat(amount){
 var rawNumStr = Math.round(amount) + '';
 return rawNumStr;
}//

function pollDownLoad(){
 var NumberDownloaded = 0;
 var PercentDownloaded = 0;

 for (var i=0; i<imgPhotoDb.length; i++){
  if (imgPhotoDb[i].complete) {NumberDownloaded++;} 
 }
  PercentDownloaded = 100 * NumberDownloaded /imgPhotoDb.length;
  PercentDownloaded = numberFormat(PercentDownloaded);
  document.getElementById(downloadAmount).innerHTML = PercentDownloaded + "% downloaded";

 if (NumberDownloaded == imgPhotoDb.length){
   if (pollTimer) {clearInterval(pollTimer);}
   document.getElementById(DownloadWindow).innerHTML = "Building Gallery";
   setTimeout('createPhotoGalleryDisplay()',2000);
 }
}//


function createGallery(){
 if (PhotoDb.length == 0) {
   document.getElementById(DownloadWindow).style.display = "none";  
   document.getElementById(ThumbnailWindow).style.display = "none";  
   document.getElementById(NoPhotosWindow).style.display = "block";
   return;
 }
 loadphotoDb();
 pollTimer=setInterval("pollDownLoad()",2000);
}//