/***************************************************************************
* 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('1851425,428533,428512,428500,428488');
	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('1851425,428533,428512,428500,428488');
	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 = 'Photography by Stephen A Furlong: ' + 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 the current 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(428482,'33839','','gallery','http://www1.clikpic.com/stevefur/images/1001.jpg',360,504,'','http://www1.clikpic.com/stevefur/images/1001_thumb.jpg',93, 130,0, 0,'Chilston Park Staircase','','','','','');
photos[1] = new photo(428484,'33839','','gallery','http://www1.clikpic.com/stevefur/images/1002.jpg',504,360,'','http://www1.clikpic.com/stevefur/images/1002_thumb.jpg',130, 93,0, 0,'Horse Power','','','','','');
photos[2] = new photo(428488,'33839','','gallery','http://www1.clikpic.com/stevefur/images/1003.jpg',360,504,'','http://www1.clikpic.com/stevefur/images/1003_thumb.jpg',93, 130,1, 0,'The Archbishop\'s Palace, Maidstone','','','','','');
photos[3] = new photo(428491,'33839','','gallery','http://www1.clikpic.com/stevefur/images/1004.jpg',504,360,'','http://www1.clikpic.com/stevefur/images/1004_thumb.jpg',130, 93,0, 0,'The Boys','','','','','');
photos[4] = new photo(428492,'33839','','gallery','http://www1.clikpic.com/stevefur/images/1005.jpg',360,504,'','http://www1.clikpic.com/stevefur/images/1005_thumb.jpg',93, 130,0, 0,'Making Music','','','','','');
photos[5] = new photo(428493,'33839','','gallery','http://www1.clikpic.com/stevefur/images/1006.jpg',504,360,'','http://www1.clikpic.com/stevefur/images/1006_thumb.jpg',130, 93,0, 0,'Medway Register Office','','','','','');
photos[6] = new photo(428494,'33839','','gallery','http://www1.clikpic.com/stevefur/images/1007.jpg',360,504,'','http://www1.clikpic.com/stevefur/images/1007_thumb.jpg',93, 130,0, 0,'','','','','','');
photos[7] = new photo(428495,'33839','','gallery','http://www1.clikpic.com/stevefur/images/1008.jpg',504,360,'','http://www1.clikpic.com/stevefur/images/1008_thumb.jpg',130, 93,0, 0,'Upnor Castle Staircase','','','','','');
photos[8] = new photo(428496,'33839','','gallery','http://www1.clikpic.com/stevefur/images/1009.jpg',360,504,'','http://www1.clikpic.com/stevefur/images/1009_thumb.jpg',93, 130,0, 0,'Sailing','','','','','');
photos[9] = new photo(428497,'33839','','gallery','http://www1.clikpic.com/stevefur/images/1010.jpg',504,360,'','http://www1.clikpic.com/stevefur/images/1010_thumb.jpg',130, 93,0, 0,'','','','','','');
photos[10] = new photo(428498,'33839','','gallery','http://www1.clikpic.com/stevefur/images/1011.jpg',360,504,'','http://www1.clikpic.com/stevefur/images/1011_thumb.jpg',93, 130,0, 0,'...and the cake','','','','','');
photos[11] = new photo(428500,'33839','','gallery','http://www1.clikpic.com/stevefur/images/Aquietcorner.jpg',576,432,'','http://www1.clikpic.com/stevefur/images/Aquietcorner_thumb.jpg',130, 98,1, 0,'A peaceful garden','','','','','');
photos[12] = new photo(428501,'33839','','gallery','http://www1.clikpic.com/stevefur/images/1013.jpg',504,360,'','http://www1.clikpic.com/stevefur/images/1013_thumb.jpg',130, 93,0, 0,'A Young Admirer','','','','','');
photos[13] = new photo(428502,'33839','','gallery','http://www1.clikpic.com/stevefur/images/1014.jpg',360,504,'','http://www1.clikpic.com/stevefur/images/1014_thumb.jpg',93, 130,0, 0,'Laughter','','','','','');
photos[14] = new photo(428503,'33839','','gallery','http://www1.clikpic.com/stevefur/images/1015.jpg',504,360,'','http://www1.clikpic.com/stevefur/images/1015_thumb.jpg',130, 93,0, 0,'The Hands','','','','','');
photos[15] = new photo(428504,'33839','','gallery','http://www1.clikpic.com/stevefur/images/1016.jpg',360,504,'','http://www1.clikpic.com/stevefur/images/1016_thumb.jpg',93, 130,0, 0,'Swinging','','','','','');
photos[16] = new photo(428505,'33839','','gallery','http://www1.clikpic.com/stevefur/images/1017.jpg',504,360,'','http://www1.clikpic.com/stevefur/images/1017_thumb.jpg',130, 93,0, 0,'Signing the Register','','','','','');
photos[17] = new photo(428506,'33839','','gallery','http://www1.clikpic.com/stevefur/images/1018.jpg',360,504,'','http://www1.clikpic.com/stevefur/images/1018_thumb.jpg',93, 130,0, 0,'Winter Sunshine','','','','','');
photos[18] = new photo(428508,'33839','','gallery','http://www1.clikpic.com/stevefur/images/1019.jpg',504,360,'','http://www1.clikpic.com/stevefur/images/1019_thumb.jpg',130, 93,0, 0,'Hempstead House','','','','','');
photos[19] = new photo(428509,'33839','','gallery','http://www1.clikpic.com/stevefur/images/1020.jpg',360,504,'','http://www1.clikpic.com/stevefur/images/1020_thumb.jpg',93, 130,0, 0,'Chiddingstone Castle','','','','','');
photos[20] = new photo(428510,'33839','','gallery','http://www1.clikpic.com/stevefur/images/1021.jpg',504,360,'','http://www1.clikpic.com/stevefur/images/1021_thumb.jpg',130, 93,0, 0,'The Girls','','','','','');
photos[21] = new photo(428512,'33839','','gallery','http://www1.clikpic.com/stevefur/images/1024.jpg',360,504,'','http://www1.clikpic.com/stevefur/images/1024_thumb.jpg',93, 130,1, 0,'The Kiss','','','','','');
photos[22] = new photo(428517,'33839','','gallery','http://www1.clikpic.com/stevefur/images/1023.jpg',504,360,'','http://www1.clikpic.com/stevefur/images/1023_thumb.jpg',130, 93,0, 0,'Left Holding the Flowers','','','','','');
photos[23] = new photo(428520,'33839','','gallery','http://www1.clikpic.com/stevefur/images/1025.jpg',504,360,'','http://www1.clikpic.com/stevefur/images/1025_thumb.jpg',130, 93,0, 0,'Time to Go','','','','','');
photos[24] = new photo(428523,'33839','','gallery','http://www1.clikpic.com/stevefur/images/1026.jpg',360,504,'','http://www1.clikpic.com/stevefur/images/1026_thumb.jpg',93, 130,0, 0,'Happiness','','','','','');
photos[25] = new photo(428524,'33839','','gallery','http://www1.clikpic.com/stevefur/images/1027.jpg',504,360,'','http://www1.clikpic.com/stevefur/images/1027_thumb.jpg',130, 93,0, 0,'Christmas at The Knowle','','','','','');
photos[26] = new photo(428525,'33839','','gallery','http://www1.clikpic.com/stevefur/images/1028.jpg',360,504,'','http://www1.clikpic.com/stevefur/images/1028_thumb.jpg',93, 130,0, 0,'Close Attention','','','','','');
photos[27] = new photo(428526,'33839','','gallery','http://www1.clikpic.com/stevefur/images/1029.jpg',504,360,'','http://www1.clikpic.com/stevefur/images/1029_thumb.jpg',130, 93,0, 0,'More Rings','','','','','');
photos[28] = new photo(428528,'33839','','gallery','http://www1.clikpic.com/stevefur/images/1030.jpg',360,504,'','http://www1.clikpic.com/stevefur/images/1030_thumb.jpg',93, 130,0, 0,'Confetti','','','','','');
photos[29] = new photo(428530,'33839','','gallery','http://www1.clikpic.com/stevefur/images/1031.jpg',504,360,'','http://www1.clikpic.com/stevefur/images/1031_thumb.jpg',130, 93,0, 0,'Priestfield Stadium','','','','','');
photos[30] = new photo(428533,'33839','','gallery','http://www1.clikpic.com/stevefur/images/Thebestman.jpg',432,576,'','http://www1.clikpic.com/stevefur/images/Thebestman_thumb.jpg',98, 130,1, 0,'The Best Man!','','','','','');
photos[31] = new photo(428534,'33839','','gallery','http://www1.clikpic.com/stevefur/images/1033.jpg',504,360,'','http://www1.clikpic.com/stevefur/images/1033_thumb.jpg',130, 93,0, 0,'','','','','','');
photos[32] = new photo(428536,'33839','','gallery','http://www1.clikpic.com/stevefur/images/1034.jpg',360,504,'','http://www1.clikpic.com/stevefur/images/1034_thumb.jpg',93, 130,0, 0,'','','','','','');
photos[33] = new photo(428537,'33839','','gallery','http://www1.clikpic.com/stevefur/images/1035.jpg',504,360,'','http://www1.clikpic.com/stevefur/images/1035_thumb.jpg',130, 93,0, 0,'In Camera','','','','','');
photos[34] = new photo(428538,'33839','','gallery','http://www1.clikpic.com/stevefur/images/1036.jpg',360,504,'','http://www1.clikpic.com/stevefur/images/1036_thumb.jpg',93, 130,0, 0,'Sparkling','','','','','');
photos[35] = new photo(428539,'33839','','gallery','http://www1.clikpic.com/stevefur/images/1037.jpg',504,360,'','http://www1.clikpic.com/stevefur/images/1037_thumb.jpg',130, 93,0, 0,'Are You Following Us?','','','','','');
photos[36] = new photo(428540,'33839','','gallery','http://www1.clikpic.com/stevefur/images/1038.jpg',504,360,'','http://www1.clikpic.com/stevefur/images/1038_thumb.jpg',130, 93,0, 0,'','','','','','');
photos[37] = new photo(428541,'33839','','gallery','http://www1.clikpic.com/stevefur/images/1039.jpg',504,360,'','http://www1.clikpic.com/stevefur/images/1039_thumb.jpg',130, 93,0, 0,'Smart Thinking by the Groom and Best Man','','','','','');
photos[38] = new photo(428542,'33839','','gallery','http://www1.clikpic.com/stevefur/images/1040.jpg',504,360,'','http://www1.clikpic.com/stevefur/images/1040_thumb.jpg',130, 93,0, 0,'Elegance','','','','','');
photos[39] = new photo(428544,'33839','','gallery','http://www1.clikpic.com/stevefur/images/1041.jpg',504,360,'','http://www1.clikpic.com/stevefur/images/1041_thumb.jpg',130, 93,0, 0,'The Wedding Party','','','','','');
photos[40] = new photo(428545,'33839','','gallery','http://www1.clikpic.com/stevefur/images/1042.jpg',504,360,'','http://www1.clikpic.com/stevefur/images/1042_thumb.jpg',130, 93,0, 0,'Port Lympne Wild Animal Park','','','','','');
photos[41] = new photo(428546,'33839','','gallery','http://www1.clikpic.com/stevefur/images/1043.jpg',504,360,'','http://www1.clikpic.com/stevefur/images/1043_thumb.jpg',130, 93,0, 0,'Private Moments','','','','','');
photos[42] = new photo(428547,'33839','','gallery','http://www1.clikpic.com/stevefur/images/1044.jpg',504,360,'','http://www1.clikpic.com/stevefur/images/1044_thumb.jpg',130, 93,0, 0,'The Cornfield','','','','','');
photos[43] = new photo(428548,'33839','','gallery','http://www1.clikpic.com/stevefur/images/1045.jpg',360,504,'','http://www1.clikpic.com/stevefur/images/1045_thumb.jpg',93, 130,0, 0,'Evening Sunshine','','','','','');
photos[44] = new photo(428550,'33839','','gallery','http://www1.clikpic.com/stevefur/images/1046.jpg',504,360,'','http://www1.clikpic.com/stevefur/images/1046_thumb.jpg',130, 93,0, 0,'A Quiet Moment','','','','','');
photos[45] = new photo(428551,'33839','','gallery','http://www1.clikpic.com/stevefur/images/1047.jpg',504,360,'','http://www1.clikpic.com/stevefur/images/1047_thumb.jpg',130, 93,0, 0,'... and the Shoes','','','','','');
photos[46] = new photo(428552,'33839','','gallery','http://www1.clikpic.com/stevefur/images/1048.jpg',504,360,'','http://www1.clikpic.com/stevefur/images/1048_thumb.jpg',130, 93,0, 0,'The Smiles Say it All','','','','','');
photos[47] = new photo(1851425,'33839','','gallery','http://www1.clikpic.com/stevefur/images/Haveaseat.jpg',432,576,'','http://www1.clikpic.com/stevefur/images/Haveaseat_thumb.jpg',98, 130,1, 0,'The King Charles Hotel','','','','','');
photos[48] = new photo(1851434,'33839','','gallery','http://www1.clikpic.com/stevefur/images/Withthisring.jpg',576,432,'','http://www1.clikpic.com/stevefur/images/Withthisring_thumb.jpg',130, 98,0, 0,'With this ring ...','','','','','');

/***************************************************************************
* Create the array of Gallery objects                                      *
***************************************************************************/
galleries = new Array();
galleries[0] = new gallery(33839,'1851434,1851425,428552,428551,428550,428548,428547,428546,428545,428544','Weddings','gallery');

