/***************************************************************************
* Create a photo object                                                    *
***************************************************************************/
function photo(id,galleries_id,src,width,height,caption,thumbnail,thumbnail_width,thumbnail_height,home,gallery,description,takendate,photographer,location) {
	this.id = id;
	this.galleries_id = galleries_id;
	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) {
	this.id = id;
	this.featured_images = featured_images;
	this.title = title;
}

/***************************************************************************
* 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('130722,130714,130711,130706,130701,125630,125616,125604,125591,125571,125564,125558,125542,125535,125534,125533,125532,125517,125514,125482,125473,125437,125435,125432,125426,125425');
	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;
		}
	}
}

/***************************************************************************
***************************************************************************/
function showHomeImageInline() {
	
	imageID = randomListVal('130722,130714,130711,130706,130701,125630,125616,125604,125591,125571,125564,125558,125542,125535,125534,125533,125532,125517,125514,125482,125473,125437,125435,125432,125426,125425');
	for (j = 0; j < photos.length; j++) {
		if (photos[j].id == imageID) {
			document.write('<img src="images/' + photos[j].src + '" width="' + photos[j].width + '" height="' + photos[j].height + '" class="homepageimage" id="mainSample" name="mainSample" alt="' + photos[j].caption  + '" border="0">');
			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.all.imagePhoto.innerHTML = '<img class="galleryimage" 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 = '<strong>' + photos[nextImg].caption + '</strong>';
			temp = ''
			temp = temp +  '<div style="margin-bottom:12px" class="normal">' + photos[nextImg].description + '</div>';
			
			debug('Taken date is ' + photos[nextImg].takendate);
			
			if (photos[nextImg].takendate != '') {
				debug('Resetting taken date');
				temp = temp + '<div class="normal"><strong>Date: </strong>' + photos[nextImg].takendate + '</div>';
			}
			
			if (photos[nextImg].location != '') {
				debug('Resetting location');
				temp = temp + '<div class="normal"><strong>Location: </strong>' +  photos[nextImg].location + '</div>';
			}
			
			if (photos[nextImg].photographer != '') {
				debug('Resetting photographer');
				temp = temp + '<div class="normal"><strong>Photographer: </strong>' + photos[nextImg].photographer + '</div>';
			}
			
					if (temp == '') {
			document.getElementById('imageCopy').style.visibility = 'hidden';
		}
		else {
			document.getElementById('imageCopy').style.visibility = 'visible';
		}
		document.getElementById('imageCopy').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) {

	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(125425,11027,'PG Fell Farm 2.jpg',400,342,'Fell Farm','PG Fell Farm 2_thumb.jpg',130, 111,1, 1,'','','','');
photos[1] = new photo(125426,11027,'PG August Storm1.jpg',400,342,'August Storm','PG August Storm1_thumb.jpg',130, 111,1, 1,'','','','');
photos[2] = new photo(125428,11027,'PG Beacon Hill1.jpg',400,342,'Beacon Hill','PG Beacon Hill1_thumb.jpg',130, 111,0, 0,'','','','');
photos[3] = new photo(125430,11027,'PG Harvest Cottage.jpg',400,342,'Harvest Cottage','PG Harvest Cottage_thumb.jpg',130, 111,0, 0,'','','','');
photos[4] = new photo(125432,11027,'PG Harvest Moon copy.jpg',400,342,'Harvest Moon','PG Harvest Moon copy_thumb.jpg',130, 111,1, 0,'','','','');
photos[5] = new photo(125435,11027,'PG Headland.jpg',400,342,'Headland','PG Headland_thumb.jpg',130, 111,1, 1,'','','','');
photos[6] = new photo(125437,11027,'PG Meadow Lane1.jpg',400,342,'Meadow Lane ','PG Meadow Lane1_thumb.jpg',130, 111,1, 1,'','','','');
photos[7] = new photo(125473,11027,'PG New Moon.jpg',400,342,'New Moon','PG New Moon_thumb.jpg',130, 111,1, 1,'','','','');
photos[8] = new photo(125475,11027,'PG Tern copy.jpg',400,342,'Tern','PG Tern copy_thumb.jpg',130, 111,0, 0,'','','','');
photos[9] = new photo(125477,11027,'PG Tree Ridge copy.jpg',400,342,'Tree Ridge','PG Tree Ridge copy_thumb.jpg',130, 111,0, 0,'','','','');
photos[10] = new photo(125480,11027,'PG Valley Church.jpg',400,343,'Valley Church','PG Valley Church_thumb.jpg',130, 111,0, 0,'','','','');
photos[11] = new photo(125482,11027,'PG Winter Fields.jpg',400,342,'Winter Fields','PG Winter Fields_thumb.jpg',130, 111,1, 1,'','','','');
photos[12] = new photo(125485,11027,'PG Winter Sunset.jpg',400,342,'Winter Sunset','PG Winter Sunset_thumb.jpg',130, 111,0, 0,'','','','');
photos[13] = new photo(125514,11593,'SP August Fields.jpg',400,308,'August Fields','SP August Fields_thumb.jpg',130, 100,1, 1,'','','','');
photos[14] = new photo(125515,11593,'SP Autum Glade.jpg',400,308,'Autumn Glade','SP Autum Glade_thumb.jpg',130, 100,0, 0,'','','','');
photos[15] = new photo(125516,11593,'SP Autumn Leaves.jpg',400,308,'Autumn Leaves','SP Autumn Leaves_thumb.jpg',130, 100,0, 0,'','','','');
photos[16] = new photo(125517,11593,'SP Bluebell Wood.jpg',400,308,'Bluebell Wood','SP Bluebell Wood_thumb.jpg',130, 100,1, 1,'Beatrix Potter, creator of Peter Rabbit, Benjamin Bunny, Pigling Bland and others, lived at Hill Top Farm at Sawrey between the Windermere Ferry and Hawkshead in The Lake District. Her childrens books were inspired by the farms, gardens and woodlands near her home.<br><br>\n<b>Bluebell Wood</b> draws it\'s inspiration from the stories and drawings of Beatrix Potter.','','','');
photos[17] = new photo(125518,11593,'SP Bridle Way.jpg',400,308,'Bridle Way','SP Bridle Way_thumb.jpg',130, 100,0, 1,'','','','');
photos[18] = new photo(125519,11593,'SP Calm Inlet.jpg',400,308,'Calm Inlet','SP Calm Inlet_thumb.jpg',130, 100,0, 0,'The Lake District has been a source of inspiration to many writers in the past including Arthur Ransome who lived in Coniston, 1930-67 and used settings from Windermere, Coniston Water and Tarn Hows for his Swallows and Amazons books. Peel Island in Coniston Water becomes Wild Cat Island in Swallows and Amazons.<br><br>\n<b>Calm Inlet</b> draws it\'s inspiration from the stories of Arthur Ransome.','','','');
photos[19] = new photo(125520,11593,'SP Cumbrian Valley.jpg',400,308,'Cumbrian Valley','SP Cumbrian Valley_thumb.jpg',130, 100,0, 0,'','','','');
photos[20] = new photo(125522,11593,'SP Estuary Cottage.jpg',400,308,'Estuary Cottage','SP Estuary Cottage_thumb.jpg',130, 100,0, 0,'','','','');
photos[21] = new photo(125531,11593,'SP Eden Vale1.jpg',400,308,'Eden Vale','SP Eden Vale1_thumb.jpg',130, 100,0, 0,'','','','');
photos[22] = new photo(125532,11593,'SP Evening Sky.jpg',400,308,'Evening Sky','SP Evening Sky_thumb.jpg',130, 100,1, 1,'','','','');
photos[23] = new photo(125533,11593,'SP Fir lsland.jpg',400,308,'Fir Island','SP Fir lsland_thumb.jpg',130, 100,1, 1,'The Lake District has been a source of inspiration to many writers in the past including Arthur Ransome who lived in Coniston 1930-67 and used settings from Windermere and Coniston Water for his Swallows and Amazons books. Peel Island in Coniston Water becomes Wild Cat Island in Swallows and Amazons.<br><br>\n<b>Fir Island</b> draws it\'s inspiration from the stories of Arthur Ransome.','','','');
photos[24] = new photo(125534,11593,'SP Flaxen Way.jpg',400,308,'Flaxen Way','SP Flaxen Way_thumb.jpg',130, 100,1, 1,'','','','');
photos[25] = new photo(125535,11593,'SP Forest Edge.jpg',400,308,'Forest Edge','SP Forest Edge_thumb.jpg',130, 100,1, 1,'Beatrix Potter, creator of Peter Rabbit, Benjamin Bunny and others, lived at Hill Top Farm at Sawrey between the Windermere Ferry and Hawkshead in The Lake District. Her childrens books were inspired by the farms, gardens and woodlands near her home.<br><br>\n<b>Forest Edge</b> draws it\'s inspiration from the stories and drawings of Beatrix Potter.','','','');
photos[26] = new photo(125536,11593,'SP Harvest Moon.jpg',400,308,'Harvest Moon','SP Harvest Moon_thumb.jpg',130, 100,0, 0,'','','','');
photos[27] = new photo(125537,11593,'SP Holmewood.jpg',400,308,'Holme Wood','SP Holmewood_thumb.jpg',130, 100,0, 1,'','','','');
photos[28] = new photo(125538,11597,'SP Low Water.jpg',400,308,'Low Water','SP Low Water_thumb.jpg',130, 100,0, 1,'','','','');
photos[29] = new photo(125539,11597,'SP May Fields.jpg',400,308,'May Fields','SP May Fields_thumb.jpg',130, 100,0, 1,'','','','');
photos[30] = new photo(130712,11597,'SP Meadow Bank.jpg',400,308,'Meadow Bank','SP Meadow Bank_thumb.jpg',130, 100,0, 1,'','','','');
photos[31] = new photo(130713,11597,'SP Morning Light.jpg',400,308,'Morning Light','SP Morning Light_thumb.jpg',130, 100,0, 0,'The Lake District has been a source of inspiration to many writers in the past including Arthur Ransome who lived in Coniston 1930-67 and used settings from Windermere and Coniston Water for his Swallows and Amazons books. Peel Island in Coniston Water becomes Wild Cat Island in Swallows and Amazons.<br><br>\n<b>Morning Light</b> draws it\'s inspiration from the stories of Arthur Ransome.','','','');
photos[32] = new photo(130714,11597,'SP Poppies.jpg',400,308,'Poppies','SP Poppies_thumb.jpg',130, 100,1, 1,'','','','');
photos[33] = new photo(130718,11597,'SP Poppy Field.jpg',400,308,'Poppy Field','SP Poppy Field_thumb.jpg',130, 100,0, 1,'','','','');
photos[34] = new photo(130720,11597,'SP Summer Haze.jpg',400,308,'Summer Haze','SP Summer Haze_thumb.jpg',130, 100,0, 0,'','','','');
photos[35] = new photo(130721,11597,'SP Summer Walk.jpg',400,308,'Summer Walk','SP Summer Walk_thumb.jpg',130, 100,0, 0,'','','','');
photos[36] = new photo(130722,11597,'SP Water Margin.jpg',400,308,'Water Margin','SP Water Margin_thumb.jpg',130, 100,1, 1,'Beatrix Potter, creator of Peter Rabbit, Benjamin Bunny and others, lived at Hill Top Farm at Sawrey between the Windermere Ferry and Hawkshead in The Lake District. Her childrens books were inspired by the farms, gardens and woodland near her home.<br><br>\n<b>Water Margin</b> draws it\'s inspiration from the stories and drawings of Beatrix Potter.','','','');
photos[37] = new photo(130725,11597,'SP West Meadow.jpg',400,308,'West Meadow','SP West Meadow_thumb.jpg',130, 100,0, 1,'','','','');
photos[38] = new photo(130732,11597,'SP Willow Bank.jpg',400,308,'Willow Bank','SP Willow Bank_thumb.jpg',130, 100,0, 0,'','','','');
photos[39] = new photo(130738,11597,'SP Winter Walk.jpg',400,308,'Winter Walk','SP Winter Walk_thumb.jpg',130, 100,0, 1,'','','','');
photos[40] = new photo(125542,11594,'AbG Approaching Storm.jpg',400,342,'Approaching Storm','AbG Approaching Storm_thumb.jpg',130, 111,1, 1,'','','','');
photos[41] = new photo(125548,11594,'AbG Beach Pool.jpg',400,342,'Beach Pool','AbG Beach Pool_thumb.jpg',130, 111,0, 0,'','','','');
photos[42] = new photo(125554,11594,'AbG Bracken Ridge.jpg',400,342,'Bracken Ridge','AbG Bracken Ridge_thumb.jpg',130, 111,0, 1,'','','','');
photos[43] = new photo(125558,11594,'AbG Ebb Tide.jpg',400,342,'Ebb Tide','AbG Ebb Tide_thumb.jpg',130, 111,1, 1,'','','','');
photos[44] = new photo(125574,11594,'AbG Forest Light 1.jpg',400,342,'Brantwood 1','AbG Forest Light 1_thumb.jpg',130, 111,0, 1,'An abstract poetic interpretation of the woodlands surrounding Brantwood on the eastern side of Coniston Water. Home of John Ruskin, poet, art critic and philosopher from 1871.','','','');
photos[45] = new photo(125578,11594,'AbG Forest Light 2.jpg',400,342,'Brantwood 2','AbG Forest Light 2_thumb.jpg',130, 111,0, 1,'An abstract poetic interpretation of the woodlands surrounding Brantwood on the eastern side of Coniston Water. Home of John Ruskin from 1871.','','','');
photos[46] = new photo(125591,11594,'AbG Forest Light 5.jpg',400,342,'Brantwood 3','AbG Forest Light 5_thumb.jpg',130, 111,1, 0,'An abstract poetic interpretation of the woodlands surrounding Brantwood on the eastern side of Coniston Water. Home of John Ruskin from 1871.','','','');
photos[47] = new photo(125597,11594,'AbG Giverny Refections.jpg',400,342,'Giverny Reflections','AbG Giverny Refections_thumb.jpg',130, 111,0, 0,'Claude Monet said that \"These landscapes of water and reflections have become an obsession\". To his Dealer he suggested rather than calling the series <i>Reflections</i> call them <i>Water-lilies, series of waterscapes.</i><br>\n<b>Giverny Reflections</b> is an abstract interpretation based on and inspired by Monet\'s Water-lilie Paintings.','','','');
photos[48] = new photo(125600,11594,'AbG Giverny.jpg',400,342,'Giverny','AbG Giverny_thumb.jpg',130, 111,0, 0,'In 1890 Claude Monet bought his house and garden at Giverny, some 40 miles from Paris and began his Water-lilie paintings around 1899.<br>\n<b>Giverny</b> is an abstract interpretation based on and inspired by Monet\'s Water-lilie paintings.','','','');
photos[49] = new photo(125604,11594,'AbG January Sunrise.jpg',400,342,'January Sunrise','AbG January Sunrise_thumb.jpg',130, 111,1, 0,'','','','');
photos[50] = new photo(125611,11594,'AbG Moonlight.jpg',400,342,'Moonlight','AbG Moonlight_thumb.jpg',130, 111,0, 0,'','','','');
photos[51] = new photo(125616,11594,'AbG Nortern Lights.jpg',400,342,'Northern Lights','AbG Nortern Lights_thumb.jpg',130, 111,1, 1,'','','','');
photos[52] = new photo(125618,11594,'AbG Pennines.jpg',400,342,'Pennines','AbG Pennines_thumb.jpg',130, 111,0, 0,'','','','');
photos[53] = new photo(156648,11594,'AbG Brantwood G.jpg',400,342,'Brantwood Garden','AbG Brantwood G_thumb.jpg',130, 111,0, 1,'John Ruskin had many favourite walks in the gardens at Brantwood and one particular place he found inspiring is known as Ruskin\'s Seat. Here he would contemplate his writing and painting.<br><br>\nHe became an inspiration and patron to a generation of younger artists, most notably The Pre-Raphaelite Brotherhood. He was a friend of Burne-Jones, Millais, Rosetti and Holman Hunt.','','','');
photos[54] = new photo(125545,11598,'AbG Aurora.jpg',400,342,'Aurora','AbG Aurora_thumb.jpg',130, 111,0, 1,'','','','');
photos[55] = new photo(125564,11598,'Abg Estuary Sunset.jpg',400,342,'Estuary Sunset','Abg Estuary Sunset_thumb.jpg',130, 111,1, 1,'','','','');
photos[56] = new photo(125571,11598,'AbG First Snow.jpg',400,342,'First Snow','AbG First Snow_thumb.jpg',130, 111,1, 1,'','','','');
photos[57] = new photo(125625,11598,'AbG Rainbow.jpg',400,342,'Rainbow','AbG Rainbow_thumb.jpg',130, 111,0, 1,'','','','');
photos[58] = new photo(125630,11598,'AbG Sea Light.jpg',400,342,'Sea Light','AbG Sea Light_thumb.jpg',130, 111,1, 1,'','','','');
photos[59] = new photo(130629,11598,'AbG Seashore.jpg',400,342,'Seashore','AbG Seashore_thumb.jpg',130, 111,0, 1,'','','','');
photos[60] = new photo(130699,11598,'AbG Snow Margin.jpg',400,342,'Snow Margin','AbG Snow Margin_thumb.jpg',130, 111,0, 1,'','','','');
photos[61] = new photo(130700,11598,'AbG Snow Melt.jpg',400,342,'Snow Melt','AbG Snow Melt_thumb.jpg',130, 111,0, 0,'','','','');
photos[62] = new photo(130701,11598,'AbG Snowscape.jpg',400,342,'Snowscape','AbG Snowscape_thumb.jpg',130, 111,1, 1,'','','','');
photos[63] = new photo(130702,11598,'AbG Spring Time.jpg',400,342,'Spring Time','AbG Spring Time_thumb.jpg',130, 111,0, 1,'','','','');
photos[64] = new photo(130703,11598,'AbG Sun Clouds copy.jpg',400,342,'Sun Clouds','AbG Sun Clouds copy_thumb.jpg',130, 111,0, 0,'','','','');
photos[65] = new photo(130706,11598,'AbG Sunset copy.jpg',400,342,'Sunset','AbG Sunset copy_thumb.jpg',130, 111,1, 1,'','','','');
photos[66] = new photo(130710,11598,'AbG Tide Mark.jpg',400,342,'Tide Mark','AbG Tide Mark_thumb.jpg',130, 111,0, 1,'','','','');
photos[67] = new photo(130711,11598,'AbG Winter Feilds copy.jpg',400,342,'Winter Fields','AbG Winter Feilds copy_thumb.jpg',130, 111,1, 1,'','','','');

/***************************************************************************
* Create the array of Photo objects                                        *
***************************************************************************/
galleries = new Array();
galleries[0] = new gallery(11027,'125482,125473,125437,125435,125426,125425','1 Landscape Prints');
galleries[1] = new gallery(11593,'125537,125535,125534,125533,125532,125518,125517,125514','2 Screenprints');
galleries[2] = new gallery(11597,'130738,130725,130722,130718,130714,130712,125539,125538','3 Screenprints');
galleries[3] = new gallery(11594,'156648,125616,125578,125574,125558,125554,125542','4 Abstract Prints');
galleries[4] = new gallery(11598,'130711,130710,130706,130702,130701,130699,130629,125630,125625,125571,125564,125545','5 Abstract Prints');

