// JavaScript Document
var lastImg = new Boolean(false);

function fileExists(url) {
	var result = false;
	
	var req;
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	if (req) {
		req.open("HEAD", url, false);
		req.send(' ');
		if (req.status != 404) {
			result = true;
		}
	}
	
	return result;
}

function Photo(imgPath, thumbPath) {
	this.imgPath = imgPath;
	this.thumbPath = thumbPath;

	if (fileExists(imgPath) == true) {
		lastImg = false;
	} else {
		lastImg = true;
	}
}

function writePhotoTable() {
	document.write("<table class=\"album\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"margin: 0px;\"><tbody>");	
}

function writePhotoTr() {
	document.write("<tr style=\"background:1px solid #f7f7f7;\">");	
}

function writePhotoTd(array, j, width, maxwidth) {
	document.write("<td><a href=\"" + array[j].imgPath + "\" rel=\"lightbox[example]\" title=\" \"> <img src=\"" + array[j].thumbPath + "\" alt=\"\" width=\"" + width + "\" style=\"max-width: " + maxwidth + "px;\" /></a></td>");
}

function writePhotosComingSoon() {
	document.write("<table><tr><td>Photos coming soon!</td></tr></table>");
}

function populatePhotos(category) {
	var i = 0;
	var array = new Array();
	lastImg = false;
	while (lastImg == false) {
		array[i] = new Photo("Images/" + category + i + ".jpg", "Images/" + category + i + "-t" + ".jpg");
		i++;
	}
	array.splice(i-1);
	
	return array;
}