// JavaScript Document
// Create and view a picture gallery. 
// (c) Adrian Yates 20004
// fullsize images are 640x480 default.
// Uses CSS for formatting text/background

// Global vars

// XHTML Constants - edit to suit
var wHead = '<?xml version="1.0" encoding="iso-8859-1"?>\n<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n<html xmlns="http://www.w3.org/1999/xhtml">\n';
	wHead += '<head>\n<title>Burwain Sailing Club Photo Gallery</title>\n';
	wHead += '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />\n';
	wHead += '<script language="JavaScript" src="Scripts/newgallery.js" type="text/javascript"></script>\n';
	// Edit this line to include whichever CSS file
	wHead += '<link href="Styles/gallery.css" rel="stylesheet" type="text/css" />\n</head>\n';
	// Edit the body tag to suit which ever CSS class

var wBody = '<body class="gallery" leftmargin="0" topmargin="0">\n<div align="center"><br/>\n';
	// Edit the <h1> element to title the pages generated
	wBody += '<h1>Burwain picture gallery</h1>\n';

function gallery(pWinName, pTitle,pPath, pSn,pEn, left, top, width, height)
{
// Params:
//	pWinName is the name of the window to work in. NB if '_self' is passed then current window is used
//  pTitle is the title which will appear above the images
//  pPath is the path to the direcory which contains the images (needs trailing '/')
//  pSN is the start number of the image sequence
//  pEN is the end number of the image sequence
// left, top, width, height refer to the window dimensions (doesnt make any difference if pWinName=_self
//
// Sample call:
// <p><a href="javascript:Gallery('Burwain', 'Learn to sail','Assets/Gallery/lts/',100,119,100,100,700,600);">Show image</a></p>
//
var popUp=0;
var stHTM="";
var pCn;

/*	popUp=eval(pWinName);
    if(!popUp.closed) 
		popUp.close(); */
    popUp = open('', pWinName, 'scrollbars=yes,resizable=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
	// Generate html string
	pCn = pSn;

	stHTM= wHead;
	stHTM += '<script language="JavaScript">\nvar iCur=' + pCn + ';\nvar iSn=' + pSn + ';\nvar iEn=' + pEn + ';\nvar iPath="' + pPath + 'image";</script>';
	stHTM += wBody;
	
	stHTM+='<h4>' + pTitle+ '</h4><br/>\n';
	// Display the image now
//	stHTM+='<img src="' + pPath + 'image' + pCn +'.jpg" border="1" alt="image' + pCn + '.jpg" width="640" height="480">\n';
	stHTM+='<img src="' + pPath + 'image' + pCn +'.jpg" border="1" alt="image' + pCn + '.jpg">\n';
	
	// Now write out the table, containg the next, back and previous links
	stHTM+='<table width="95%" cellpadding="3" cellspacing="0">\n';
	stHTM+='<tr>\n';
	stHTM+='<td width="33%">\n';
	stHTM+='<div align="center"><a href="Javascript:PrevPic();">Previous</a></div></td>\n';
	stHTM+='<td width="33%" >\n';
	stHTM+='<div align="center" id="fname">image ' + pCn + ' of ' + pEn + '</div></td>\n';
	stHTM+='<td width=33%>\n';
	stHTM+='<div align="center"><a href="Javascript:NextPic();">Next</a></div></td>\n';
//	stHTM+='<td>\n';
//	stHTM+='<div align="right" id="fname" width="80px">image'+pCn+'.jpg</div></td>\n';
	stHTM+='</tr>\n';
	stHTM+='</table><br/>\n';
	stHTM+='</div></body></html>\n';
	if (popUp) {
		popUp.document.write(stHTM);
		popUp.document.close();
	}
}

function PrevPic() {
// Display previous pic in sequence, or wrap round to last pic
	if (iCur > iSn) 
		iCur--;
	else 
		iCur = iEn;
	replacePic();
}

function NextPic() {
// Display next pic in sequence, or wrap round to first pic
	if (iCur < iEn) 
		iCur++;
	else 
		iCur = iSn;
	replacePic();
}

function replacePic() {
// Replace current image with next image in sequence
	document.images[0].src =  iPath + iCur +".jpg";
	document.images[0].alt = 'image' + iCur + '.jpg';
	// Update image name in text
	var t = document.getElementById("fname");
	if (t)	t.innerHTML = 'image ' + iCur + ' of ' + iEn;
}

