//slideshow.js V. 2.1
//For creating a slideshow without having to create a seperate web page for each image
//created by David W. Behroozi david@davidwbehroozi.com

//DO NOT EDIT THIS FILE

//split URL, into URL and parameters
var params = document.location.href.split("?");
var filename = /(\w*\.\w*)$/.exec(params[0]);


//pictures
var pictures = new Array();

//captions
var captions = new Array();

//number of albums
var numAlbums=0;

//for temporarily storing the folder name
var folderName;

//current album and picture number
var picture=0;
var album=0;

//for storing additional parameters from URL
var paramString="?";

//increment through all of the params, extract album and picture information and save additional params
if(params[1]){
	splitParams = params[1].split("&");
	for(i in splitParams){
		var a = /album=(\d+)/.exec(splitParams[i]);
		if(a)
			album=parseInt(a[1]);
		else{
			var p = /pic=(\d+)/.exec(splitParams[i]);
			if(p)		
				picture=parseInt(p[1]);
			else{
				paramString+=splitParams[i]+"&";
			}
		}
	}
}

//Adds a picture to the current album with the filename and caption you specify
function add(filename,caption){
        if(numAlbums==0)
                alert("You must create an new album using newAlbum() before adding pictures to it");
        var index = pictures[numAlbums-1].length;
        pictures[numAlbums-1][index] = folderName+filename;
        captions[numAlbums-1][index] = caption;
}

//Creates a new album and looks for images in current folder or the folder you specify
function newAlbum(folder){
        pictures[numAlbums]=new Array();
        captions[numAlbums]=new Array();
        if(folder)
                folderName=folder+"/";
        else
                folderName="";
        numAlbums++;
}

//returns number of the previous image
function prevLinkHtml(content){
		albumExists();
		if(!content)
			content="";
        document.writeln("<a href='"+filename[0]+paramString+"album="+album+"&pic="+(picture+pictures[album].length-1)%pictures[album].length+"'>"+content+"</a>");
}

//returns the number of the next image
function nextLinkHtml(content){
	albumExists();
	if(!content)
		content="";
	document.writeln("<a href='"+filename[0]+paramString+"album="+album+"&pic="+(picture+1)%pictures[album].length+"'>"+content+"</a>");
}

//prints html code to display current image
function printImageHtml(){
	albumExists();
	if(pictures[album][picture])
		document.write("<img src='"+pictures[album][picture]+"'>");
	else
		alert("Picture doesn't exist");
}

//prints the caption
function printCaption(){
	albumExists();
	document.write(captions[album][picture]);
}

//used to see if a caption exists
function captionExists(){
	albumExists();
	return captions[album][picture];
}

function albumExists(){
	if(album>=numAlbums||album<0)
		alert("Album doesn't exist");
}