/***************************************************************************
* 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('548868,395062,381448,352272,352271,352267,350809,227338,224253,224251,222414,222412,222408');
	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('548868,395062,381448,352272,352271,352267,350809,227338,224253,224251,222414,222412,222408');
	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="images/' + 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 && !(1)) {
		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;
			/* 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 = '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(222750,'','','','Printed with TitleJPG.jpg',400,283,'Image with Title','Printed with TitleJPG_thumb.jpg',130, 92,0, 0,'','','','');
photos[1] = new photo(222751,'','','','Pano with TitleJPG.jpg',400,283,'Panorama with Title','Pano with TitleJPG_thumb.jpg',130, 92,0, 0,'','','','');
photos[2] = new photo(222752,'','','','Printed No TitleJPG.jpg',400,283,'Image with No Title','Printed No TitleJPG_thumb.jpg',130, 92,0, 0,'','','','');
photos[3] = new photo(222754,'','','','Pano No TitleJPG.jpg',400,283,'Panorama with No Title','Pano No TitleJPG_thumb.jpg',130, 92,0, 0,'','','','');
photos[4] = new photo(350808,'29077','','gallery','AntrimCoastTriptychJPG.jpg',400,585,'Antrim Coast Triptych','AntrimCoastTriptychJPG_thumb.jpg',130, 190,0, 0,'Three panoramas to show the beauty of the Antrim Coast','','David Robinson ARPS','Co Antrim, Northern Ireland');
photos[5] = new photo(350809,'29077','','gallery','BenbaneHeadJPG.jpg',400,213,'Benbane Head','BenbaneHeadJPG_thumb.jpg',130, 69,1, 1,'Taken from the White Rocks area with a big sea after a storm','','David Robinson ARPS','Co Antrim, Northern Ireland');
photos[6] = new photo(395062,'29077','','gallery','CarrackaradeIsland001.jpg',400,209,'Carrick-a-Rede','CarrackaradeIsland001_thumb.jpg',130, 68,1, 1,'Shows the dramatic setting of the famous rope bridge which gives access to the salmon fishery on Carrick Island','','David Robinson ARPS','North Antrim, N Ireland');
photos[7] = new photo(381448,'29077','','gallery','antrimcoasttriptych2JPG.jpg',400,585,'Antrim Coast Triptych 2','antrimcoasttriptych2JPG_thumb.jpg',130, 190,1, 1,'','','David Robinson ARPS','');
photos[8] = new photo(352271,'29077','','gallery','StraidkillyPoint2JPG.jpg',400,625,'Straidkilly Point (portrait format)','StraidkillyPoint2JPG_thumb.jpg',130, 203,1, 1,'Looking across Carnlough Bay to Garron Point','','David Robinson ARPS','Co Antrim, Northern Ireland - Coast Road');
photos[9] = new photo(352272,'29077','','gallery','StraidkillyPointJPG.jpg',400,281,'Straidkilly Point','StraidkillyPointJPG_thumb.jpg',130, 91,1, 1,'A great spot for picnic!','','David Robinson ARPS','');
photos[10] = new photo(352267,'29077','','gallery','DunluceCastleB&WJPG.jpg',400,305,'Dunluce Castle','DunluceCastleB&WJPG_thumb.jpg',130, 99,1, 1,'Under storm clouds but with light picking up the sea colours','','David Robinson ARPS','Co Antrim, Northern Ireland');
photos[11] = new photo(548868,'29077','','gallery','White Rocks StrandJPG.jpg',400,213,'White Rocks Strand','White Rocks StrandJPG_thumb.jpg',130, 69,1, 1,'','','David Robinson ARPS','Co. Antrim, N Ireland');
photos[12] = new photo(222408,'19672','','gallery','East Strand PortrushJPG.jpg',400,287,'East Strand, Portrush','East Strand PortrushJPG_thumb.jpg',130, 93,1, 0,'A blustery, showery day, great for a walk!','','David Robinson ARPS','Portrush, Northern Ireland');
photos[13] = new photo(222412,'19672','','gallery','Lough Foyle 2JPG.jpg',400,283,'Lough Foyle','Lough Foyle 2JPG_thumb.jpg',130, 92,1, 1,'A rare combination of a great sky in late afternoon with the tide out.','','David Robinson ARPS','Lough Foyle, Northern Ireland');
photos[14] = new photo(222413,'19672','','gallery','Lough FoyleJPG.jpg',400,230,'Lough Foyle Panorama','Lough FoyleJPG_thumb.jpg',130, 75,0, 0,'A great sky, tide out and an old boat - photographer\'s heaven!','','David Robinson ARPS','Lough Foyle, Northern Ireland');
photos[15] = new photo(222414,'19672','','gallery','Magilligan StrandJPG.jpg',400,307,'Magilligan Strand','Magilligan StrandJPG_thumb.jpg',130, 100,1, 0,'Taken at Benone in early December, hence no tourists!','','David Robinson ARPS','Magilligan Strand,Northern Ireland');
photos[16] = new photo(222416,'19672','','gallery','The SkeriesJPG.jpg',400,299,'The Skerries','The SkeriesJPG_thumb.jpg',130, 97,0, 1,'Taken from East Strand with ultra-wide angle lens. I had a long wait for the right lighting.','','David Robinson','Portrush Northern Ireland');
photos[17] = new photo(222421,'19672','','gallery','The Skerries 2JPG.jpg',257,400,'The Skerries 2','The Skerries 2JPG_thumb.jpg',130, 202,0, 0,'The Skerries taken from White Rocks beach.  The Sky and sand colours work well together.','','David Robinson','White Rocks, Portrush');
photos[18] = new photo(222423,'19672','','gallery','The White RocksJPG.jpg',400,211,'The White Rocks','The White RocksJPG_thumb.jpg',130, 69,0, 0,'A cold, wet day with big rollers coming in and just the occasional flash of sunlight.','','David Robinson ARPS','White Rocks, Co.Antrim, N.Ireland');
photos[19] = new photo(228126,'19672','','gallery','Loch Foyle 3JPG.jpg',259,400,'Lough Foyle 3','Loch Foyle 3JPG_thumb.jpg',130, 201,0, 0,'Portrait format - unusual for landscape photography but worthit sometimes','','David Robinson ARPS','Lough Foyle, N.Ireland');
photos[20] = new photo(224250,'20039','','gallery','Capella Di VitaletaJPG.jpg',400,224,'Capella Di Vitaleta','Capella Di VitaletaJPG_thumb.jpg',130, 73,0, 0,'Key was to wait for light on the chapel with a cloud shadow behind.','','David Robinson ARPS','Nr Pienza, Tuscany, Italy');
photos[21] = new photo(224251,'20039','','gallery','Cypresses MonoJPG.jpg',400,243,'Cypresses (mono)','Cypresses MonoJPG_thumb.jpg',130, 79,1, 0,'I was fascinated by the play of cloud shadows on a rolling landscape bare of vegetation except for these trees.','','David Robinson ARPS','Tuscany, Italy');
photos[22] = new photo(224253,'20039','','gallery','CypressesJPG.jpg',400,244,'Cypresses','CypressesJPG_thumb.jpg',130, 79,1, 1,'A colour version which tries to retain the gritty quality of the autumn landscape of Tuscany','','David Robinson ARPS','Tuscany, Italy');
photos[23] = new photo(224254,'20039','','gallery','Cyrpess AvenueJPG.jpg',400,237,'Avenue of Cypresses','Cyrpess AvenueJPG_thumb.jpg',130, 77,0, 0,'A fantastic sky with the avenue leading the eye to the hilltop farm.','','David Robinson ARPS','Tuscany, Italy');
photos[24] = new photo(224259,'20039','','gallery','Tuscan AutumnJPG.jpg',400,255,'Tuscan Autumn','Tuscan AutumnJPG_thumb.jpg',130, 83,0, 0,'A colour version of Cypress Avenue which also works for me.','','David Robinson ARPS','Tuscany Italy');
photos[25] = new photo(224261,'20039','','gallery','Tuscan LandscapesJPG.jpg',400,283,'Tuscan Landscapes','Tuscan LandscapesJPG_thumb.jpg',130, 92,0, 0,'A selection of landscapes - designed to work best on A3.','','David Robinson ARPS','Tuscany, Italy');
photos[26] = new photo(224263,'20039','','gallery','Tuscan VillageJPG.jpg',224,400,'Tuscan Village','Tuscan VillageJPG_thumb.jpg',130, 232,0, 0,'A hilltop village typical of many in the region.','','David Robinson ARPS','Tuscany, Italy');
photos[27] = new photo(225059,'20040','','gallery','Eiffel TowerJPG.jpg',286,400,'Tour Eiffel','Eiffel TowerJPG_thumb.jpg',130, 182,0, 0,'','','David Robinson ARPS','Paris');
photos[28] = new photo(227338,'20040','','gallery','Quai D\'OrleansJPG1.jpg',287,400,'Quai D\'Orleans','Quai D\'OrleansJPG1_thumb.jpg',130, 181,1, 1,'','','David Robinson ARPS','Paris');
photos[29] = new photo(225062,'20040','','gallery','Notre DameJPG.jpg',285,400,'Notre Dame','Notre DameJPG_thumb.jpg',130, 182,0, 1,'','','David Robinson ARPS','Paris');
photos[30] = new photo(225063,'20040','','gallery','Nortre Dame 2JPG.jpg',287,400,'Notre Dame 2','Nortre Dame 2JPG_thumb.jpg',130, 181,0, 0,'','','David Robinson ARPS','Paris');
photos[31] = new photo(224255,'20042','','gallery','Lone TreeJPG.jpg',400,213,'Lone Tree','Lone TreeJPG_thumb.jpg',130, 69,0, 1,'Using a long lens and panoramic crop gave an image evocative of the place and season.','','David Robinson ARPS','Tuscany, Italy');
photos[32] = new photo(224256,'20042','','gallery','Pano CapellaJPG.jpg',400,188,'Capella Di Vitaleta (pano)','Pano CapellaJPG_thumb.jpg',130, 61,0, 1,'A beautiful location which invited a panoramic treatment.','','David Robinson ARPS','Nr Piennza, Tuscany, Italy');
photos[33] = new photo(225064,'20042','','gallery','FlorenceJPG.jpg',400,220,'Florence','FlorenceJPG_thumb.jpg',130, 72,0, 0,'Taken just after getting soaked in a thunder storm!','','David Robinson ARPS','Italy');
photos[34] = new photo(225065,'20042','','gallery','hill top farmJPG.jpg',400,197,'Hilltop Farm','hill top farmJPG_thumb.jpg',130, 64,0, 0,'','','David Robinson ARPS','Tuscany');

/***************************************************************************
* Create the array of Gallery objects                                      *
***************************************************************************/
galleries = new Array();
galleries[0] = new gallery(29077,'548868,395062,381448,352272,352271,352267,350809','New Images','gallery');
galleries[1] = new gallery(19672,'222416,222412','Northern Ireland','gallery');
galleries[2] = new gallery(20039,'224253','Tuscany','gallery');
galleries[3] = new gallery(20040,'227338,225062','Paris','gallery');
galleries[4] = new gallery(20042,'224256,224255','Panoramas','gallery');

