/***************************************************************************
* 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('37969,37968,37955,37954,37950,37948,37946,37943,37940,37938,37935');
	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('37969,37968,37955,37954,37950,37948,37946,37943,37940,37938,37935');
	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">');
						}
			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 (photos[j].galleries_id != '') {
				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;
			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(345621,'28853','','gallery','balconies.jpg',400,533,'Balconies','balconies_thumb.jpg',130, 173,0, 1,'Block of flats in Plymouth from a recent visit ','','','');
photos[1] = new photo(345622,'28853','','gallery','church-and-block.jpg',400,558,'new and old','church-and-block_thumb.jpg',130, 181,0, 0,'The old ruined church with the back drop of the new shopping complex  ','','','plymouth');
photos[2] = new photo(345625,'28853','','gallery','glasshouse.jpg',400,533,'glasshouse','glasshouse_thumb.jpg',130, 173,0, 0,'refection of the sky in new modern block in Plymouth','','','');
photos[3] = new photo(345627,'28853','','gallery','plymouth-block.jpg',400,365,'tower block','plymouth-block_thumb.jpg',130, 119,0, 0,'block of flats in Plymouth early summer morning','','','');
photos[4] = new photo(345628,'28853','','gallery','tower-block.jpg',400,512,'block of flats','tower-block_thumb.jpg',130, 166,0, 0,'from a recent visit to Plymouth','','','');
photos[5] = new photo(345630,'28853','','gallery','plymouth-james-church.jpg',400,578,'the ruined church','plymouth-james-church_thumb.jpg',130, 188,0, 0,'The juxapostion of old and new in Plymouth','','','');
photos[6] = new photo(345631,'28853','','gallery','glasswall.jpg',400,454,'glass wall','glasswall_thumb.jpg',130, 148,0, 0,'detail of new building and relections','','','');
photos[7] = new photo(74007,'3901','','gallery','cornfield ringmer.jpg',400,271,'Movement ','cornfield ringmer_thumb.jpg',130, 88,0, 0,'light catches the corn as the wind stirs the crop creating movement','','Robin Earl LRPS','Ringmer ,East Sussex');
photos[8] = new photo(74010,'3901','','gallery','the glade.jpg',400,133,'The glade','the glade_thumb.jpg',130, 43,0, 0,'Shafts of evening light reach deep into the glade<br>\nvivid bright greens in the field beyond<br>\nGiclee A3 prints £45 excludes post and packing','','Robin Earl LRPS','Rushlake Green in East Sussex');
photos[9] = new photo(37968,'3901','','gallery','windswept.jpg',400,286,'windswept','windswept_thumb.jpg',130, 93,1, 1,'Windswept cornfield high on the Sussex Downs ,movement and light at sunset<br>\nGiclee print A3 £45 excludes post and packing','','Robin Earl','Sompting West Sussex');
photos[10] = new photo(37935,'3901','','gallery','cornfield.jpg',400,417,'Cornfield','cornfield_thumb.jpg',130, 136,1, 1,'Golden cornfield under a vivid blue sky torn by a white cloud <br>\nAs featured in Digital Photo magazine July 2005<br>\nA3 giclee print £45 each excludes post and packing ','','Robin Earl','Lancing West Sussex');
photos[11] = new photo(37937,'3901','','gallery','cow and gate.jpg',400,267,'Cow and Gate','cow and gate_thumb.jpg',130, 87,0, 0,'Early morning on Pevensey levels a cow in profile by a sluice gate looming out of the mist.<br>\nA3 giclee print £45 excludes post and packing  ','','Robin Earl','Pevensey Marsh, East Sussex');
photos[12] = new photo(37943,'3901','','gallery','misty gate.jpg',400,259,'Misty gate','misty gate_thumb.jpg',130, 84,1, 1,'A gate to nowhere on marshland in October a view to a sunrise beyond.<br>\nA3 giclee print £45 excludes post and packing','','Robin Earl','Pevensey Levels');
photos[13] = new photo(37948,'3901','','gallery','scorhill.jpg',400,502,'Scorhill stone circle','scorhill_thumb.jpg',130, 163,1, 1,'Scorhill stone circle very early morning in July the moon pointed out by a megalithic finger.<br>\nA3 giclee print £45 excludes post and packing ','','Robin Earl','Scorhill Devon Dartmoor');
photos[14] = new photo(37950,'3901','','gallery','sheep on marsh.jpg',400,247,'Sheep on the marsh','sheep on marsh_thumb.jpg',130, 80,1, 1,'Sheep approach but it is not feeding time on this bitterly cold October morning only thier hopes and the sun rise.','','Robin Earl','Pevensey marsh East Sussex');
photos[15] = new photo(37951,'3901','','gallery','shep in mist.jpg',400,257,'sheep in the mist','shep in mist_thumb.jpg',130, 84,0, 0,'Sheep laying in the rising mist.<br>\nA3 Giclee print £45 excludes post and packing    ','','Robin Earl','Battle East Sussex');
photos[16] = new photo(37969,'3901','','gallery','woods.jpg',400,263,'The woods','woods_thumb.jpg',130, 85,1, 1,'Bluebell woods reveal a scuplture or a hiding place,who knows?<br>\nA3 giclee print £45 excludes post and packing','','Robin Earl','Old Heathfield in East Sussex');
photos[17] = new photo(37931,'3958','','gallery','bowl ak.jpg',400,245,'Ceramic bowl made by Adrienne Kreil','bowl ak_thumb.jpg',130, 80,0, 0,'Ceramic bowel with rich metal rim glaze','','Robin Earl','Blackboys');
photos[18] = new photo(37956,'3958','','gallery','tall green.jpg',400,576,'Tall pot by Matthew Bayman of Blackboys Sharlands Farm','tall green_thumb.jpg',130, 187,0, 1,'Tall green pot as made by Matthew Bayman','','Robin Earl','Blackboys');
photos[19] = new photo(37958,'3958','','gallery','three pots.jpg',400,345,'Three pots by Matthew Bayman of Sharlands Farm Blackboys','three pots_thumb.jpg',130, 112,0, 1,'Three pots made by Matthew Bayman','','Robin Earl','Blackboys');
photos[20] = new photo(37957,'3958','','gallery','three pots nite lite.jpg',400,319,'three pots with nite light made by Matthew Bayman of Sharlands Farm, Blackboys','three pots nite lite_thumb.jpg',130, 104,0, 1,'Three pots as made by Matthew Bayman','','Robin Earl','Blackboys');
photos[21] = new photo(74001,'3959','','gallery','poppy field print.jpg',400,234,'poppyfield','poppy field print_thumb.jpg',130, 76,0, 0,'Back lit poppies and dasiy flowers at sunset on the South Downs  ','','Robin Earl LRPS','Brighton South Downs');
photos[22] = new photo(37927,'3959','','gallery','bee.jpg',400,907,'Split second timing required','bee_thumb.jpg',130, 295,0, 1,'Honey bee entering Foxglove flowers the only frame that worked out of four rolls of film.<br>\nGiclee print A3 £45 excludes post and packing','','Robin Earl','East Sussex');
photos[23] = new photo(37954,'3959','','gallery','starlings in blizzard.jpg',400,253,'Starlings in a blizzard','starlings in blizzard_thumb.jpg',130, 82,1, 1,'Starlings finding no shelter from the blizzard in a bare apple tree.I find no shelter either so this is the only photograph I took.','','Robin Earl','Battle East Sussex');
photos[24] = new photo(74004,'3960','','gallery','cliff sunset birling pan.jpg',400,150,'sunset from Birling Gap','cliff sunset birling pan_thumb.jpg',130, 49,0, 0,'Stunning sky and waves gently fall onto the beach at Severn Sisters cliffs','','Robin Earl LRPS','Birling Gap to the Severn Sisters');
photos[25] = new photo(37929,'3960','','gallery','birling gap beach.jpg',400,552,'Birling Gap beach','birling gap beach_thumb.jpg',130, 179,0, 0,'Dramatic cliffs and interesting shoreline in winter sun and vivi blue skies.<br>\nA3 giclee print £45 excludes post and packing','','Robin Earl','Birling Gap in East Sussex');
photos[26] = new photo(37930,'3960','','gallery','boats on river adur.jpg',400,264,'Boats on the River Adur in Shoreham ','boats on river adur_thumb.jpg',130, 86,0, 0,'Boats bob on the River Adur under a lilac sky at sunset.Movement blurs the water<br>\nA3 giclee print £45 excludes post and packing ','','Robin Earl','Shoreham in West Sussex');
photos[27] = new photo(37936,'3960','','gallery','couple on st agnus beach.jpg',400,476,'Couple on St Agnus beach','couple on st agnus beach_thumb.jpg',130, 155,0, 0,'Beautiful sunset a private moment for a couple walking ouy in the evening light<br>\nA3 giclee prit £45 excludes post and packing','','Robin Earl','Cornwall St Agnus');
photos[28] = new photo(37938,'3960','','gallery','dusk river adur.jpg',400,256,'Dusk on the river Adur','dusk river adur_thumb.jpg',130, 83,1, 1,'Dusk on the lilac coloured river blurred with the tide.A stunning sunset<br>\nA3 giclee print £45 excludes post and packing','','Robin Earl','Shoreham in West Sussex');
photos[29] = new photo(37940,'3960','','gallery','fairlight cliffs.jpg',400,499,'Fairlight Cliffs','fairlight cliffs_thumb.jpg',130, 162,1, 1,'The storm clouds gather over the cliffs at Fairlight moments latter the light changes and then the rain starts.<br>\nA3 giclee print £45 excludes post and packing','','Robin Earl','Hastings in East Sussex');
photos[30] = new photo(37944,'3960','','gallery','old toll bridge.jpg',400,457,'Old toll bridge','old toll bridge_thumb.jpg',130, 149,0, 1,'The old toll bridge across the River Adur at low tide.','','Robin Earl','Shoreham in West Sussex');
photos[31] = new photo(37949,'3960','','gallery','seagulls.jpg',400,265,'Seagulls','seagulls_thumb.jpg',130, 86,0, 1,'Seagulls feeding time the scraps on Hastings Beach.<br>\nA3 giclee print £45 excludes post and packing','','Robin Earl','Hastings East Sussex');
photos[32] = new photo(37941,'3960','','gallery','hastings harbour arm.jpg',400,905,'Hastings harbour arm. ','hastings harbour arm_thumb.jpg',130, 294,0, 0,'The arm reaches out into the sea a splash of red midway for safety and to mark out danger.<br>\nA3 giclee print £45 excludes post and packing','','Robin Earl','Hastings in East Sussex');
photos[33] = new photo(37953,'3960','','gallery','st agnus beach.jpg',400,294,'St Agnus beach Cornwall','st agnus beach_thumb.jpg',130, 96,0, 1,'Sunset golden sky and light falling on a remote peaceful beach<br>\nA3 giclee print £45 excludes post and packing','','Robin Earl','St Agnus in Cornwall');
photos[34] = new photo(37946,'3960','','gallery','river adur at dusk.jpg',400,263,'River Adur at Dusk','river adur at dusk_thumb.jpg',130, 85,1, 1,'Dramatic sky and vivid colours at sunset,boats bob with the tide.Lancing College stands in the distance.<br>\nA3 giclee print £45 excludes post and packing','','Robin Earl','Shoreham in West Sussex');
photos[35] = new photo(37955,'3960','','gallery','sunset and crescent moon.jpg',400,271,'crescent moon','sunset and crescent moon_thumb.jpg',130, 88,1, 1,'In the golden yellow sky the youngest of moons hangs low a good search will find it!<br>\nA3 giclee print £45 excludes post and packing','','Robin Earl','Shoreham in West Sussex');
photos[36] = new photo(73999,'3960','','gallery','on birling gap.jpg',400,236,'Willow structure ','on birling gap_thumb.jpg',130, 77,0, 0,'A willow frame like a pair of sails sits on top of the cliffs near Birling Gap,just do not step back too far to get a good photo!<br>\nA3 giclee print £45 excludes post and packing','','Robin Earl','Birling Gap in East Sussex');
photos[37] = new photo(37960,'3961','','gallery','west pier decay.jpg',400,341,'West Pier decaying','west pier decay_thumb.jpg',130, 111,0, 1,'The West Pier , Brighton as it may never be seen again.','','Robin Earl','brighton');
photos[38] = new photo(37961,'3961','','gallery','west pier decking.jpg',400,215,'west pier decking','west pier decking_thumb.jpg',130, 70,0, 1,'The deck of the now missing west pier in Brighton','','Robin Earl','brighton');
photos[39] = new photo(37962,'3961','','gallery','west pier in ballroom.jpg',400,313,'west pier ballroom','west pier in ballroom_thumb.jpg',130, 102,0, 1,'Ballroom inside view of now destroyed West Pier in Brighton ','','Robin Earl','brighton');
photos[40] = new photo(37963,'3961','','gallery','west pier main entrance.jpg',400,277,'west pier main building','west pier main entrance_thumb.jpg',130, 90,0, 1,'The front of the main building on the West Pier off Brighton','','Robin Earl','brighton');
photos[41] = new photo(37964,'3961','','gallery','west pier pavillion.jpg',400,185,'west pier pavillion','west pier pavillion_thumb.jpg',130, 60,0, 1,'Pavillion on the West Pier , Brighton ','','Robin Earl','brighton');
photos[42] = new photo(37965,'3961','','gallery','west pier to beach.jpg',400,300,'the beach from the West Pier','west pier to beach_thumb.jpg',130, 98,0, 0,'A view that cannot be witnessed any more from the West Pier in Brighton','','Robin Earl','brighton');
photos[43] = new photo(37932,'3962','','gallery','bristol balloons 2.jpg',400,320,'Bristol Balloon Fiesta 2004','bristol balloons 2_thumb.jpg',130, 104,0, 0,'2004 event at Bristol evening liftoff','','Robin Earl','Bristol Ashton Court');
photos[44] = new photo(37933,'3962','','gallery','bristol balloons 6.jpg',400,521,'Bristol Balloon Fiesta 2004 ','bristol balloons 6_thumb.jpg',130, 169,0, 0,'Liftoff from Ashton Court Bristol','','Robin Earl','Bristol Ashton Court');
photos[45] = new photo(37934,'3962','','gallery','bristol balloons 7.jpg',400,293,'Evening glow at Bristol balloon fiesta 2004','bristol balloons 7_thumb.jpg',130, 95,0, 1,'evening glow event at Britol Fiesta ','','Robin Earl','Bristol Ashton Court');
photos[46] = new photo(37928,'3963','','gallery','360 view office.jpg',400,114,'Panoramic view of office space','360 view office_thumb.jpg',130, 37,0, 0,'Can also used as a virtual tour in Quicktime media mode','','Robin Earl','West Sussex Shoreham');
photos[47] = new photo(37942,'3963','','gallery','manicure area.jpg',400,290,'The Salon ','manicure area_thumb.jpg',130, 94,0, 1,'Used to promte a new beauty salon','','Robin Earl','Eastbourne');
photos[48] = new photo(37939,'3963','','gallery','eastbourne harbour 360 view.jpg',400,109,'panoramic view of Eastbourne harbour','eastbourne harbour 360 view_thumb.jpg',130, 35,0, 0,'Full 360 degree view of Eastbourne Harbour can also be used as a quicktime movie virtual tour','','Robin Earl','Eastbourne');
photos[49] = new photo(37945,'3963','','gallery','pedicure.jpg',400,287,'Pedicure','pedicure_thumb.jpg',130, 93,0, 0,'Photo taken to promote local business','','Robin Earl','Eastbourne');
photos[50] = new photo(37947,'3963','','gallery','sauna.jpg',400,450,'the sauna','sauna_thumb.jpg',130, 146,0, 0,'The sauna at local beauty salon','','Robin Earl','Eastbourne');

/***************************************************************************
* Create the array of Gallery objects                                      *
***************************************************************************/
galleries = new Array();
galleries[0] = new gallery(28853,'345621','Architecture','gallery');
galleries[1] = new gallery(3901,'37969,37968,37950,37948,37943,37935','Landscapes','gallery');
galleries[2] = new gallery(3958,'37958,37957,37956','Products','gallery');
galleries[3] = new gallery(3959,'37954,37927','Natural world ','gallery');
galleries[4] = new gallery(3960,'37955,37953,37949,37946,37944,37940,37938','The sea and water ','gallery');
galleries[5] = new gallery(3961,'37964,37963,37962,37961,37960','West Pier','gallery');
galleries[6] = new gallery(3962,'37934','Ballooning','gallery');
galleries[7] = new gallery(3963,'37942','Commercial','gallery');

