/* 
** functions.js (c) Tom Broad tcbroad@gmail.com
**
** Script to initialise arrays of pictures and thumbnails
** Change the values in this script to update
** the gallery. Modify the loop as appropriate
**
**/

//Initialise arrays
var picList = new Array();
var pictures = new Array(); 
var thumbs = new Array();
var preLoad = new Array();
var preThumbs = new Array();
var np = 50; //number of pictures


var ht = "";

function zn(n) {
	var z = (n < 9) ? "0" : "";
	z = z + n;
	return z;
}

for (i = 0; i < np; i++){
	var n = i + 1;
	ht += '<a class="nocolour" href="#" onclick="popWin(\'gallery_popup.html?id=' + zn(n) + '\')"><img title="Click to enlarge" class="t_i" alt="'+ zn(n) + '" id="t'+ zn(n) + '" src=""/></a>';
			
}
//alert(ht);
var url, th;

for (i = 0; i < np; i++){
	var z = (i < 9) ? "/0" : "/";
		url = "pics/gallery"+ z + (i + 1) + ".jpg";
		th = "pics/gallery/thumbs" + z + (i + 1) + ".gif";
		pictures[i] = url;
		thumbs[i] = th;
}

function doImg(){
	for (i = 0; i < pictures.length; i++){
		preLoad[i] = new Image();
		preLoad[i].src = pictures[i];
	}
}

function doThumbs() {
	for (i = 0; i < thumbs.length; i++){
		preThumbs[i] = new Image();
		preThumbs[i].src = thumbs[i];
	}
}

function usePicList(){
	for (i = 0; i < picList.length; i++);
	pictures[i] = picList[i];
}

//useNumPics();
//usePicList();

function populateThumbs() {
	doThumbs();
	document.getElementById("mt_gal").innerHTML = ht;
	var i = 1;
	while (i <= np) {
		var id = "t" + zn(i);
		document.getElementById(id).src = preThumbs[(i - 1)].src;
		i++;
	}
}	

function popWinSize(url,w,h){
	var t = (screen.height/2)-(h/2);
	var l = (screen.width/2)-(w/2);
	var features = 'height=' + h +',width=' + w +',top=' + t +',left=' + l +",scrollbars=no";
	//alert(url);
	window.open(url,'',features);
}

function popWin(url) { popWinSize(url, 800, 800) }