/***************************************************************************
* 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('3401496');
	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('3401496');
	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 = 'LeCheile Health & Healing Centre: ' + 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(3397299,'209287','','gallery','http://www3.clikpic.com/LeCheile/images/Yoga-at-LeCheile.gif',400,300,'Yoga with Angelika in our large workshop space','http://www3.clikpic.com/LeCheile/images/Yoga-at-LeCheile_thumb.gif',130, 98,0, 0,'','','','','','');
photos[1] = new photo(3427067,'209287','','gallery','http://www3.clikpic.com/LeCheile/images/Yoga-with-Angelika-at-LeCheile.gif',400,273,'Yoga with Angelika','http://www3.clikpic.com/LeCheile/images/Yoga-with-Angelika-at-LeCheile_thumb.gif',130, 89,0, 0,'','','','','','');
photos[2] = new photo(3426678,'209287','','gallery','http://www3.clikpic.com/LeCheile/images/Mairead.jpg',400,406,'Mairead Phelan our masseuse at LeCheile','http://www3.clikpic.com/LeCheile/images/Mairead_thumb.jpg',130, 132,0, 0,'','','','','','');
photos[3] = new photo(3426681,'209287','','gallery','http://www3.clikpic.com/LeCheile/images/MAIREAD AT WORK.jpg',400,300,'Mairead Phelan at work in LeCheile','http://www3.clikpic.com/LeCheile/images/MAIREAD AT WORK_thumb.jpg',130, 98,0, 0,'','','','','','');
photos[4] = new photo(3426684,'209287','','gallery','http://www3.clikpic.com/LeCheile/images/Mairead at work II.jpg',400,254,'Mairead at work in LeChéile','http://www3.clikpic.com/LeCheile/images/Mairead at work II_thumb.jpg',130, 83,0, 0,'','','','','','');
photos[5] = new photo(3401562,'207367','','gallery','http://www3.clikpic.com/LeCheile/images/Therapy-room-at-LeCheile-9-Rockingham.gif',400,300,'Therapy room at LeChéile','http://www3.clikpic.com/LeCheile/images/Therapy-room-at-LeCheile-9-Rockingham_thumb.gif',130, 98,0, 0,'','','','','','');
photos[6] = new photo(3401579,'207367','','gallery','http://www3.clikpic.com/LeCheile/images/Bright-Therapy-room-at-LeCheile.gif',400,300,'Bright Therapy room at LeChéile','http://www3.clikpic.com/LeCheile/images/Bright-Therapy-room-at-LeCheile_thumb.gif',130, 98,0, 0,'','','','','','');
photos[7] = new photo(3401628,'207367','','gallery','http://www3.clikpic.com/LeCheile/images/Ceramic-circle-Workshop-space-LeCheile.gif',400,300,'Shamanic Wheel / Power Animals','http://www3.clikpic.com/LeCheile/images/Ceramic-circle-Workshop-space-LeCheile_thumb.gif',130, 98,0, 0,'','','','','','');
photos[8] = new photo(3424128,'207367','','gallery','http://www3.clikpic.com/LeCheile/images/workshop-space-no-10-LeCheile-Rockingham.gif',400,265,'Large workshop space at No 10 LeCheile','http://www3.clikpic.com/LeCheile/images/workshop-space-no-10-LeCheile-Rockingham_thumb.gif',130, 86,0, 0,'','','','','','');
photos[9] = new photo(3426816,'207367','','gallery','http://www3.clikpic.com/LeCheile/images/Tipi-in-the-garden-of-No-10-LeCheile.gif',400,534,'Tipi in the garden of LeCheile','http://www3.clikpic.com/LeCheile/images/Tipi-in-the-garden-of-No-10-LeCheile_thumb.gif',130, 174,0, 0,'','','','','','');
photos[10] = new photo(3426821,'207367','','gallery','http://www3.clikpic.com/LeCheile/images/LeCheile-exterior.gif',400,300,'Exterior of 9 & 10 LeChéile Health & Healing Centre','http://www3.clikpic.com/LeCheile/images/LeCheile-exterior_thumb.gif',130, 98,0, 0,'','','','','','');
photos[11] = new photo(3426828,'207367','','gallery','http://www3.clikpic.com/LeCheile/images/workshop-space-at-No-9-LeCheile.gif',400,265,'Workshop space at No 9 LeChéile','http://www3.clikpic.com/LeCheile/images/workshop-space-at-No-9-LeCheile_thumb.gif',130, 86,0, 0,'','','','','','');
photos[12] = new photo(3426887,'207367','','gallery','http://www3.clikpic.com/LeCheile/images/Waiting room.jpg',400,300,'Our Waiting Room','http://www3.clikpic.com/LeCheile/images/Waiting room_thumb.jpg',130, 98,0, 0,'At LeChéile each client is welcome to stay after any session to have a cuppa, lie down, sit in the waiting room and take your time, allowing you to get the full benefit from your chosen therapy.','','','','','');
photos[13] = new photo(3427058,'207367','','gallery','http://www3.clikpic.com/LeCheile/images/large-workshop-space-no-10-LeCheile.gif',400,294,'Large workshop space at 10 LeCheile','http://www3.clikpic.com/LeCheile/images/large-workshop-space-no-10-LeCheile_thumb.gif',130, 96,0, 0,'','','','','','');
photos[14] = new photo(3401496,'207763','','gallery','http://www3.clikpic.com/LeCheile/images/LeCheile Logo_low res.jpg',255,255,'LeChéile logo','http://www3.clikpic.com/LeCheile/images/LeCheile Logo_low res_thumb.jpg',130, 130,1, 0,'','','','','','');
photos[15] = new photo(3401541,'207763','','gallery','http://www3.clikpic.com/LeCheile/images/Gingko-tree-at-LeCheile1.gif',400,533,'Our Ginkgo Tree at LeChéile','http://www3.clikpic.com/LeCheile/images/Gingko-tree-at-LeCheile1_thumb.gif',130, 173,0, 0,'','','','','','');
photos[16] = new photo(3401558,'207763','','gallery','http://www3.clikpic.com/LeCheile/images/Gingko-leaf.gif',400,268,'Gingko Leaf','http://www3.clikpic.com/LeCheile/images/Gingko-leaf_thumb.gif',130, 87,0, 0,'','','','','','');
photos[17] = new photo(3426526,'207368','','gallery','http://www3.clikpic.com/LeCheile/images/Feile-LeCheile-Main-Stage.gif',400,300,'Feile LeCheile Charity Event -  Main Stage','http://www3.clikpic.com/LeCheile/images/Feile-LeCheile-Main-Stage_thumb.gif',130, 98,0, 0,'','','','','','');
photos[18] = new photo(3426532,'207368','','gallery','http://www3.clikpic.com/LeCheile/images/Feile-LeCheile-Live-Music.gif',400,533,'Feile LeChéile Main Stage Live Music','http://www3.clikpic.com/LeCheile/images/Feile-LeCheile-Live-Music_thumb.gif',130, 173,0, 0,'','','','','','');
photos[19] = new photo(3426539,'207368','','gallery','http://www3.clikpic.com/LeCheile/images/Feile-LeCheile-Charity-Event.gif',400,533,'Feile LeChéile','http://www3.clikpic.com/LeCheile/images/Feile-LeCheile-Charity-Event_thumb.gif',130, 173,0, 0,'','','','','','');

/***************************************************************************
* Create the array of Gallery objects                                      *
***************************************************************************/
galleries = new Array();
galleries[0] = new gallery(209287,'3427067,3426684,3426681,3426678,3397299','Our practioners & facilitators','gallery');
galleries[1] = new gallery(207367,'3427058,3426887,3426828,3426821,3426816,3424128,3401628,3401579,3401562','LeChéile therapy rooms & workshop spaces','gallery');
galleries[2] = new gallery(207763,'3401558,3401541,3401496','Our Logo','gallery');
galleries[3] = new gallery(207368,'3426539,3426532,3426526','Events at LeCheile','gallery');

