/*
 * GQADJPG - Greg's Quick and Dirty Javascript Photo Gallery
 */
 
self.name = "main";

current = 1; // start with the first picture
indexMaxMonza = 22; // number of photos in gallery A
indexMaxMidi = 6; // number of photos in gallery B
indexMaxPic = 3; // number of photos in gallery C
indexMax = indexMaxMonza;// number of photos in current gallery
galleryName = "Monza";

function setGallery(gallery){
	galleryName = gallery;
	if( galleryName == "Monza" )
		indexMax = indexMaxMonza;
	if( galleryName == "Keyboard" )
		indexMax = indexMaxMidi;
	if( galleryName == "Pic" )
		indexMax = indexMaxPic;
	if( current > indexMax)
		current = 1;
		
	displayPhoto(current);
}

function gotoPhoto(index){ // someone wants a specific photo
	current = index
	if (current > indexMax) // jic
		current=1;
	
	displayPhoto(current);
}

function displayPhoto(index){

	document.getElementById("photogallery").innerHTML = '<center><a href="javascript:nextPhoto()"><img id="currentphoto" src="' + galleryName + '/' + index + '-sachs.jpg" width="600" /></a></center>';
	displayThumbnails();
}

function nextPhoto(){ 
	current++;
	if (current > indexMax)
		current=1;
	
	displayPhoto(current);
}

function previousPhoto(){
	current--;
	if (current < 1)
		current=indexMax;
	
	displayPhoto(current);
}

function displayThumbnails(){
	i = 0;
	thumbHTML = "";
	while( i < indexMax){
		i++;
		if( i == current ){
			thumbHTML += '<img id="currentthumb" src="' + galleryName + 'thumbs/' + i + '-sachs.jpg" /></a>';
		} else {
			thumbHTML += '<a href="javascript:gotoPhoto(' + i + ')"><img id="photothumb" src="' + galleryName + 'thumbs/' + i + '-sachs.jpg" /></a>';
		}
		
	}
	document.getElementById("thumbnails").innerHTML = '<center>' + thumbHTML + '</center>';
}