// Photogallery Page
//
// Created by Gage Trader, April 22, 2005

var size = 0; // the total number of pictures in the current gallery
var root = ""; // the root location of the gallery (where all the HTML pages are stored)
var pageNo = 0; // the number of the page corresponding to position in the list.
var begin = null; // reference to the beginning node in the list
var current = null; // reference to the current node in the list
var indexName = ""; // reference to the name of the index page the photos should go on.  

function Photogallery(root)
{
	this.root = root;
}

function addPhoto(photoLoc, caption, index)
{
	add(new Photo(photoLoc, caption, index));
}

function addPhoto(photoLoc, caption, index, printVal)
{
	add(new Photo(photoLoc, caption, index, printVal));
}

function add(photo)
{
	if ( size == 0 )
	{
		begin = photo;
		current = photo;	
	}
	else 
	{
		current.next = photo;
		current = photo;
	}
	
	size++;
}

function getSize()
{
	return size;
}

function getPhotoAt()
{
	var lookfor = begin;
	for (var i = 1; i < pageNo; i++ )
	{
		lookfor = lookfor.next;
	}
	
	return lookfor;
}

function drawIndex()
{
	document.write('<table align="center" class="photogallery"><tr>');
	var lookfor = begin;
	var pageCounter = 1;
	var innerCounter = 1;
	var loc = ""; 
	var ind;
	
	ind = lookfor.index;
	for (var i = 1; i <= size; i++ )
	{
		ind = lookfor.index;
		if (ind == (indexName+ ".htm"))
		{
			i = size;
		}
		else
		{
			lookfor = lookfor.next;
			pageCounter++;
		}
	}
	
	for (var i = 1; i <= size; i++)
	{
		ind = lookfor.index;
		if (ind != (indexName + ".htm"))
		{
			i = size;
		}
		else
		{
			if (pageCounter < 10) 
			{
				loc = "00" + pageCounter + ".htm";
			}
			else if (pageCounter < 100)
			{
				loc = "0" + pageCounter + ".htm";
			}
			else 
			{
				loc = pageCounter + ".htm";
			}
		
			document.write('<td><a href="' + loc + '"><img src="thumbs/' + lookfor.photoLoc+'" alt="' + defaultAlt + '" /></a></td>');
			if (innerCounter == 5)
			{
				document.write('</tr><tr>');
				innerCounter = 0;
			}
			innerCounter++;
			pageCounter++;
			lookfor = lookfor.next;
		}
	} 
	if (innerCounter % 5 != 0) { document.write('</tr>');}
	document.write('</table>');
}

function drawContent()
{
 	var photo = getPhotoAt();
 	var index = photo.index;
	var loc = photo.photoLoc;
	var cap = photo.caption;
	var pV = photo.printVal;
	
	if (pV == true || pV == null) 
	{
 		document.write('<p align="right"><a href="print/' + loc +'">Print Quality Version</a></p>');
	}
	
 	document.write('<table align="center"><tr><td>');
	if (pageNo == 1)
	{
		document.write('&lt; Previous');
	}
	else if (pageNo <= 10) 
	{
		document.write('<a href="00'+ (pageNo-1)+'.htm">&lt; Previous</a>');
	}
	else if (pageNo <= 100)
	{
		document.write('<a href="0'+ (pageNo-1)+'.htm">&lt; Previous</a>');
	}
	else 
	{
		document.write('<a href="'+ (pageNo-1)+'.htm">&lt; Previous</a>');
	}
	document.write('</td><td>  |  </td><td><a href="' + index +'">Index</a></td>');
	document.write('<td>  |  </td><td>');
	if (pageNo == size) { document.write('Next &gt;');}
	else if (pageNo >= 99)
	{
		document.write('<a href="'+ (pageNo+1)+'.htm">Next &gt;</a>');	
	}
	else if (pageNo >= 9 )
	{
		document.write('<a href="0'+ (pageNo+1)+'.htm">Next &gt;</a>');
	}
	else 
	{
		document.write('<a href="00'+ (pageNo+1)+'.htm">Next &gt;</a>');
	}
	document.write('</td></tr></table>');

	document.write('<div id="photoContainer"><img src="photos/' + loc + '" alt="' + defaultAlt + '" border="0" />');
	document.write('<p>'+cap+'</p></div>');
}

// Photo Node-like stuff

function Photo (loc, capt, idx, prnt)
{
	var next = null;
    var photoLoc = "";
    var caption = "";
    var index = "";
	var printVal = "";
	var defaultAlt = ""; // if no alt text is specified, this alt text will be used

	this.photoLoc = loc;
	this.caption = capt;
	if (idx == null) { this.index = "index.htm"; }
	else { this.index = idx;}
	if (prnt != "" || prnt != null) { this.printVal = prnt; }
}
