window.onload=initGallery;
var pictures = "pictures";

var dirs = new Array("bonfire","duckraces","labyrinth","main","campsite");

//Counter to keep track of current pic to display
var currentPic = 0;
//Vars to keep track of picture categories
var bonfire = 0;
var duckraces = 1;
var labyrinth = 2;
var main = 3;
var campsite = 4;

var ppflist = new Array("ppf32","ppf33","general");
//Array for each  PPF keeping track of how many pictures in each sub category for display
//the order of ppfmain must be in the order the ppflist is above otherwise the pics are going to 
//be unordered!!!
var ppfmain = new Array(ppflist.length);
ppfmain[0]=new Array(14,15,6,5,0); //ppf32 picture folder
ppfmain[1]=new Array(38,12,20,0,0); //ppf33 picture folder
ppfmain[2]=new Array(0,0,0,0,22); //general picture folder

var pics = new Array();
var alt = new Array();
var ppf;
var dir;
function  initGallery(form){
	//ppf = document.gallery.ppf.value;
	//dir = document.gallery.dir.value;
	ppf = document.getElementById("ppf").value;
	dir = document.getElementById("dir").value;
	
	for(var i=0;i<=ppflist.length ;i++){ //i will give location of which ppf
		if (ppf.toString() == ppflist[i]){ //Find which ppf it is
			for(var x=0;x<=dirs.length ;x++){ //x will give location of which sub dirctory and how many pictures in directory
				if(dir.toString() == dirs[x]){ //Find which sub directory it is
					var key = 0;
					for(var y=ppfmain[i][x];y>0;y--){
						pics[key] = pictures+"/"+ppflist[i]+"/"+dir+"/"+dir+(key+1)+".jpg";
						alt[key] = dir+(key+1)+".jpg";
						key++;
					}
				}
			}
		}
	}
	
	document.getElementById("prevLink").onclick = processPrevious;
	document.getElementById("nextLink").onclick = processNext;
}

function processPrevious(){
	if(currentPic == 0){
		//currentPic = ppf32pics.length;
		currentPic = pics.length;
	}
	currentPic--;
	//document.getElementById("picSlideShow").src=ppf32pics[currentPic];
	document.getElementById("picSlideShow").src=pics[currentPic];
	document.getElementById("picSlideShow").alt=alt[currentPic];
	return false;
}

function processNext(){
	currentPic++;
	//if(currentPic == ppf32pics.length){
	if(currentPic == pics.length){
		currentPic = 0;
	}
	//document.getElementById("picSlideShow").src=ppf32pics[currentPic];
	document.getElementById("picSlideShow").src=pics[currentPic];
	document.getElementById("picSlideShow").alt=alt[currentPic];
	return false;
}