// Change the image that was rolled over
function swap(img, on)
{
  if(on) {img.src = img.src.replace("1.png", "2.png");}
  else   {img.src = img.src.replace("2.png", "1.png");}
}

// Writes the navigation buttons for the document
function writeNav()
{
	var curPage = document.URL;
	var i, pgIndex=-1, pgCount = pages.length;

	if(pgCount < 2)
		{return;}

	for(i=0 ; i < pgCount ; i++)
	{
		if(curPage.match(pages[i]))
		{
			pgIndex = i;
			break;
		}
	}
	
	if(pgIndex < 0)
		{alert("Error:  The current page is not listed in the pages[] array.");}

	document.write("<table align='center' border='0' cellpadding='0' cellspacing='0'><tr>"
	+ "<td valign='middle' width='76'>");

	if (pgIndex > 0)
	{
		document.write("<a href='"+pages[pgIndex-1]+"'>"
		+ "<img src='/supfiles/prev1.png' class='navbtn' alt='<- Prev' title='<- Prev'"
		+ " onMouseOver='swap(this, true);' onMouseOut='swap(this, false);'></a>");
	}
	else
		{document.write("&nbsp;");}

	document.write("</td><td valign='middle'>");

	for(i=0 ; i < pgCount ; i++)
	{
		if(pgIndex != i)
			{document.write("&nbsp; <a href='"+pages[i]+"'>pg " + (i+1) + "</a> &nbsp;");}
		else
			{document.write("&nbsp; pg " + (i+1) + " &nbsp;")};
	}

	document.write("</td><td valign='middle' width='76'>");
	
	if(pgIndex < pgCount-1)
	{
		document.write("<a href='"+pages[pgIndex+1]+"'>"
		+ "<img src='/supfiles/next1.png' class='navbtn' alt='Next ->' title='Next ->'"
		+ " onMouseOver='swap(this, true);' onMouseOut='swap(this, false);'></a>");
	}
	else
		{document.write("&nbsp;");}

	document.write("</td></tr></table>");
}

// Writes out the table of images and the Header for the table.
function writeBody(header,prefix)
{
	var counter=0, black=true, bg="black", size, j=0, arrayDims, defaultDims;

	if(arrayIsWide)
		{arrayDims = "width=100 height=75"; defaultDims = "width=75 height=100";}
	else
		{arrayDims = "width=75 height=100"; defaultDims = "width=100 height=75";}

	document.write("<h1>"+header+"</h1><table width='100%' border=0 cellspacing=0 cellpadding=10 bgcolor='#000000'><tr>");

	// This loop fills in all of the thumbnail blocks
	for(i=0;i<files.length;i++,counter++)
	{
		if(longSides[j]==i)
			{size=arrayDims; ++j;}
		else
			{size=defaultDims;}
				
		if(counter==5){document.write("</tr><tr>"); counter=0;}

		document.write("<td class='"+bg+"' width='20%' align='center'>"
			+ "<a class='"+bg+"' href='"+picFolder+"/"+prefix+files[i]+".jpg'>"
			+ "<img name='t"+i+"' "+size+" src='fake.jpg' align='center'>"
			+ "<br>"+files[i]+"</a></td>");

		if(black)
			{bg="white"; black=false;}
		else
			{bg="black"; black=true;}
	}

	// This loop fills in extra empty blocks at the end of the thumbnails.
	for(i=counter;i<5;i++)
	{
		document.write("<td class='"+bg+"' width='20%'>&nbsp;</td>");

		if(black)
			{bg="white"; black=false;}
		else
			{bg="black"; black=true;}
	}

	document.write("</tr></table>");

	// This loop replaces the fake image fillers with the real images.
	for(i=0;i<files.length;i++,counter++)
		{document["t"+i].src = thumbFolder+"/"+prefix+files[i]+"-t.jpg";}
}