// fucntions for creating a slide show 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++;
		}
	}
}

var winleft = (screen.width - 360)/2;
var wintop = (screen.height - 288)/2;
var winprop = 'toolbar=0, menubar=0, scrollbars=0, resizable=0, width=360px, height=288px, left=' + winleft + ', top=' + wintop; 

// 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 jump(imagecount){
   viewIndex = imagecount;
   viewer.setAttribute("src", dir + images[viewIndex][0]);
}

function enlarge(){
   window.open(images[viewIndex][1], '', winprop);
}

function replaceP(id, textitem){
	
	var newNode = document.createElement("p");
	newNode.setAttribute("id", id);
	
	var newText = document.createTextNode(textitem);
	newNode.appendChild(newText);
	
	var oldNode = document.getElementById(id);
	var parent = document.getElementById(id).parentNode;
	
	parent.replaceChild(newNode, oldNode);
}

// 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);