

var album_list = new Array();
var album_long_name;
var photo_gallery = "albumcategories.aspx";
var pix_per_line = 4;
var slideshow_timer, slideshow_counter = 0, slideshow_frequency = 4, slideshow_mode = "Play";

function tc_photos() {
	var actr;
	var tc;

	initialize_photo_albums();
	tc = "";
	tc += "<div align=\"center\" class=\"wideColumn\">\n";
	tc += "<h1 align=center>Photo Galleries</h1>\n";

	tc += "<div class=\"fixer\"></div>\n";
	tc += "<br />\n";
	tc += "<table id=\"pgallery\" cellspacing=\"0\" cellpadding=\"0\" align=\"Center\" VerticalAlign=\"Middle\" border=\"0\" style=\"border-width:0px;border-style:Solid;border-collapse:collapse;\">\n";
	for (actr = 0; actr < album_list.length; actr++) {
		if (actr % pix_per_line == 0)
			tc += "<tr>\n";
		tc += "<td align=\"center\">\n";
		tc += "<div class=\"categoryContainer\">";
		tc += "<a href=\"photodriver.html?album_name=" + album_list[actr].dirname + "\">";
		tc += "<img src=\"images/AlbumCategories/" + album_list[actr].albumcover + "\"";
		tc += " alt=\"" + album_list[actr].alttext + "\"";
		tc += " title=\"" + album_list[actr].alttext + "\"";
		tc += " width=" + album_list[actr].width + " height=" + album_list[actr].height;
		tc += " border=0 /><br />\n";
		tc += album_list[actr].showtext + "</a>\n";
		tc += "</div>\n";
		tc += "</td>\n";
		if (actr % pix_per_line == eval(pix_per_line - 1))
			tc += "</tr>\n";
	}
	if (actr % pix_per_line != eval(pix_per_line - 1))
		tc += "</tr>\n";
	tc += "</table>\n";
	tc += "<div class=\"fixer\"></div>\n";
	tc += "</div>\n";

	document.write(tc);
//window.alert(tc);
}

function initialize_photo_albums() {
	var ctr = 0;

	for (ctr = 0; ctr < photo_albums.length; ctr++) {
		album_list[ctr] = new make_photogallery(photo_albums[ctr]);
	}
}

function make_photogallery(photogallery) {
	if (photogallery.length != 6) {
		window.alert("Invalid argument to make_photogallery");
		return;
	}
	this.dirname = photogallery[0];
	this.albumcover = photogallery[1];
	this.alttext = photogallery[2];
	this.showtext = photogallery[3];
	this.width = photogallery[4];
	this.height = photogallery[5];
}

function getQueryVariable(variable)
{
	// Get the query string
	var query = window.location.search.substring(1);
	
	// Break the query string into chunks
	var vars = query.split("&");
		
	// return
	for (var i=0;i<vars.length;i++)
	{
		var pair = vars[i].split("=");
		if (pair[0] == variable)
		{
			return pair[1];
		}
	}
	return (null);
}					

function tc_make_photo_album() {
	var tc, pctr;
	var album;
	var album_name;

	if (album_list.length == 0)
		initialize_photo_albums();
	album_name = getQueryVariable("album_name");
	if (album_name == null) {
		window.alert("Could not determine the album_name.");
		return;
	}

	tc = "";
	try {
		album = eval(album_name);
	}
	catch(err) {
		tc += "<h2 align=center>The contents of Album " + album_name + " is not defined.</h2>\n";
		tc += "<h1 align=center><a href=\"" + photo_gallery + "\">Back to Photo Galleries</a></h1><p></p>";
		document.write(tc);
		return;
	}

	get_album_long_name(album_name);

	tc += "<div align=center class=\"wideColumn\" id=\"" + album_name + "\">\n";
	tc += "<h1 align=center><a href=\"" + photo_gallery + "\">Photo Galleries</a> |\n";
	tc += "<a href=\"photodriver.html?album_name=" + album_name + "\">" + album_long_name + "</a>\n";
	tc += "</h1><p></p>";
	tc += "<table id=\"dlPictures\" cellspacing=\"0\" cellpadding=\"0\" align=\"Center\" VerticalAlign=\"Middle\" border=\"0\" style=\"border-width:0px;border-style:Solid;border-collapse:collapse;\">\n";
	for (pctr = 0; pctr < album.length; pctr++) {
		if (pctr % pix_per_line == 0)
			tc += "<tr>\n";
		tc += "<td align=\"center\">\n";
	 	tc += "<div class=\"photosContainer\"><a href=\"javascript:tc_open_photo('" + album_name + "','" + album[pctr][0] + "', 1);\"><img border=\"2\"  src=\"images/Albums/" + album_name + "/Thumbs/" + album[pctr][0] + "\">";
	 	if (album[pctr][1] != "")
			tc += "<br />" + album[pctr][1];
		tc += "</a></div>\n";
		tc += "</td>\n";
		if (pctr % pix_per_line == eval(pix_per_line - 1))
			tc += "</tr>\n";
	}
	if (pctr % pix_per_line != eval(pix_per_line - 1))
		tc += "</tr>\n";
	tc += "</table>\n";
	tc += "</div>\n";
	document.write(tc);
//window.alert(tc);
}

function tc_open_photo(album_name, photo_name, scrollflag) {
	var album, albumdiv;
	var tc;
	var pctr, curridx;
	var previdx, nextidx;

	if ((album = eval(album_name)) == null) {
		window.alert("The contents of Album " + album_name + " is not defined.");
		return;
	}
	for (pctr = 0; pctr < album.length; pctr++) {
		if (album[pctr][0] == photo_name) {
			curridx = pctr;
			break;
		}
	}
	if (curridx == album.length - 1)
		nextidx = -1;
	else
		nextidx = curridx + 1;
	if (curridx == 0)
		previdx = -1;
	else
		previdx = curridx - 1;

	slideshow_counter = curridx;

	tc = "";
	tc += "<h1><a href=\"photodriver.html?album_name=" + album_name + "\">" + album_long_name + "</a></h1>";
	tc += "<a href=\"" + photo_gallery + "\">Back to the Photo Galleries</a>";
	tc += "<br /><br />";
	tc += "<div align=center style=\"width:750px;\">";
	tc += "<div align=left style=\"float:left;\">";
	tc += "<br />";
	tc += "<a href=\"javascript:tc_open_photo('" + album_name + "','" + album[0][0] + "', 0);\">First</a> |\n";
	if (previdx == -1)
		tc += "<a href=\"javascript:do_nothing();\">Previous</a> |\n";
	else
		tc += "<a href=\"javascript:tc_open_photo('" + album_name + "','" + album[previdx][0] + "', 0);\">Previous</a> |\n";
	if (nextidx == -1)
		tc += "<a href=\"javascript:do_nothing();\">Next</a> |\n";
	else
		tc += "<a href=\"javascript:tc_open_photo('" + album_name + "','" + album[nextidx][0] + "', 0);\">Next</a> |\n";
	tc += "<a href=\"javascript:tc_open_photo('" + album_name + "','" + album[album.length - 1][0] + "', 0);\">Last</a> |\n";
	tc += "<a href=\"photodriver.html?album_name=" + album_name + "\">Thumbnails</a>";
	tc += "</div>";
	tc += "<div align=right style=\"float:right;\">";
	tc += "Slide Show: <a id=\"ssanchor\" href=\"javascript:tc_slideshow('" + album_name + "');\">" + ss_mode() + "</a>\n";
	tc += "<br />Frequency <select id=\"ssfreq\">";
	for (pctr = 1; pctr <= 20; pctr++) {
		if (pctr == slideshow_frequency)
			tc += "<option selected>" + pctr + "</option>";
		else
			tc += "<option>" + pctr + "</option>";
	}
	tc += "</select>\n";
	tc += "</div>";
	tc += "</div>";
	tc += "<br />";
	tc += "<div align=center style=\"height:850px;clear:top;\">\n";
	tc += "<br />";
	if (album[curridx][1] != "")
		tc += "<p>" + album[curridx][1] + " | ";
	else
		tc += "<p>" + photo_name + " | ";
	tc += (curridx + 1) + " of " + album.length + "</p>\n";
	tc += "<img src=\"images/Albums/" + album_name + "/Photos/" + photo_name + "\" border=\"0\" alt=\"" + photo_name + "\" title=\"" + photo_name + "\">\n";
	tc += "</div>\n";

	albumdiv = document.getElementById(album_name);
	albumdiv.innerHTML = tc;
	if (scrollflag == 1)
		window.scrollTo(0,0)
	//document.getElementById("ssfreq").selectedIndex = slideshow_frequency - 1;
}

function get_album_long_name(album_name) {
	var actr;

	initialize_photo_albums();
	for (actr = 0; actr < album_list.length; actr++) {
		if (album_name == album_list[actr].dirname) {
			album_long_name = album_list[actr].showtext;
			return;
		}
	}
	album_long_name = album_name
}

function do_nothing() {
}

function tc_slideshow(album_name) {

	if (slideshow_mode == "Play") {
		slideshow_frequency = document.getElementById("ssfreq").selectedIndex + 1;
		slideshow_timer = setInterval("show_slide('" + album_name + "');", slideshow_frequency * 1000);
		slideshow_mode = "Pause";
	}
	else {
		clearInterval(slideshow_timer);
		slideshow_mode = "Play";
	}
	document.getElementById("ssanchor").innerHTML = slideshow_mode;
}

function ss_mode() {
	//document.getElementById("ssanchor").innerHTML = slideshow_mode;
	return(slideshow_mode);
}

function show_slide(album_name) {
	var album;

	if ((album = eval(album_name)) == null)
		return;

	tc_open_photo(album_name, album[slideshow_counter][0], 0);
	if (++slideshow_counter == album.length) {
		clearInterval(slideshow_timer);
		slideshow_mode = "Play";
		slideshow_counter = 0;
		document.getElementById("ssanchor").innerHTML = slideshow_mode;
	}
}

