/***************************************************************************
* 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('3439279,3398055,3398054,3398053,3398035,3398031,3398029,3398022,3398015,3398012,3389422');
	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('3439279,3398055,3398054,3398053,3398035,3398031,3398029,3398022,3398015,3398012,3389422');
	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 = 'Auvergne Gîte: ' + 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(3397992,'','','','http://www3.clikpic.com/cbaron/images/DSC00126.JPG',480,360,'View from a nearby hamlet','http://www3.clikpic.com/cbaron/images/DSC00126_thumb.JPG',130, 98,0, 0,'','','','','','');
photos[1] = new photo(3389422,'207009','','gallery','http://www3.clikpic.com/cbaron/images/Gite_main.jpg',480,360,'The gîte from the front','http://www3.clikpic.com/cbaron/images/Gite_main_thumb.jpg',130, 98,1, 0,'Main view of the gîte from below','','','','','');
photos[2] = new photo(3398035,'207009','','gallery','http://www3.clikpic.com/cbaron/images/Dining_room_2.JPG',480,360,'Dining area','http://www3.clikpic.com/cbaron/images/Dining_room_2_thumb.JPG',130, 98,1, 0,'Dining area on the ground floor.  Comfortable and rustic.','','','','','');
photos[3] = new photo(3398053,'207009','','gallery','http://www3.clikpic.com/cbaron/images/Gite_and_barn.JPG',480,319,'Gîte and barn','http://www3.clikpic.com/cbaron/images/Gite_and_barn_thumb.JPG',130, 86,1, 0,'View of the lower patio from front sheltered by the gîte and the barn','','','','','');
photos[4] = new photo(3398031,'207009','','gallery','http://www3.clikpic.com/cbaron/images/Sitting_room_2.JPG',480,360,'Sitting area','http://www3.clikpic.com/cbaron/images/Sitting_room_2_thumb.JPG',130, 98,1, 0,'Sitting room on ground floor','','','','','');
photos[5] = new photo(3398044,'207009','','gallery','http://www3.clikpic.com/cbaron/images/Gite_2.JPG',480,360,'Gite from the side with parking','http://www3.clikpic.com/cbaron/images/Gite_2_thumb.JPG',130, 98,0, 0,'Side and back of gîte with parking area','','','','','');
photos[6] = new photo(3398033,'207009','','gallery','http://www3.clikpic.com/cbaron/images/Sitting_room_31.JPG',480,360,'Sitting room','http://www3.clikpic.com/cbaron/images/Sitting_room_31_thumb.JPG',130, 98,0, 0,'Sitting room on ground floor.  Comfortable and rustic','','','','','');
photos[7] = new photo(3398043,'207009','','gallery','http://www3.clikpic.com/cbaron/images/DSC00981.JPG',480,360,'Steps to lower patio and garden','http://www3.clikpic.com/cbaron/images/DSC00981_thumb.JPG',130, 98,0, 1,'The gite is built into the hill so there are two levels to the garden','','','','','');
photos[8] = new photo(3398029,'207009','','gallery','http://www3.clikpic.com/cbaron/images/DSC00959.JPG',480,360,'Kitchen','http://www3.clikpic.com/cbaron/images/DSC00959_thumb.JPG',130, 98,1, 1,'The kitchen is open and well equipped.','','','','','');
photos[9] = new photo(3397991,'207009','','gallery','http://www3.clikpic.com/cbaron/images/DSC00119.JPG',480,360,'The gîte from above','http://www3.clikpic.com/cbaron/images/DSC00119_thumb.JPG',130, 98,0, 1,'Shows the gite nestled in a secluded part of the forest on a hill.','','','','','');
photos[10] = new photo(3397996,'207009','','gallery','http://www3.clikpic.com/cbaron/images/DSC00130.JPG',480,360,'Sitting room and log fire','http://www3.clikpic.com/cbaron/images/DSC00130_thumb.JPG',130, 98,0, 1,'The poele - log burner provides a focus to the sitting room and makes it very cosy in winter.','','','','','');
photos[11] = new photo(3398022,'207009','','gallery','http://www3.clikpic.com/cbaron/images/DSC00231.JPG',480,360,'Barn at sunset','http://www3.clikpic.com/cbaron/images/DSC00231_thumb.JPG',130, 98,1, 1,'Sunsets from the gite and surrounding area can be spectacular.','','','','','');
photos[12] = new photo(3398028,'207009','','gallery','http://www3.clikpic.com/cbaron/images/DSC00958.JPG',480,360,'Dinning area','http://www3.clikpic.com/cbaron/images/DSC00958_thumb.JPG',130, 98,0, 1,'The dining area is open plan with kitchen and sitting room which make it a social area.  Comfortably and rustically furnished.','','','','','');
photos[13] = new photo(3398038,'207009','','gallery','http://www3.clikpic.com/cbaron/images/DSC00978.JPG',480,360,'Upper patio and main entrance','http://www3.clikpic.com/cbaron/images/DSC00978_thumb.JPG',130, 98,0, 1,'Main entrance to the ground floor is on the upper garden level.','','','','','');
photos[14] = new photo(3398015,'207009','','gallery','http://www3.clikpic.com/cbaron/images/DSC00214.JPG',480,360,'Upper patio','http://www3.clikpic.com/cbaron/images/DSC00214_thumb.JPG',130, 98,1, 1,'Garden furniture is available to enjoy the patios and garden.','','','','','');
photos[15] = new photo(3398039,'207009','','gallery','http://www3.clikpic.com/cbaron/images/DSC00980.JPG',480,360,'The Gite and parking','http://www3.clikpic.com/cbaron/images/DSC00980_thumb.JPG',130, 98,0, 0,'Parking spaces are available next to the gite and at the top of the track.','','','','','');
photos[16] = new photo(3439279,'207009','','gallery','http://www3.clikpic.com/cbaron/images/Gite_spring.JPG',480,360,'Spring in the garden','http://www3.clikpic.com/cbaron/images/Gite_spring_thumb.JPG',130, 98,1, 0,'This water trough in the lower garden contains the cool spring water that comes from above.  It is often a home to newts.','','','','','');
photos[17] = new photo(3397994,'207008','','gallery','http://www3.clikpic.com/cbaron/images/DSC00129.JPG',480,360,'View from a nearby hamlet','http://www3.clikpic.com/cbaron/images/DSC00129_thumb.JPG',130, 98,0, 1,'The pool in the foreground is for trout farming.  The backdrop is the Livradois hills on the other side of the valley.','','','','','');
photos[18] = new photo(3398000,'207008','','gallery','http://www3.clikpic.com/cbaron/images/DSC00142.JPG',480,360,'Walking cycling track','http://www3.clikpic.com/cbaron/images/DSC00142_thumb.JPG',130, 98,0, 1,'The whole area is a network of tracks and trails suitable for walking or cycling.','','','','','');
photos[19] = new photo(3398005,'207008','','gallery','http://www3.clikpic.com/cbaron/images/DSC00182.JPG',480,360,'View from a nearby hamlet','http://www3.clikpic.com/cbaron/images/DSC00182_thumb.JPG',130, 98,0, 1,'Trout pool in the foreground and Monts du Livradois in the distance','','','','','');
photos[20] = new photo(3398007,'207008','','gallery','http://www3.clikpic.com/cbaron/images/DSC00186.JPG',480,360,'View from a nearby hamlet','http://www3.clikpic.com/cbaron/images/DSC00186_thumb.JPG',130, 98,0, 1,'The forests often open out into fields where cattle, goats, sheep or horses are farmed.','','','','','');
photos[21] = new photo(3398013,'207008','','gallery','http://www3.clikpic.com/cbaron/images/DSC00209.JPG',480,360,'Pervanche a neighbour','http://www3.clikpic.com/cbaron/images/DSC00209_thumb.JPG',130, 98,0, 1,'Horses are often kept in the field next to the gite.  They are friendly and come to chat when you are in the garden or walking up the track.','','','','','');
photos[22] = new photo(3398017,'207008','','gallery','http://www3.clikpic.com/cbaron/images/DSC00219.JPG',480,360,'Col de beal','http://www3.clikpic.com/cbaron/images/DSC00219_thumb.JPG',130, 98,0, 1,'Col de Beal is an easy drive and at 1300 metres is one of the high road passes locally.  You can walk there from the gite or drive and walk on the hills.','','','','','');
photos[23] = new photo(3398018,'207008','','gallery','http://www3.clikpic.com/cbaron/images/DSC00227.JPG',480,360,'Forest walking','http://www3.clikpic.com/cbaron/images/DSC00227_thumb.JPG',130, 98,0, 1,'Wherever you walk from the gite there are forest tracks and views over the hills (Monts du Forez)','','','','','');
photos[24] = new photo(3398024,'207008','','gallery','http://www3.clikpic.com/cbaron/images/DSC00508.JPG',480,360,'Chateau at Le Teilhet country view','http://www3.clikpic.com/cbaron/images/DSC00508_thumb.JPG',130, 98,0, 1,'This is the view from a distance of a nearby restored medieval chateau at Le Teilhet.','','','','','');
photos[25] = new photo(3398056,'207008','','gallery','http://www3.clikpic.com/cbaron/images/DSC_0669.JPG',480,319,'Mist in the Dore Valley','http://www3.clikpic.com/cbaron/images/DSC_0669_thumb.JPG',130, 86,0, 1,'From above the Dore valley can look like a lake when the morning mist settles.','','','','','');
photos[26] = new photo(3398058,'207008','','gallery','http://www3.clikpic.com/cbaron/images/DSC_0681.JPG',480,319,'Horses near Le Brugeron','http://www3.clikpic.com/cbaron/images/DSC_0681_thumb.JPG',130, 86,0, 1,'Horses are commonly kept by local farmers.','','','','','');
photos[27] = new photo(3398061,'207008','','gallery','http://www3.clikpic.com/cbaron/images/DSC_0693.JPG',480,319,'Montmarie chateau','http://www3.clikpic.com/cbaron/images/DSC_0693_thumb.JPG',130, 86,0, 1,'A nearby chateau (near Olliergues)and grounds are picturesque.','','','','','');
photos[28] = new photo(3398062,'207008','','gallery','http://www3.clikpic.com/cbaron/images/DSC_0695.JPG',480,319,'Walking in the grounds of Montmarie chateau','http://www3.clikpic.com/cbaron/images/DSC_0695_thumb.JPG',130, 86,0, 1,'Montmarie Chateau (Near Olliergues) and grounds including arboretum is a straightforward walk through the forest from the gite.','','','','','');
photos[29] = new photo(3398055,'207008','','gallery','http://www3.clikpic.com/cbaron/images/Mist_Dore_valley.JPG',480,319,'Mist in the Dore valley','http://www3.clikpic.com/cbaron/images/Mist_Dore_valley_thumb.JPG',130, 86,1, 1,'On some mornings the valley below looks like a lake.','','','','','');
photos[30] = new photo(3398054,'207008','','gallery','http://www3.clikpic.com/cbaron/images/DSC_0653.JPG',480,319,'Les Monts Volcans from Forez','http://www3.clikpic.com/cbaron/images/DSC_0653_thumb.JPG',130, 86,1, 0,'In the distance you can see the snow covered volcanoes in the Chaine des Puy','','','','','');
photos[31] = new photo(3398052,'207008','','gallery','http://www3.clikpic.com/cbaron/images/DSC01817.JPG',480,360,'Walking cycling track','http://www3.clikpic.com/cbaron/images/DSC01817_thumb.JPG',130, 98,0, 1,'The walking and cycle tracks and trails cross and recross small rivers and tributaries.  Suitable for trout fishing but you need a licence.','','','','','');
photos[32] = new photo(3441369,'207008','','gallery','http://www3.clikpic.com/cbaron/images/Forest_walk_1.JPG',480,319,'Forest walks','http://www3.clikpic.com/cbaron/images/Forest_walk_1_thumb.JPG',130, 86,0, 0,'The scenery is beautiful no matter what the season.  Beech leaves in autumn and winter add a particular warmth to the forest floor and cushion your forest walks','','','','','');
photos[33] = new photo(3398050,'207008','','gallery','http://www3.clikpic.com/cbaron/images/DSC01815.JPG',480,360,'Nearby tributary','http://www3.clikpic.com/cbaron/images/DSC01815_thumb.JPG',130, 98,0, 1,'A walking trail crosses a tributary that flows to join the river Dore.  The rivers make the walks very interesting as wildlife abounds.','','','','','');
photos[34] = new photo(3398020,'207008','','gallery','http://www3.clikpic.com/cbaron/images/DSC00228.JPG',480,360,'Walking cycling track','http://www3.clikpic.com/cbaron/images/DSC00228_thumb.JPG',130, 98,0, 1,'Walking and cycling in this area of France is made easy by way marked circular trails.  You have to keep your eyes open for the colour coded marks on trees and stones but the guides take you through beautiful and scenic routes.','','','','','');
photos[35] = new photo(3398012,'207008','','gallery','http://www3.clikpic.com/cbaron/images/DSC00204.JPG',480,360,'Walking cycling track','http://www3.clikpic.com/cbaron/images/DSC00204_thumb.JPG',130, 98,1, 1,'Sun shining through the trees makes forest walks inspiring.  There are tracks and trails for cycling and walking everywhere and you may not see another soul while you are out.','','','','','');
photos[36] = new photo(3398011,'207008','','gallery','http://www3.clikpic.com/cbaron/images/DSC00203.JPG',480,360,'Forest view','http://www3.clikpic.com/cbaron/images/DSC00203_thumb.JPG',130, 98,0, 1,'This forest is mixed deciduous and evergreen.  It is managed and new tree planting takes place on a cycle as the fully mature trees are harvested.  Most areas in the forest are quiet calm and secluded.','','','','','');
photos[37] = new photo(3441364,'207008','','gallery','http://www3.clikpic.com/cbaron/images/Le_Teilhet_chateau_2.JPG',480,319,'Le Teilhet Chateau','http://www3.clikpic.com/cbaron/images/Le_Teilhet_chateau_2_thumb.JPG',130, 86,0, 0,'Several of the many circular walks that can be started from the door of the gite will take you past this picturesque medieval chateau that was recently restored.','','','','','');
photos[38] = new photo(3439273,'207008','','gallery','http://www3.clikpic.com/cbaron/images/Le_Teilhet_chateau_1.JPG',480,360,'Chateau at Le Teilhet','http://www3.clikpic.com/cbaron/images/Le_Teilhet_chateau_1_thumb.JPG',130, 98,0, 0,'A recently renovated medieval chateau at Le Teilhet is very picturesque and not far from the gite.','','','','','');
photos[39] = new photo(3439280,'207008','','gallery','http://www3.clikpic.com/cbaron/images/Cycling_sunset.JPG',480,360,'Cycling at sunset','http://www3.clikpic.com/cbaron/images/Cycling_sunset_thumb.JPG',130, 98,0, 0,'The sunsets are spectacular and it is easy to stay out late on balmy summer nights.  Din\'t forget to take lights!','','','','','');
photos[40] = new photo(3439284,'207008','','gallery','http://www3.clikpic.com/cbaron/images/Walking_Jasserie.JPG',480,360,'Walking through a Jasserie in spring','http://www3.clikpic.com/cbaron/images/Walking_Jasserie_thumb.JPG',130, 98,0, 0,'Jasseries are grazing areas used by herdsmen as a half way stop between hill grazing in summer and lowland or indoor grazing in winter.  In spring they are often covered in daffodils.','','','','','');
photos[41] = new photo(3441361,'207008','','gallery','http://www3.clikpic.com/cbaron/images/Walking_Forez_1.JPG',480,360,'Walking in the monts du Forez','http://www3.clikpic.com/cbaron/images/Walking_Forez_1_thumb.JPG',130, 98,0, 0,'Walking among the hills, forests and rivers of Forez is relaxing, interesting and varied.','','','','','');

/***************************************************************************
* Create the array of Gallery objects                                      *
***************************************************************************/
galleries = new Array();
galleries[0] = new gallery(207009,'3398043,3398038,3398029,3398028,3398022,3398015,3397996,3397991','Gîte','gallery');
galleries[1] = new gallery(207008,'3398062,3398061,3398058,3398056,3398055,3398052,3398050,3398024,3398020,3398018,3398017,3398013,3398012,3398011,3398007,3398005,3398000,3397994','Countryside','gallery');

