var ctp = 0;
var nt = 24;
function LoadFirst(){

var length = images.length;

  for (var c = 0; c < nt; c++){


		if (c < images.length){
			iname = images[c].name;
			alt = images[c].alt;
//			credit = images[c].credit;
//			description = images[c].description;

			if (!Loaded[iname]){
				Loaded[iname] = new Image();
				Loaded[iname].src = iname;
				Loaded[iname].alt = alt;
				Loaded[iname].title = alt;				
//				Loaded[iname].description = description;	
//				Loaded[iname].credit = credit;	
			}

		}
	}
}

var Loaded = new Array();

function ShowPrev(places){
// alert("In ShowPrev" + places);
	MoveThumbs('p', places);
	return(false);
}

function ShowNext(places){
// alert("In ShowNext" + places);
	MoveThumbs('n', places);
	return(false);
}


function GImage(n, a, p, d){
	this.name = n;
	this.alt = a;
	this.credit = p;
	this.description = d;
}


function MoveThumbs(dir, places){

var slot = 0;
var divid = '';
var ai;
	if (dir == 'n'){
		ctp = ctp + places;
		document.getElementById('FImgPrev').style.visibility = 'visible';
		if (ctp >= nt){
/*			document.getElementById('ThumbPrev').style.visibility = 'visible'; */
		}

	} else {
		ctp = ctp - places;
		document.getElementById('FImgNext').style.visibility = 'visible';	
		if (ctp < images.length - nt){
/*			document.getElementById('ThumbNext').style.visibility = 'visible';	*/
		}
	}
	
	if (ctp < 0){
		ctp = 0;
	}
	if (ctp >= images.length){
		ctp = images.length - 1;
	}
	
    ai = ctp;

/* Load thumbs */
    for (var c = 0; c < nt; c++){

		if (ai >= thumbimages.length){
    		slot = '<img src="Images/spacer.gif" width="56" height="56">';
    	} else {
    		tname = thumbimages[ai].name;
    		alt = images[ai].alt;
			iname = images[ai].name;
    		slot = '<img src="' + tname + '" title="' + alt + '"  alt="' + alt + '" onClick="ShowImage(\'' + iname + '\');">';    		
    	}
		dc = c + 1;
		divid = "Thumb" + dc;
//		alert(divid);
		thumbdiv = document.getElementById(divid);
		if (thumbdiv)  thumbdiv.innerHTML = slot;
    	ai++;
    }



	if (dir == 'n'){
		if (ai >= images.length){
/*			document.getElementById('ThumbNext').style.visibility = 'hidden';	 */
		}
		if (ctp >= images.length - 1){
			document.getElementById('FImgNext').style.visibility = 'hidden'; 
		 
		}
    } else {
        if (ctp <= nt){
/*			document.getElementById('ThumbPrev').style.visibility = 'hidden'; */
		}
        if (ctp <= 0){
			document.getElementById('FImgPrev').style.visibility = 'hidden'; 
		
		}
    }


    ai = ctp;
/* Preload Images */
    iname = images[ai].name;
    ShowImage(iname);
    for (var c = 0; c < nt; c++){

		if (ai < images.length){
    		iname = images[ai].name;
    		alt = images[ai].alt;
     		credit = images[ai].credit;   		
     		description = images[ai].description;   	
			if (!Loaded[iname].src){
				Loaded[iname] = new Image();
				Loaded[iname].src = iname;
				Loaded[iname].alt = alt;
				Loaded[iname].title = alt;	
				Loaded[iname].credit = credit;
				Loaded[iname].description = description;
			}
 
		}

    	ai++;
    }


}

function ShowImage(imagename){

var alt = Loaded[imagename].alt;
var credit = Loaded[imagename].credit;
var description = Loaded[imagename].description;

// alert("Alt = " + alt);
imagediv = document.getElementById('GalleryImage');
titletag = document.getElementById('ImageTitle');


 var itext = '';
//  itext = itext + '<h3>'+ alt + '</h3>';
var titletext = alt;
 itext = itext + '<img src="' + imagename + '" alt="' + alt + '" title="' + alt +'">';
 if (description){
 	itext = itext + "<p>" + description + "</p>";
 } 


 if (credit){
 	itext = itext + "<h4>Photo: " + credit + "<h4>";
 }

imagediv.innerHTML = itext;
titletag.innerHTML = titletext;

}

var timerONE = false;

function StopSlideshow(){
	if (timerONE){
		window.clearTimeout(timerONE);
	}
	document.getElementById('SlideShowControl').innerHTML = '<div onClick="Slideshow()" id="SlideShowButton">Start Slideshow</div>';
}

function Slideshow(){

	ctp = ctp + 1;
	if (ctp >= images.length){ ctp = 0; }
	var iname = images[ctp].name;  
	var alt = images[ctp].alt;  
	var credit = images[ctp].credit;  

	if (!Loaded[iname]){
		Loaded[iname] = new Image();
		Loaded[iname].src = iname;
		Loaded[iname].alt = alt;
		Loaded[iname].title = alt;	
		Loaded[iname].credit = credit;
	}
	ShowImage(iname);
	timerONE = window.setTimeout('Slideshow()',4000);
	ai = ctp + 1;
	if (ai < images.length){
		iname = images[ai].name;
		alt = images[ai].alt;
		credit = images[ai].credit;   		
		if (!Loaded[iname]){
			Loaded[iname] = new Image();
			Loaded[iname].src = iname;
			Loaded[iname].alt = alt;
			Loaded[iname].title = alt;	
			Loaded[iname].credit = credit;
		}
	}
	document.getElementById('SlideShowControl').innerHTML = '<div onClick="StopSlideshow()" id="SlideShowButton">Stop Slideshow</div>';

}

