// JavaScript Document
// This script is designed to create a scrollable gallery page
// Created By Michael Fox

function urllinks(whichone) {
//create an array containing the urls to the image files
urlid = new Array(9);
urlid[0] = "johnguitar.jpg";
urlid[1] = "christmasday.jpg";
urlid[2] = "congregation.jpg";
urlid[3] = "harvestflowers.jpg";
urlid[4] = "ruth.jpg";
urlid[5] = "shumensong.jpg";
urlid[6] = "shumencong.jpg";
urlid[7] = "shumenread.jpg";
urlid[8] = "churchfront.jpg";
urlid[9] = "marriage.jpg";
 return urlid[whichone];
}

function imgcaptions(whichone) {
//create an array containing the captions and alt tags for the above image files
captionTxT = new Array(9);
captionTxT[0] = "Our Minister John Bown playing the guitar";
captionTxT[1] = "Christmas Day Advent Candle lighting";
captionTxT[2] = "The Congregation at a Parade Service";
captionTxT[3] = "Harvest Festival flower arrangement";
captionTxT[4] = "Ruth Bravo talking about the Mission to Seamen";
captionTxT[5] = "The congregation at the Shumen Methodist Church singing together";
captionTxT[6] = "The congregation at the Shumen Methodist Church";
captionTxT[7] = "A reading at the Shuman service";
captionTxT[8] = "Bromley Methodist Church building";
captionTxT[9] = "The Marriage of Jane Carter and Matthew Willock";
 return captionTxT[whichone];
}

function createScroll(pagenum) {
//Set the number of items in the gallery
howmany = 9

//create new DIV
scrollDiv = document.createElement("div");
scrollDiv.setAttribute("id","thumbnails");

//create down arrow
downarrow = document.createElement("img");
downarrow.setAttribute("align","left");
downarrow.setAttribute("width","25px");
downarrow.setAttribute("height","25px");

//set down arrow as blank if no down, or as next	
if (pagenum == (howmany-4)) {
	downarrow.setAttribute("src","images/gallery_down_shaded.jpg");
	scrollDiv.appendChild(downarrow);
}
else {
	downarrow.setAttribute("src","images/gallery_down.jpg");
	arrowLink = document.createElement("a");
	arrowLink.setAttribute("href","javascript:createScroll(" + (pagenum+1) + ");");
	arrowLink.appendChild(downarrow);
	scrollDiv.appendChild(arrowLink);
}

//create up arrow
uparrow = document.createElement("img");
uparrow.setAttribute("width","25px");
uparrow.setAttribute("height","25px");

//set up arrow as blank if no up, or as previous	
if (pagenum == 0) {
	uparrow.setAttribute("src","images/gallery_up_shaded.jpg");
	scrollDiv.appendChild(uparrow);
}
else {
	uparrow.setAttribute("src","images/gallery_up.jpg");
	arrowLink = document.createElement("a");
	arrowLink.setAttribute("href","javascript:createScroll(" + (pagenum-1) + ");");
	arrowLink.appendChild(uparrow);
	scrollDiv.appendChild(arrowLink);
}

//create line break and add it
lineBreak = document.createElement("br");
scrollDiv.appendChild(lineBreak);

//identify resource location
resource = "images/thumbnails/"

//loop the images
for(i=0;i<=3;i++){
	if (pagenum <= (howmany-3)) {
		// create the link
		linkref = document.createElement("a");
		linkref.setAttribute("href","javascript:changeimg(" + (pagenum+i) + ");");
		//create the image
		imgref = document.createElement("img");
		imgref.setAttribute("src",resource + urllinks(pagenum+i));
		imgref.setAttribute("width","50");
		imgref.setAttribute("height","50");
		//create caption
		caption = document.createTextNode(imgcaptions(pagenum+i));
		//append the image and then caption to the link
		linkref.appendChild(imgref);
		linkref.appendChild(caption);
		//append the link to the div
		scrollDiv.appendChild(linkref)
		//add line breaks
		scrollDiv.appendChild(lineBreak);
		scrollDiv.appendChild(lineBreak);
	}
	else {
		continue;
		}
}

//replace the old scroll with the new one
tdright = document.getElementById("right");
oldScroll = document.getElementById("thumbnails");
tdright.replaceChild(scrollDiv,oldScroll);

}//eofn