/***************************************************************************
* Create a photo object                                                    *
***************************************************************************/
function photo(id, galleries_id, photo_ref, section_code, src, width, height, caption, thumbnail, thumbnail_width, thumbnail_height, home, gallery, description, takendate, photographer, location, item_price, purchase_instruction) {
	this.id = id;
	this.galleries_id = galleries_id;
	this.photo_ref = photo_ref;
	this.section_code = section_code;
	this.src = src;
	this.width = width;
	this.height = height;
	this.caption = caption;
	this.thumbnail = thumbnail;
	this.thumbnail_width = thumbnail_width;
	this.thumbnail_height = thumbnail_height;
	this.home = home;
	this.gallery = gallery;
	this.description = description;
	this.takendate = takendate;
	this.photographer = photographer;
	this.location = location;
	this.item_price = item_price;
	this.purchase_instruction = purchase_instruction;
}
/***************************************************************************
* Create a gallery object                                                  *
***************************************************************************/

function gallery(id,featured_images,title,section_code) {
	this.id = id;
	this.featured_images = featured_images;
	this.title = title;
	this.section_code = section_code;}

/***************************************************************************
* Select a random value from a comma separated list                        *
***************************************************************************/
function randomListVal(list) {
	arrayVals = list.split(',');
	pos = Math.round(Math.random() * (arrayVals.length - 1));
	debug('Returning ' + arrayVals[pos] + ' as random image');
	return arrayVals[pos];
}

/***************************************************************************
* img = reference to image object in which to show image                   *
***************************************************************************/
function showHomeImage(img) {

	imageID = randomListVal('6432720,6432717,6432709,6432704,6432675,6432672,6432664,6432660,6328131,6328118,6328089,6328036,6327999,6327995,6327991,6289340,6064774,5811081,5811074,5811068,5811061,5811043,5713493,5664920,5664911,4864191,4864168,1227414,938476,732507,337500,337497,337493,337429,310752,310746,310745,232853,232852');
	for (j = 0; j < photos.length; j++) {
		if (photos[j].id == imageID) {
			if (!basic) {
			img.src = photos[j].src;
			img.width = photos[j].width;
			img.height = photos[j].height;
			}
			else {
				newImage = new Image(photos[j].width,photos[j].height);
				newImage.src = photos[j].src;
				document.images[img.name] = newImage;
				debug(newImage.src);
			}
			break;
		}
	}
}

/***************************************************************************
* Show a random image on home page from featured images                    *
***************************************************************************/
function showHomeImageInline() {
	
	imageID = randomListVal('6432720,6432717,6432709,6432704,6432675,6432672,6432664,6432660,6328131,6328118,6328089,6328036,6327999,6327995,6327991,6289340,6064774,5811081,5811074,5811068,5811061,5811043,5713493,5664920,5664911,4864191,4864168,1227414,938476,732507,337500,337497,337493,337429,310752,310746,310745,232853,232852');
	for (j = 0; j < photos.length; j++) {
		if (photos[j].id == imageID) {
			if ('gallery' != '') {
						if (photos[j].galleries_id != '') {
						document.write('<a href="' + photos[j].section_code + '_' + photos[j].galleries_id + '.html">');
						}
						else {
						document.write('<a href="gallery.html">');
						}
			}
			document.write('<img src="' + photos[j].src + '" width="' + photos[j].width + '" height="' + photos[j].height + '" class="mainhomepageimage" id="mainSample" name="mainSample" alt="' + photos[j].caption  + '" border="0">');
			if ('gallery' != '') {
				document.write('</a>');
			}
			break;
		}
	}
	
}

/***************************************************************************
* Show the next image in a gallery. field = hidden field containing        *
* image_id, img = reference to image object in which to show image         *
***************************************************************************/
function next(field,img) {

	debug('IN next');
	imageID = field.value;
	
	for (j = 0; j < photos.length; j++) {
		if (photos[j].id == imageID) {
			break;
		}
	}
	debug('image is ' + j);
	nextImg = -1;
	k= j + 1;
	while (nextImg < 0) {
		for (; k < photos.length; k++) {
			debug('testing image ' + k + ': gallery = ' + photos[k].galleries_id + '(existing: ' + photos[j].galleries_id + ')');
			if (photos[k].galleries_id == photos[j].galleries_id) {
				nextImg = k;
				debug('setting  nextImg = ' + k);
				break;
			}
		}
		if (nextImg == -1) {
			k = 0;
		}
	}
	if (nextImg != -1) {
		updateImage(nextImg, field,img);
	}


}


/***************************************************************************
* Set a new image on the gallery detail page given its array position      *
***************************************************************************/
function updateImage (nextImg, field,img) {
	debug('Updating image');
	if (!basic && !((0) || (0))) {
		debug('In updateImage');
		debug('setting  img src = ' + photos[nextImg].src);
		
					
			document.getElementById('imagePhoto').innerHTML = '<img class="mainphoto" src="' + photos[nextImg].src + ' " id="mainPic" name="mainPic" width="' + photos[nextImg].width + '" height="' + photos[nextImg].height + '" alt="' + photos[nextImg].caption + '">';
						field.value = photos[nextImg].id;
			document.getElementById('imageTitle').innerHTML = photos[nextImg].caption;
									document.title = 'St Peter\'s Church.  Redcar: ' + photos[nextImg].caption;
										/* apply 'blank' classname to element where */			if ( photos[nextImg].caption == '') {
				document.getElementById('imageTitle').style.className = 'blank';
			}
			else {
				document.getElementById('imageTitle').style.className = 'normal';
			}
						temp = '';
			if (photos[nextImg].description != '') {
				temp = temp +  '<p id="imageDescription">' + photos[nextImg].description + '</p>';
			}
						if (photos[nextImg].photo_ref != '') {
				temp = temp + '<p class="imageinfo" id="imageRef"><strong>Ref: </strong>' + photos[nextImg].photo_ref + '</p>';
			}
						if (photos[nextImg].takendate != '') {
				debug('Resetting taken date');
				temp = temp + '<p class="imageinfo" id="imageDate"><strong>Date: </strong>' + photos[nextImg].takendate + '</p>';
			}
			
			if (photos[nextImg].location != '') {
				debug('Resetting location');
				temp = temp + '<p class="imageinfo" id="imageLocation"><strong>Location: </strong>' +  photos[nextImg].location + '</p>';
			}
			
			if (photos[nextImg].photographer != '') {
				debug('Resetting photographer');
				temp = temp + '<p class="imageinfo" id="imagePhotographer"><strong>Photographer: </strong>' + photos[nextImg].photographer + '</p>';
			}
			if (temp != '') {				temp = temp + '<div class="spacer"></div>';			}					if (temp == '') {
			document.getElementById('imageDetails').style.display = 'none';
		}
		else {
			document.getElementById('imageDetails').style.display = 'block';
		}
		document.getElementById('imageDetails').innerHTML =temp;	
		
	}
	else {
		debug('Redirecting to id ' + photos[nextImg].id);
		window.location = 'photo_' + photos[nextImg].id + '.html';
	}
}

/***************************************************************************
* Show the previous image for a gallery. field = hidden field containing   *
* image_id, img = reference to image object in which to show image         *
***************************************************************************/
function previous(field,img) {


	imageID = field.value;
	for (j = 0; j < photos.length; j++) {
		if (photos[j].id == imageID) {
			break;
		}
	}
	debug('image is ' + j);
	nextImg = -1;
	k = j -1;
	while (nextImg < 0) {
		for (; k >= 0; k--) {
			if (photos[k].galleries_id == photos[j].galleries_id) {
				nextImg = k;
				break;
			}
		}
		if (nextImg == -1) {
			k = photos.length -1;
		}
	}
	if (nextImg != -1) {
		updateImage(nextImg, field,img);	
	}
}

/***************************************************************************
* Pick a photo at random from the featured images of a gallery.            *
* Gallery_id = id of gallery to choose,                                    *
* img = reference to html image in                                         *
* which to show image                                                      *
***************************************************************************/
function showGalleryImage(gallery_id, img) {
	debug('Gallery = ' + gallery_id);
	for (i = 0; i < galleries.length; i++) {
		if (galleries[i].id == gallery_id) {
			imageID = randomListVal(galleries[i].featured_images);
				for (j = 0; j < photos.length; j++) {
					if (photos[j].id == imageID) {
						
						img.src = photos[j].thumbnail;
						img.width = photos[j].thumbnail_width;
						img.height = photos[j].thumbnail_height;
						
						break;
					}
				}
			break;
		}
	} 
	}

/***************************************************************************
* If we have dynamic HTML, replace the galleries link with a list that     *
* doesn't include thecurrent gallery                                       *
***************************************************************************/
function showGalleries(gallery_id) {
	debug('Showing links for gallery ' + gallery_id);
	
	if (!basic) {
		temp = '';
		for (i = 0; i < galleries.length; i++) {
			debug('Testing gallery ' + galleries[i].id);
			
			if (galleries[i].id != gallery_id) {
				debug('Adding link');
				if (temp != '') {
					temp = temp + ' | ';
				}
				temp = temp + '<a href="gallery_' + galleries[i].id + '.html">' + galleries[i].title + '</a>';
			}
		}
		document.all.galleryLinks.innerHTML = 'Other galleries: ' + temp;
	}
}
/***************************************************************************
* Create the array of Photo objects                                        *
***************************************************************************/
photos = new Array();
photos[0] = new photo(6432660,'355064','','gallery','http://www.clikchurch.com/vbrennan/images/aileen.jpg',400,282,'Aileen and friends enjoying the summer evening','http://www.clikchurch.com/vbrennan/images/aileen_thumb.jpg',130, 92,0, 0,'','','','','','');
photos[1] = new photo(6432664,'355064','','gallery','http://www.clikchurch.com/vbrennan/images/children.jpg',400,300,'Children having fun','http://www.clikchurch.com/vbrennan/images/children_thumb.jpg',130, 98,0, 0,'','','','','','');
photos[2] = new photo(6432672,'355064','','gallery','http://www.clikchurch.com/vbrennan/images/hoggs.jpg',400,300,'Two branches of the Hogg family having a break after David did a good job on the BBQ','http://www.clikchurch.com/vbrennan/images/hoggs_thumb.jpg',130, 98,0, 0,'','','','','','');
photos[3] = new photo(6432675,'355064','','gallery','http://www.clikchurch.com/vbrennan/images/poster1.jpg',400,640,'People enjoying the good weather !','http://www.clikchurch.com/vbrennan/images/poster1_thumb.jpg',130, 208,0, 0,'','','','','','');
photos[4] = new photo(6432704,'355064','','gallery','http://www.clikchurch.com/vbrennan/images/sheila.jpg',400,288,'Miriam and Tom with the family','http://www.clikchurch.com/vbrennan/images/sheila_thumb.jpg',130, 94,0, 0,'','','','','','');
photos[5] = new photo(6432709,'355064','','gallery','http://www.clikchurch.com/vbrennan/images/rose.jpg',400,300,'Rose looking pleased to be with us again','http://www.clikchurch.com/vbrennan/images/rose_thumb.jpg',130, 98,0, 0,'','','','','','');
photos[6] = new photo(6432717,'355064','','gallery','http://www.clikchurch.com/vbrennan/images/valerie.jpg',400,411,'Val doing sterling work selling raffle tickets','http://www.clikchurch.com/vbrennan/images/valerie_thumb.jpg',130, 134,0, 0,'','','','','','');
photos[7] = new photo(6432720,'355064','','gallery','http://www.clikchurch.com/vbrennan/images/norma.jpg',400,256,'Norma and Arthur having a good time','http://www.clikchurch.com/vbrennan/images/norma_thumb.jpg',130, 83,0, 0,'','','','','','');
photos[8] = new photo(232852,'17006','','gallery','http://www.clikchurch.com/vbrennan/images/jwnewweb.jpg',302,350,'The Vicar<br>\r\nThe Rev. Canon John Weetman','http://www.clikchurch.com/vbrennan/images/jwnewweb_thumb.jpg',130, 151,0, 0,'','','','','','');
photos[9] = new photo(232853,'17006','','gallery','http://www.clikchurch.com/vbrennan/images/julienewweb.jpg',300,350,'Rev Dr Julie Watson <br>\r\nAssociate Minister','http://www.clikchurch.com/vbrennan/images/julienewweb_thumb.jpg',130, 152,0, 0,'The Rev Dr Julie Watson is associate minister at St Peter\'s Church. She works full time at Teesside University','','','','','');
photos[10] = new photo(310745,'17006','','gallery','http://www.clikchurch.com/vbrennan/images/Image1.jpg',400,459,'Mrs Betty Parramore<br>\r\nChurchwarden','http://www.clikchurch.com/vbrennan/images/Image1_thumb.jpg',130, 149,0, 0,'','','','','','');
photos[11] = new photo(310746,'17006','','gallery','http://www.clikchurch.com/vbrennan/images/Image6.jpg',400,459,'Mr Chris Bowers<br>\r\nReader','http://www.clikchurch.com/vbrennan/images/Image6_thumb.jpg',130, 149,0, 0,'','','','','','');
photos[12] = new photo(310752,'17006','','gallery','http://www.clikchurch.com/vbrennan/images/juliesmith1.jpg',192,256,'Mrs Julie Smith <br>\r\nReader','http://www.clikchurch.com/vbrennan/images/juliesmith1_thumb.jpg',130, 173,0, 0,'','','','','','');
photos[13] = new photo(938476,'17006','','gallery','http://www.clikchurch.com/vbrennan/images/claire1.jpg',304,407,'Miss Claire Soderman<br>\r\nChurchwarden','http://www.clikchurch.com/vbrennan/images/claire1_thumb.jpg',130, 174,0, 0,'','','','','','');
photos[14] = new photo(1227414,'17006','','gallery','http://www.clikchurch.com/vbrennan/images/fionaweb1.jpg',236,272,'Rev.Fiona Harrison-Smith<br>\r\nCurate','http://www.clikchurch.com/vbrennan/images/fionaweb1_thumb.jpg',130, 150,0, 0,'','','','','','');
photos[15] = new photo(5664911,'17006','','gallery','http://www.clikchurch.com/vbrennan/images/claire.jpg',290,302,'Claire Todd, Reader','http://www.clikchurch.com/vbrennan/images/claire_thumb.jpg',130, 135,0, 0,'','','','','','');
photos[16] = new photo(4864168,'17007','','gallery','http://www.clikchurch.com/vbrennan/images/foxweb_-_Copy.jpg',400,300,'Three generations of the Fox Family at the Harvest Service','http://www.clikchurch.com/vbrennan/images/foxweb_-_Copy_thumb.jpg',130, 98,0, 0,'','','','','','');
photos[17] = new photo(4864191,'17007','','gallery','http://www.clikchurch.com/vbrennan/images/pramharvestweb.jpg',379,273,'Some of the people who took part in the Family Harvest Service','http://www.clikchurch.com/vbrennan/images/pramharvestweb_thumb.jpg',130, 94,0, 0,'','','','','','');
photos[18] = new photo(5664920,'17007','','gallery','http://www.clikchurch.com/vbrennan/images/Family-Claires_Licensing_Nov_09.JPG',400,300,'Claire and family at her licensing at York Minster','http://www.clikchurch.com/vbrennan/images/Family-Claires_Licensing_Nov_09_thumb.JPG',130, 98,0, 0,'','','','','','');
photos[19] = new photo(5713493,'17007','','gallery','http://www.clikchurch.com/vbrennan/images/sandraweb1.jpg',342,456,'Sandra, known as the Queen of Hearts, at the Mad Hatter\'s Teaparty','http://www.clikchurch.com/vbrennan/images/sandraweb1_thumb.jpg',130, 173,0, 0,'','','','','','');
photos[20] = new photo(5811043,'17007','','gallery','http://www.clikchurch.com/vbrennan/images/webisrael6.jpg',400,300,'Israel 2010 <br>\r\nInside Church of The Holy Sepulchre','http://www.clikchurch.com/vbrennan/images/webisrael6_thumb.jpg',130, 98,0, 0,'','','','','','');
photos[21] = new photo(5811061,'17007','','gallery','http://www.clikchurch.com/vbrennan/images/gethsemane.jpg',400,300,'Entrance to Gethsemane','http://www.clikchurch.com/vbrennan/images/gethsemane_thumb.jpg',130, 98,0, 0,'','','','','','');
photos[22] = new photo(5811068,'17007','','gallery','http://www.clikchurch.com/vbrennan/images/webisrael2.jpg',400,300,'Anne and Sandra in the river Jordan','http://www.clikchurch.com/vbrennan/images/webisrael2_thumb.jpg',130, 98,0, 1,'Israel Pilgrimage','','','','','');
photos[23] = new photo(5811074,'17007','','gallery','http://www.clikchurch.com/vbrennan/images/webisrael1.jpg',400,300,'Claire framed by an aquaduct built by Herod','http://www.clikchurch.com/vbrennan/images/webisrael1_thumb.jpg',130, 98,0, 0,'','','','','','');
photos[24] = new photo(5811081,'17007','','gallery','http://www.clikchurch.com/vbrennan/images/webisrael4.jpg',400,300,'under an olive tree','http://www.clikchurch.com/vbrennan/images/webisrael4_thumb.jpg',130, 98,0, 0,'','','','','','');
photos[25] = new photo(6064774,'17007','','gallery','http://www.clikchurch.com/vbrennan/images/CLAIRE_WITH_GROUP_OF_READERS_IN_YORK_MINSTER_LIGHTENED.jpg',400,300,'Claire with other readers and The Archbishop after their licensing','http://www.clikchurch.com/vbrennan/images/CLAIRE_WITH_GROUP_OF_READERS_IN_YORK_MINSTER_LIGHTENED_thumb.jpg',130, 98,0, 0,'','','','','','');
photos[26] = new photo(6289340,'17007','','gallery','http://www.clikchurch.com/vbrennan/images/XLS0710.jpg',400,239,'reality at lightwater valley','http://www.clikchurch.com/vbrennan/images/XLS0710_thumb.jpg',130, 78,0, 0,'Reality youth group at Lightwater Valley','','','','','');
photos[27] = new photo(337429,'19117','','gallery','http://www.clikchurch.com/vbrennan/images/Dcp_0372.jpg',400,603,'The Lady Chapel','http://www.clikchurch.com/vbrennan/images/Dcp_0372_thumb.jpg',130, 196,0, 0,'The Lady Chapel is used for services every week. It is a place to light a candle and spend quiet time.','','','','','');
photos[28] = new photo(337493,'19117','','gallery','http://www.clikchurch.com/vbrennan/images/Dcp_0366.jpg',400,265,'Interior of church','http://www.clikchurch.com/vbrennan/images/Dcp_0366_thumb.jpg',130, 86,0, 0,'The inside of the church showing the alterations to the sanctuary','','','','','');
photos[29] = new photo(337497,'19117','','gallery','http://www.clikchurch.com/vbrennan/images/altar.jpg',400,265,'The Altar','http://www.clikchurch.com/vbrennan/images/altar_thumb.jpg',130, 86,0, 0,'Shows the altar in its new position after the alterations','','','','','');
photos[30] = new photo(337500,'19117','','gallery','http://www.clikchurch.com/vbrennan/images/reredos.jpg',400,265,'The reredos','http://www.clikchurch.com/vbrennan/images/reredos_thumb.jpg',130, 86,0, 0,'','','','','','');
photos[31] = new photo(732507,'56477','','gallery','http://www.clikchurch.com/vbrennan/images/Lee family R.jpg',91,80,'The Lee Family','http://www.clikchurch.com/vbrennan/images/Lee family R_thumb.jpg',130, 114,0, 0,'','','','','','');
photos[32] = new photo(6327991,'350877','','gallery','http://www.clikchurch.com/vbrennan/images/fair2.jpg',400,300,'Two Davids selling books','http://www.clikchurch.com/vbrennan/images/fair2_thumb.jpg',130, 98,0, 0,'','','','','','');
photos[33] = new photo(6327995,'350877','','gallery','http://www.clikchurch.com/vbrennan/images/christine1.jpg',400,300,'Enjoying the sunshine','http://www.clikchurch.com/vbrennan/images/christine1_thumb.jpg',130, 98,0, 0,'','','','','','');
photos[34] = new photo(6327999,'350877','','gallery','http://www.clikchurch.com/vbrennan/images/keith1.jpg',400,533,'Keith was busy selling plants','http://www.clikchurch.com/vbrennan/images/keith1_thumb.jpg',130, 173,0, 0,'','','','','','');
photos[35] = new photo(6328036,'350877','','gallery','http://www.clikchurch.com/vbrennan/images/jillcolin1.jpg',400,300,'Jill and Colin hard at work preparing raffle tickets','http://www.clikchurch.com/vbrennan/images/jillcolin1_thumb.jpg',130, 98,0, 0,'','','','','','');
photos[36] = new photo(6328089,'350877','','gallery','http://www.clikchurch.com/vbrennan/images/junelinda.jpg',400,300,'June and Linda were selling beautiful scarves','http://www.clikchurch.com/vbrennan/images/junelinda_thumb.jpg',130, 98,0, 0,'','','','','','');
photos[37] = new photo(6328118,'350877','','gallery','http://www.clikchurch.com/vbrennan/images/margery1.jpg',400,533,'Margery busy at the MU stall','http://www.clikchurch.com/vbrennan/images/margery1_thumb.jpg',130, 173,0, 0,'','','','','','');
photos[38] = new photo(6328131,'350877','','gallery','http://www.clikchurch.com/vbrennan/images/julie1.jpg',400,689,'Julie in her Summer jeans','http://www.clikchurch.com/vbrennan/images/julie1_thumb.jpg',130, 224,0, 0,'','','','','','');

/***************************************************************************
* Create the array of Gallery objects                                      *
***************************************************************************/
galleries = new Array();
galleries[0] = new gallery(355064,'6432720,6432717,6432709,6432704,6432675,6432672,6432664,6432660','BBQ2010','gallery');
galleries[1] = new gallery(17006,'5664911,1227414,938476,310752,310746,310745,232853,232852','who\'s who in the church','gallery');
galleries[2] = new gallery(17007,'5811068','events','gallery');
galleries[3] = new gallery(19117,'337500,337497,337493,337429','Inside the church','gallery');
galleries[4] = new gallery(56477,'732507','CMS Link Mission Partners ','gallery');
galleries[5] = new gallery(350877,'6328131,6328118,6328089,6328036,6327999,6327995,6327991','Summer Fair','gallery');

