function emptyElement(target) {
	while (target.hasChildNodes()) {
		target.removeChild(target.firstChild);
	} //end target.hasChildNodes() WHILE
} //end emptyElement
function advance() {
	//Increment the current photo
	current++;
	
	//Return to 0 if beyond the end of the array
	if (current == photos.length) {
		current = 0;
	} //end current == photos.length IF
	
	//Update Image
	document.getElementById("slideshow").setAttribute("src","photos/"+album+"/"+photos[current]);
} //end advance
function retreat() {
	//Decrement the current photo
	current--;
	
	//Return to the end of the array if beyond 0
	if (current == -1) {
		current = (photos.length-1);
	} //end current == -1 IF
	
	//Update Image
	document.getElementById("slideshow").setAttribute("src","photos/"+album+"/"+photos[current]);
} //end retreat
function lightbox(photo,id) {
	//Update current
	current = id;
	
	//Empty lightbox
	var target = document.getElementById("lightbox");
	emptyElement(target);
	
	//Build photo
	var table = document.createElement("table");
	var tr = document.createElement("tr");
	var td = document.createElement("td");
	td.setAttribute("colspan","3");
	var img = document.createElement("img");
	img.setAttribute("id","slideshow");
	img.setAttribute("src","./photos/"+album+"/"+photo);
	img.setAttribute("alt","Photo");
	td.appendChild(img);
	tr.appendChild(td);
	table.appendChild(tr);
	
	//Build navigation
	var tr = document.createElement("tr");
	var td = document.createElement("td");
	td.setAttribute("style","width:33%;text-align:left;");
	var prev = document.createElement("img");
	prev.setAttribute("src","prev.gif");
	prev.setAttribute("id","prev");
	if (document.all) {
		prev.setAttribute("onclick",retreat);
	} else {
		prev.setAttribute("onclick","retreat();");
	} //end document.all IF
	prev.setAttribute("title","previous photo");
	td.appendChild(prev);
	tr.appendChild(td);
	var td = document.createElement("td");
	td.setAttribute("style","width:34%;text-align:center;");
	var closer = document.createElement("img");
	closer.setAttribute("src","close.gif");
	closer.setAttribute("id","close");
	if (document.all) {
		closer.setAttribute("onclick",closeLightbox);
	} else {
		closer.setAttribute("onclick","closeLightbox();");
	} //end document.all IF
	closer.setAttribute("title","close photo");
	td.appendChild(closer);
	tr.appendChild(td);
	var td = document.createElement("td");
	td.setAttribute("style","width:33%;text-align:right;");
	var next = document.createElement("img");
	next.setAttribute("src","next.gif");
	next.setAttribute("id","next");
	if (document.all) {
		next.setAttribute("onclick",advance);
	} else {
		next.setAttribute("onclick","advance();");
	} //end document.all IF
	next.setAttribute("title","next photo");
	td.appendChild(next);
	tr.appendChild(td);
	table.appendChild(tr);
	target.appendChild(table);
	
	//Blackout screen
	var blackout = document.getElementById("blackout");
	blackout.style.width = (window.innerWidth-10)+"px";
	blackout.style.height = (window.innerHeight-10)+"px";
	blackout.style.display = "block";
	
	//Display lightbox
	target.style.width = "608px";
	target.style.height = "440px";
	target.style.left = ((window.innerWidth/2)-304)+"px";
	target.style.top = ((window.innerHeight/2)-220)+"px";
	target.style.display = "block";
} //end lightbox
function closeLightbox() {
	//Remove blackout & lightbox
	document.getElementById("blackout").style.display = "none";
	document.getElementById("lightbox").style.display = "none";
} //end closeLightbox