// Buildgallery

// Builds up gallery page based on list of picture data


var a = new Array(


"g01/Plate Glass/72/100/291/400",
"g02/Desafinado/67/100/267/400",
"g03/Corkscrew/73/100/291/400",
"g04/Mycena Clavularis/73/100/291/400",

"g05/New Dawn/100/67/450/300",
"g06/Private View/91/67/408/300",
"g07/Peking Opera/100/73/400/291",
"g08/Fire-eater/100/58/450/260",

"g09/U-turn/100/73/400/291",
"g10/Inflatables/100/43/400/170",
"g11/Room at the Top/100/66/400/264",
"g12/Liaison/100/73/400/291"



);


var npics = a.length;
var i=0;



// ##############  Write images and captions to table in rows of four  ###########

document.write("<CENTER>");


do{	
	document.write("<TABLE width=720>");

	document.write("<TR height='120' align='center' valign='bottom'>");
       	document.write("<TD width='140'>");
	thumb(i);
	document.write("</TD>"); 
	i++ ; 
	document.write("<TD width='140'>");
	thumb(i);
	document.write("</TD>"); 
	i++ ; 
	document.write("<TD width='140'>");
	thumb(i);
	document.write("</TD>"); 
	i++ ; 
	document.write("<TD width='140'>");
	thumb(i);
	document.write("</TD>");
	i++; 
	document.write("</TR>");
	document.write("</TABLE>");

} while ( i < npics ) ; 




// ############################  FUNCTIONS  ######################################


function parse(i,j) {
//extracts parameter j from data string i
var dataStr = a[i];
var k=0;
var str ="";
while(j>1)
{ 
while(dataStr.charAt(k) != "/") {k++}; 
j-- ;
k++ ;
}
do{
str = str + dataStr.charAt(k);
k++; 
}
while ((dataStr.charAt(k) != "/") && (k <= dataStr.length));
return str;
}


function picID(i) {
//returns the picture ID of image i
return parse(i,1) }


function title(i) {
//returns the title of image i
return parse(i,2) }


function tnWidth(i) {
//returns the thumbnail width for image i
return Number(parse(i,3)) }

function tnHeight(i) {
//returns the thumbnail height for image i
return Number(parse(i,4)) }


function imWidth(i) {
//returns the large image width for image i
return Number(parse(i,5)) }

function imHeight(i) {
//returns the large image height for image i
return Number(parse(i,6)) }

	

function thumb(j) {


//writes thumbnail and shadow 

        document.write("<table border='0' cellpadding='0' cellspacing='0'>"); 

	
	document.write("<tr><td>");      
        document.write("<a HREF= 'javascript:popup(" + j +")'>");
	document.write("<IMG SRC = 'thumbnails/" + picID(j) + ".jpg'");
	document.write(" width = '" + tnWidth(j) + "' height = '" + tnHeight(j) + "'"); 	
	document.write(" alt='Click for larger image'></a></td>");

        document.write("<td valign='top' width='8'>");
	document.write("<img src='../clearsquare.gif' width='8' height='5'><br>");
	document.write("<img src='../tntopright.gif' width='8' height='8'><br>");
        document.write("<img src='../tnright.gif' width='8' height='" + (tnHeight(j)-13) + "'></td>");
	document.write("</tr><tr><td valign='top'>");
	document.write("<img src='../clearsquare.gif' width='4' height='7'>");
	document.write("<img src='../tnbottomleft.gif' width='8' height='7'>");
	document.write("<img src='../tnbottom.gif' width='" + (tnWidth(j)-12) + "' height='7'></td>");
	document.write("<td><img src='../tnbottomright.gif' width='8' height='7'></td>");	
	document.write("</tr></table>")


}

   


//PopWindow  opens bigger picture in new window

var popwindow; 

function popup(n) {
//opens new window with dynamically defined content
close_popup();
var winWidth = imWidth(n) + 100;
var winHeight = imHeight(n) + 130;
popwindow = window.open("","","top=0, left=0, width=" + winWidth + ", height=" + winHeight);
popwindow.document.open();
popwindow.document.write("<head><title>" + picID(n) + "</title>");
popwindow.document.write("<LINK rel=stylesheet href='../stylesheet.css' type='text/css'></head>");
popwindow.document.write( "<body background='../Texture.jpg'><center>");


popwindow.document.write("<table border='0' cellpadding='0' cellspacing='0'>"); 
popwindow.document.write("<tr><td height = '30'></td><td></td></tr><tr><td>"); 
popwindow.document.write( "<a href='javascript:close()'>");     
popwindow.document.write("<img src= 'images/" + picID(n) + ".jpg'");
popwindow.document.write("height='" + imHeight(n) + "' width='" + imWidth(n) + "'");
popwindow.document.write(" alt = 'Click to close this image' galleryimg ='no' ></a></td>");
popwindow.document.write("<td valign='top' width='8'>");
popwindow.document.write("<img src='../clearsquare.gif' width='8' height='5'><br>");
popwindow.document.write("<img src='../tntopright.gif' width='8' height='8'><br>");
popwindow.document.write("<img src='../tnright.gif' width='8' height='" + (imHeight(n)-13) + "'></td>");
popwindow.document.write("</tr><tr><td valign='top'>");
popwindow.document.write("<img src='../clearsquare.gif' width='4' height='7'>");
popwindow.document.write("<img src='../tnbottomleft.gif' width='8' height='7'>");
popwindow.document.write("<img src='../tnbottom.gif' width='" + (imWidth(n)-12) + "' height='7'></td>");
popwindow.document.write("<td><img src='../tnbottomright.gif' width='8' height='7'></td></tr></table>");	
popwindow.document.write("<table width='100% border='0' cellpadding='0' cellspacing='0'>");
popwindow.document.write("<tr><td height='20'></td></tr><tr><td height='50'>");
popwindow.document.write( "<H4><b>" + title(n) + "</b></H4>" );
popwindow.document.write("<h6> &copy; Chris Hammond </h6>");
popwindow.document.write("</center> </body>");
popwindow.document.close();
refresh();

}



function refresh(){
//refreshes thumbnail images
for (var k=0; k<document.images.length; k++)
document.images[k].src = document.images[k].src;
}




function close_popup() {
//closes popup window 
if( popwindow != null ) popwindow.close();
}
