// Pagebuild


// Builds up library page based on list of picture data


// Data (array 'a') is defined in data.js in local directory




//###############       MAIN FUNCTION BUILDPAGE    ################

function buildpage() {

document.write("<CENTER>");




//########  HEADING LINES    ########

document.write("<table><tr><td width='150'><h4><a href='../index.htm'>Home</a></h4></td>");

document.write("<td width='150'><h4><a href='../imagesales.htm'>Licensing</a></h4></td></tr></table>");




document.write("<table><tr><td><h4>Click on thumbnails for larger images or <a href='slideshow.htm'>click here to view as a slideshow</a></h4></td></tr></table>");


document.write("<br><br>");







//Write images and captions to table in rows of three  






//########  TABLE    ########

var npics = a.length;
var i=0;
document.write("<CENTER>");
do{	
	document.write("<TABLE width=750>");

	document.write("<TR align=center valign=bottom>");
       	document.write("<TD width='250'>");
	thumb(i);
	document.write("</TD>"); 
	i++ ; 
	document.write("<TD width='250'>");
	thumb(i);
	document.write("</TD>"); 
	i++ ; 
	document.write("<TD width='250'>");
	thumb(i);
	document.write("</TD>"); 
	document.write("</TR>");

	document.write("<TR  height = 50 align=center valign=top >");
	document.write("<TD><H5>" +picID(i-2) +"<br>" +title(i-2) +"</H5></TD>");	
	document.write("<TD><H5>" +picID(i-1) +"<br>" +title(i-1) +"</H5></TD>");
	document.write("<TD><H5>" +picID(i) +"<br>" +title(i) + "</H5></TD>");
	i++;  document.write("</TR>");

	document.write("</TABLE>");

} while ( npics-i >2 ) ; 

//write last row (if one residue image)
if (npics-i ==1) {
	document.write("<TABLE>");
	document.write("<TR  align=center valign=bottom >");
	document.write("<TD width='250'></TD><TD width='250'>");
	thumb(i);
	document.write("</TD><TD width='250'></TD>");
	document.write("</TR>");

	document.write("<TR  height = 50 align=center valign=top >");		
	document.write("<TD></TD>");	
	document.write("<TD><H5>" +picID(i) +"<br>" +title(i) +"</H5></TD>");
	document.write("<TD></TD>");	
	document.write("</TR>");
	document.write("</TABLE>");
}

//write last row (if two residue images)
if (npics-i ==2) {
	document.write("<TABLE>");

	document.write("<TR  align=center valign=bottom >");
	document.write("<TD width='250'>");	
	thumb(i); i++; 
	document.write("</TD><TD width='250'></TD><TD width = '250'>");
	thumb(i);
	document.write("</TD></TR>");

	document.write("<TR  height = '50' align=center valign=top >");		
	document.write("<TD><H5>" +picID(i-1) +"<br>" +title(i-1) +"</H5></TD>");
	document.write("<TD></TD>");	
	document.write("<TD><H5>" +picID(i) +"<br>" +title(i) +"</H5></TD>");
	document.write("</TR>");

	document.write("</TABLE>");
}


// #############  Footer #####################


document.write("<table <tr><td width='960' border='0'><h4>All images are available as stock photography for publication.</h4></td></tr></table>");

document.write("<table><tr><td width='150'><h4><a href='../index.htm'>Home</a></h4></td>");

document.write("<td width='150'><h4><a href='../imagesales.htm'>Licensing</a></h4></td></tr></table>");
   
document.write("<table><tr><td width='320'>");
document.write("<h4>Enquiries to: <a href='mailto:info@chri");
document.write("shammondphotography.com'>info@ch");
document.write("rishammondphotography.com</a></h4>");
document.write("</td></table>");


document.write("<table><tr align='left'><td width='600' valign='top' height='60'><h5 align='left'>The photographs on this site are the work of Chris Hammond and are protected under UK and International copyright laws. The images may not be copied, printed, published or reproduced without written permission.</h5></td></tr></table>");






 
}

//##################   END OF BUILDPAGE         ######################


// ############################  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 onclick = 'if (window.fullyloaded) 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();

}





function close_popup() {
//closes popup window 
if( popwindow != null ) popwindow.close();
}
