// fucntions for creating a image gallery





// we may want to preload these images
function preloader(){
	var i = 0;
	if(document.images){
		var galArray = new Array();
		for(image in images){
			galArray[i] = new Image(200, 150);
			galArray[i].src = dir + images[i][0];
			i++;
		}
	}
}

	
// get a hook for the image we want to change
var viewer = null;
function init(){
	viewer = document.getElementById("viewer");
	replaceP("caption", images[0][1]);
	preloader();
}

function next(){
	if(viewIndex==images.length-1){
		viewIndex=0;
	}else{
		viewIndex++;
	}
	viewer.setAttribute("src", dir + images[viewIndex][0]);
	replaceP("caption", images[viewIndex][1]);
 	if(TOnext){
       	clearTimeout(TOnext);
    }
}

function back(){
	if(viewIndex==0){
		viewIndex=images.length-1;
	}else{
		viewIndex--;
	}
	viewer.setAttribute("src", dir + images[viewIndex][0]);
	replaceP("caption", images[viewIndex][1]);
	if(TOnext){
       	clearTimeout(TOnext);
    }
}

function replaceP(id, textitem){
	
	document.getElementById(id).innerHTML=textitem;
}

var timer = 5000;

function autoSlide(){
	if(viewIndex==images.length-1){
		viewIndex=0;
	}else{
		viewIndex++;
	}
	viewer.setAttribute("src", dir + images[viewIndex][0]);
	
	replaceP("caption", images[viewIndex][1]);
	TOnext = setTimeout('autoSlide()', timer);
}

//  for automating the slide show
TOnext = setTimeout('autoSlide()', timer);
 
 
 