/***************************************************************************
* 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) {
	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;
}
/***************************************************************************
* 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('732973');
	for (j = 0; j < photos.length; j++) {
		if (photos[j].id == imageID) {
			if (!basic) {
			img.src = 'images/' + 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 = 'images/' + 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('732973');
	for (j = 0; j < photos.length; j++) {
		if (photos[j].id == imageID) {
			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="images/' + photos[j].src + '" width="' + photos[j].width + '" height="' + photos[j].height + '" class="mainhomepageimage" id="mainSample" name="mainSample" alt="' + photos[j].caption  + '" border="0">');
			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)) {
		debug('In updateImage');
		debug('setting  img src = ' + photos[nextImg].src);
		
					
						document.getElementById('imagePhoto').innerHTML = '<img class="mainphoto" src="images/' + photos[nextImg].src + ' " id="mainPic" name="mainPic" width="' + photos[nextImg].width + '" height="' + photos[nextImg].height + '" alt="' + photos[nextImg].caption + '" border="0">';
						field.value = photos[nextImg].id;
			document.getElementById('imageTitle').innerHTML = photos[nextImg].caption;
			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.visibility = 'hidden';
		}
		else {
			document.getElementById('imageDetails').style.visibility = 'visible';
		}
		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('Image = ' + 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 = 'images/' + 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(734120,'56612','','gallery','Chris-portrait.gif',288,432,'Chris','Chris-portrait_thumb.gif',130, 195,0, 0,'','','','');
photos[1] = new photo(734122,'56612','','gallery','Graeme-Tennant-portrait.gif',221,288,'','Graeme-Tennant-portrait_thumb.gif',130, 169,0, 0,'','','','');
photos[2] = new photo(734123,'56612','','gallery','Claire-portrait.gif',349,432,'','Claire-portrait_thumb.gif',130, 161,0, 0,'','','','');
photos[3] = new photo(734196,'56619','','gallery','4+1Kennedys-family.gif',432,288,'','4+1Kennedys-family_thumb.gif',130, 87,0, 0,'','','','');
photos[4] = new photo(734197,'56619','','gallery','4+1-Kennedys-family.gif',288,432,'','4+1-Kennedys-family_thumb.gif',130, 195,0, 0,'','','','');
photos[5] = new photo(734198,'56619','','gallery','4+1-Kennedys-family1.gif',288,432,'','4+1-Kennedys-family1_thumb.gif',130, 195,0, 0,'','','','');
photos[6] = new photo(734199,'56619','','gallery','Kennedy-family.gif',432,242,'','Kennedy-family_thumb.gif',130, 73,0, 0,'','','','');
photos[7] = new photo(734201,'56619','','gallery','Gordon-and-his-girls-mono-f.gif',288,466,'','Gordon-and-his-girls-mono-f_thumb.gif',130, 210,0, 0,'','','','');
photos[8] = new photo(734204,'56619','','gallery','Robbie-and-Co-family.gif',432,288,'','Robbie-and-Co-family_thumb.gif',130, 87,0, 0,'','','','');
photos[9] = new photo(734207,'56619','','gallery','Sam-and-Lennon-family.gif',500,391,'','Sam-and-Lennon-family_thumb.gif',130, 102,0, 0,'','','','');
photos[10] = new photo(734209,'56619','','gallery','seven-Fyfes-mono-family.gif',432,266,'','seven-Fyfes-mono-family_thumb.gif',130, 80,0, 0,'','','','');
photos[11] = new photo(734213,'56619','','gallery','trees-in-front-boys-looking.gif',432,288,'','trees-in-front-boys-looking_thumb.gif',130, 87,0, 0,'','','','');
photos[12] = new photo(734216,'56619','','gallery','Family-Cian-and-Sam.gif',500,540,'','Family-Cian-and-Sam_thumb.gif',130, 140,0, 0,'','','','');
photos[13] = new photo(734257,'','','','Chris-couples.gif',175,432,'','Chris-couples_thumb.gif',130, 321,0, 0,'','','','');
photos[14] = new photo(734275,'','','','Couples-Claire-and-Chris1.gif',432,334,'','Couples-Claire-and-Chris1_thumb.gif',130, 101,0, 0,'','','','');
photos[15] = new photo(734291,'','','','David-&-Claire-043-couples.gif',432,288,'','David-&-Claire-043-couples_thumb.gif',130, 87,0, 0,'','','','');
photos[16] = new photo(734293,'56620','','gallery','Claire-and-Chris-1couples.gif',288,365,'','Claire-and-Chris-1couples_thumb.gif',130, 165,0, 0,'','','','');
photos[17] = new photo(734294,'','','','Claire-and-Chris-couples.gif',288,341,'','Claire-and-Chris-couples_thumb.gif',130, 154,0, 0,'','','','');
photos[18] = new photo(734295,'56620','','gallery','Claire-and-Chris-couples1.gif',288,341,'','Claire-and-Chris-couples1_thumb.gif',130, 154,0, 0,'','','','');
photos[19] = new photo(797139,'56612','','gallery','Dress fixing.jpg',500,427,'','Dress fixing_thumb.jpg',130, 111,0, 0,'','','','');
photos[20] = new photo(813612,'56612','','gallery','Ally-18.gif',280,402,'','Ally-18_thumb.gif',130, 187,0, 0,'','','','');
photos[21] = new photo(813657,'56720','','gallery','tiny-foot.gif',500,462,'','tiny-foot_thumb.gif',130, 120,0, 1,'','','','');
photos[22] = new photo(813662,'56720','','gallery','Keekaboo-Archie.gif',500,424,'','Keekaboo-Archie_thumb.gif',130, 110,0, 0,'','','','');
photos[23] = new photo(813671,'56720','','gallery','Archie-Oliver-John-Reid-040.gif',500,594,'','Archie-Oliver-John-Reid-040_thumb.gif',130, 154,0, 0,'','','','');
photos[24] = new photo(813677,'56720','','gallery','Archie-Oliver.gif',500,543,'','Archie-Oliver_thumb.gif',130, 141,0, 0,'','','','');
photos[25] = new photo(813680,'56720','','gallery','Archie.gif',500,388,'','Archie_thumb.gif',130, 101,0, 0,'','','','');
photos[26] = new photo(813740,'63084','','gallery','brides-veil.gif',500,605,'','brides-veil_thumb.gif',130, 157,0, 1,'','','','');
photos[27] = new photo(813741,'63084','','gallery','mood-shot-copy.gif',500,352,'','mood-shot-copy_thumb.gif',130, 92,0, 0,'','','','');
photos[28] = new photo(813748,'63084','','gallery','boys-at-window.gif',500,467,'','boys-at-window_thumb.gif',130, 121,0, 0,'','','','');
photos[29] = new photo(830225,'56720','','gallery','IMG_3375-a.gif',500,469,'','IMG_3375-a_thumb.gif',130, 122,0, 0,'','','','');
photos[30] = new photo(830235,'56720','','gallery','IMG_3637mono1.gif',500,295,'','IMG_3637mono1_thumb.gif',130, 77,0, 0,'','','','');
photos[31] = new photo(732973,'55651','','gallery','IMG_12873.jpg',500,431,'Capturing a moment','IMG_12873_thumb.jpg',130, 112,1, 1,'','','','');
photos[32] = new photo(732980,'55651','','gallery','IMG_12481.jpg',500,624,'','IMG_12481_thumb.jpg',130, 162,0, 0,'','','','');
photos[33] = new photo(734108,'55651','','gallery','Archie-1.gif',432,288,'Archie','Archie-1_thumb.gif',130, 87,0, 0,'','','','');
photos[34] = new photo(734109,'55651','','gallery','Archie-2.gif',432,288,'Archie ','Archie-2_thumb.gif',130, 87,0, 0,'','','','');
photos[35] = new photo(734111,'55651','','gallery','Archie3.gif',288,432,'Archie','Archie3_thumb.gif',130, 195,0, 0,'','','','');
photos[36] = new photo(734126,'55651','','gallery','Baby-Rhys.gif',288,432,'Rhys','Baby-Rhys_thumb.gif',130, 195,0, 0,'','','','');
photos[37] = new photo(734127,'55651','','gallery','Baby-Rhys-2.gif',288,432,'','Baby-Rhys-2_thumb.gif',130, 195,0, 0,'','','','');
photos[38] = new photo(734134,'55651','','gallery','child.gif',288,432,'','child_thumb.gif',130, 195,0, 0,'','','','');
photos[39] = new photo(734135,'55651','','gallery','child-Jack.gif',288,379,'','child-Jack_thumb.gif',130, 171,0, 0,'','','','');
photos[40] = new photo(734138,'55651','','gallery','Child-Jack-21.gif',230,474,'','Child-Jack-21_thumb.gif',130, 268,0, 0,'','','','');
photos[41] = new photo(734141,'55651','','gallery','child-section-Jack.gif',288,420,'','child-section-Jack_thumb.gif',130, 190,0, 0,'','','','');
photos[42] = new photo(734143,'55651','','gallery','Boys-off-to-play-children.gif',177,382,'','Boys-off-to-play-children_thumb.gif',130, 281,0, 0,'','','','');
photos[43] = new photo(734144,'55651','','gallery','Cian-2-children.gif',198,373,'','Cian-2-children_thumb.gif',130, 245,0, 0,'','','','');
photos[44] = new photo(734146,'55651','','gallery','Cian-3-children.gif',311,311,'','Cian-3-children_thumb.gif',130, 130,0, 0,'','','','');
photos[45] = new photo(734147,'55651','','gallery','Cian-children.gif',230,295,'','Cian-children_thumb.gif',130, 167,0, 0,'','','','');
photos[46] = new photo(734149,'55651','','gallery','Dezil-boy-babies.gif',432,288,'','Dezil-boy-babies_thumb.gif',130, 87,0, 0,'','','','');
photos[47] = new photo(734150,'55651','','gallery','Lennon-chidren.gif',421,421,'','Lennon-chidren_thumb.gif',130, 130,0, 0,'','','','');
photos[48] = new photo(734151,'55651','','gallery','little-family-children.gif',432,270,'','little-family-children_thumb.gif',130, 81,0, 0,'','','','');
photos[49] = new photo(734170,'55651','','gallery','oh-dear-dirty-hands-Child.gif',432,299,'','oh-dear-dirty-hands-Child_thumb.gif',130, 90,0, 0,'','','','');
photos[50] = new photo(734171,'55651','','gallery','Smiley-little-dezil--babies.gif',424,424,'','Smiley-little-dezil--babies_thumb.gif',130, 130,0, 0,'','','','');
photos[51] = new photo(734175,'55651','','gallery','Rhys-2.gif',288,432,'','Rhys-2_thumb.gif',130, 195,0, 0,'','','','');
photos[52] = new photo(734179,'55651','','gallery','Rhys-bubble-chaser.gif',288,411,'','Rhys-bubble-chaser_thumb.gif',130, 186,0, 0,'','','','');
photos[53] = new photo(734182,'55651','','gallery','Rhys-enjoying-a-tasty-snack.gif',288,356,'','Rhys-enjoying-a-tasty-snack_thumb.gif',130, 161,0, 0,'','','','');

/***************************************************************************
* Create the array of Gallery objects                                      *
***************************************************************************/
galleries = new Array();
galleries[0] = new gallery(56720,'813657','Bumps and beyond','gallery');
galleries[1] = new gallery(56620,'734295,734293','Couples','gallery');
galleries[2] = new gallery(56619,'734216,734213,734209,734207,734204,734201,734199,734198,734197,734196','Families','gallery');
galleries[3] = new gallery(56612,'813612,797139,734123,734122,734120','portraits','gallery');
galleries[4] = new gallery(63084,'813740','Weddings','gallery');
galleries[5] = new gallery(55651,'732973','Babies and children','gallery');

