/***************************************************************************
* 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('1129391');
	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('1129391');
	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 = 'Laura Mc Gillycuddy Photography: ' + 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(1115215,'81689','','gallery','http://www4.clikpic.com/lauramcg/images/birds of paradise.jpg',380,380,'Birds of Paradise','http://www4.clikpic.com/lauramcg/images/birds of paradise_thumb.jpg',130, 130,0, 1,'','','','','','');
photos[1] = new photo(1122796,'81689','','gallery','http://www4.clikpic.com/lauramcg/images/daffodil parade.jpg',390,111,'daffodil parade','http://www4.clikpic.com/lauramcg/images/daffodil parade_thumb.jpg',130, 37,0, 0,'','','','','','');
photos[2] = new photo(1122815,'81689','','gallery','http://www4.clikpic.com/lauramcg/images/pink geranium 22.jpg',288,288,'pink geranium 2','http://www4.clikpic.com/lauramcg/images/pink geranium 22_thumb.jpg',130, 130,0, 0,'','','','','','');
photos[3] = new photo(1123063,'81689','','gallery','http://www4.clikpic.com/lauramcg/images/snowdrops.jpg',350,233,'snowdrops','http://www4.clikpic.com/lauramcg/images/snowdrops_thumb.jpg',130, 87,0, 0,'','','','','','');
photos[4] = new photo(1123071,'81689','','gallery','http://www4.clikpic.com/lauramcg/images/sepia dandelion.jpg',380,380,'seipa dandelion','http://www4.clikpic.com/lauramcg/images/sepia dandelion_thumb.jpg',130, 130,0, 0,'','','','','','');
photos[5] = new photo(1123088,'81689','','gallery','http://www4.clikpic.com/lauramcg/images/dahila.jpg',360,360,'dahila','http://www4.clikpic.com/lauramcg/images/dahila_thumb.jpg',130, 130,0, 0,'','','','','','');
photos[6] = new photo(1123821,'82107','','gallery','http://www4.clikpic.com/lauramcg/images/deep sea blue.jpg',310,388,'Deep sea blue','http://www4.clikpic.com/lauramcg/images/deep sea blue_thumb.jpg',130, 163,0, 0,'','','','','','');
photos[7] = new photo(1123826,'82107','','gallery','http://www4.clikpic.com/lauramcg/images/purple haze.jpg',500,357,'purple haze','http://www4.clikpic.com/lauramcg/images/purple haze_thumb.jpg',130, 93,0, 0,'','','','','','');
photos[8] = new photo(1123829,'82107','','gallery','http://www4.clikpic.com/lauramcg/images/jingle jangle.jpg',400,300,'bangles','http://www4.clikpic.com/lauramcg/images/jingle jangle_thumb.jpg',130, 98,0, 0,'','','','','','');
photos[9] = new photo(1123865,'82107','','gallery','http://www4.clikpic.com/lauramcg/images/wine glass.jpg',500,357,'wine glass','http://www4.clikpic.com/lauramcg/images/wine glass_thumb.jpg',130, 93,0, 1,'','','','','','');
photos[10] = new photo(1129327,'81689','','gallery','http://www4.clikpic.com/lauramcg/images/tulip pink.jpg',280,392,'tulip pink','http://www4.clikpic.com/lauramcg/images/tulip pink_thumb.jpg',130, 182,0, 0,'','','','','','');
photos[11] = new photo(1129334,'81689','','gallery','http://www4.clikpic.com/lauramcg/images/orchid.jpg',380,380,'orchid','http://www4.clikpic.com/lauramcg/images/orchid_thumb.jpg',130, 130,0, 0,'','','','','','');
photos[12] = new photo(1129366,'81689','','gallery','http://www4.clikpic.com/lauramcg/images/red rose.jpg',380,380,'red rose','http://www4.clikpic.com/lauramcg/images/red rose_thumb.jpg',130, 130,0, 0,'','','','','','');
photos[13] = new photo(1129525,'82107','','gallery','http://www4.clikpic.com/lauramcg/images/raindrop.jpg',360,360,'raindrop','http://www4.clikpic.com/lauramcg/images/raindrop_thumb.jpg',130, 130,0, 0,'','','','','','');
photos[14] = new photo(1129536,'82107','','gallery','http://www4.clikpic.com/lauramcg/images/violet splash.jpg',380,271,'violet splash','http://www4.clikpic.com/lauramcg/images/violet splash_thumb.jpg',130, 93,0, 0,'','','','','','');
photos[15] = new photo(1129537,'82107','','gallery','http://www4.clikpic.com/lauramcg/images/splatter.jpg',380,253,'splatter','http://www4.clikpic.com/lauramcg/images/splatter_thumb.jpg',130, 87,0, 0,'','','','','','');
photos[16] = new photo(1129575,'82107','','gallery','http://www4.clikpic.com/lauramcg/images/sea green1.jpg',380,271,'sea green','http://www4.clikpic.com/lauramcg/images/sea green1_thumb.jpg',130, 93,0, 0,'','','','','','');
photos[17] = new photo(1129588,'82107','','gallery','http://www4.clikpic.com/lauramcg/images/spinning lights.jpg',370,264,'spining lights','http://www4.clikpic.com/lauramcg/images/spinning lights_thumb.jpg',130, 93,0, 0,'','','','','','');
photos[18] = new photo(1159444,'81689','','gallery','http://www4.clikpic.com/lauramcg/images/yellow calla.jpg',380,380,'yellow calla','http://www4.clikpic.com/lauramcg/images/yellow calla_thumb.jpg',130, 130,0, 0,'','','','','','');
photos[19] = new photo(1159445,'81689','','gallery','http://www4.clikpic.com/lauramcg/images/untitled 9.jpg',300,300,'untitled 9','http://www4.clikpic.com/lauramcg/images/untitled 9_thumb.jpg',130, 130,0, 0,'','','','','','');
photos[20] = new photo(1159447,'81689','','gallery','http://www4.clikpic.com/lauramcg/images/lilly black and white.jpg',380,390,'Lilly black and white','http://www4.clikpic.com/lauramcg/images/lilly black and white_thumb.jpg',130, 133,0, 0,'','','','','','');
photos[21] = new photo(1159448,'82107','','gallery','http://www4.clikpic.com/lauramcg/images/fire light.jpg',380,285,'fire light','http://www4.clikpic.com/lauramcg/images/fire light_thumb.jpg',130, 98,0, 0,'','','','','','');
photos[22] = new photo(1159450,'82107','','gallery','http://www4.clikpic.com/lauramcg/images/bright lights.jpg',380,285,'bright lights','http://www4.clikpic.com/lauramcg/images/bright lights_thumb.jpg',130, 98,0, 0,'','','','','','');
photos[23] = new photo(1261738,'82107','','gallery','http://www4.clikpic.com/lauramcg/images/summer sun.jpg',260,390,'summer sun','http://www4.clikpic.com/lauramcg/images/summer sun_thumb.jpg',130, 195,0, 0,'','','','','','');
photos[24] = new photo(1108813,'81261','','gallery','http://www4.clikpic.com/lauramcg/images/orange geranium.jpg',380,374,'Orange geranium','http://www4.clikpic.com/lauramcg/images/orange geranium_thumb.jpg',130, 128,0, 0,'','','','','','');
photos[25] = new photo(1108823,'81261','','gallery','http://www4.clikpic.com/lauramcg/images/Dandelion.jpg',380,352,'Dandelion','http://www4.clikpic.com/lauramcg/images/Dandelion_thumb.jpg',130, 120,0, 0,'','','','','','');
photos[26] = new photo(1108840,'81261','','gallery','http://www4.clikpic.com/lauramcg/images/Tulip with raindrop1.jpg',380,380,'Tulip with rain drop','http://www4.clikpic.com/lauramcg/images/Tulip with raindrop1_thumb.jpg',130, 130,0, 0,'','','','','','');
photos[27] = new photo(1108852,'81261','','gallery','http://www4.clikpic.com/lauramcg/images/Untitled-2.jpg',380,380,'Untitled-2','http://www4.clikpic.com/lauramcg/images/Untitled-2_thumb.jpg',130, 130,0, 0,'','','','','','');
photos[28] = new photo(1108897,'81261','','gallery','http://www4.clikpic.com/lauramcg/images/orange rose.jpg',260,260,'Orange rose','http://www4.clikpic.com/lauramcg/images/orange rose_thumb.jpg',130, 130,0, 0,'','','','','','');
photos[29] = new photo(1108912,'81261','','gallery','http://www4.clikpic.com/lauramcg/images/Yellow lilly.jpg',350,350,'Yellow lilly','http://www4.clikpic.com/lauramcg/images/Yellow lilly_thumb.jpg',130, 130,0, 0,'','','','','','');
photos[30] = new photo(1112705,'81261','','gallery','http://www4.clikpic.com/lauramcg/images/calla  lilly.jpg',380,380,'Calla Lilly black and white','http://www4.clikpic.com/lauramcg/images/calla  lilly_thumb.jpg',130, 130,0, 0,'','','','','','');
photos[31] = new photo(1112715,'81261','','gallery','http://www4.clikpic.com/lauramcg/images/Untitled-3.jpg',370,370,'untitled-3','http://www4.clikpic.com/lauramcg/images/Untitled-3_thumb.jpg',130, 130,0, 0,'','','','','','');
photos[32] = new photo(1112721,'81261','','gallery','http://www4.clikpic.com/lauramcg/images/untitled-4.jpg',400,300,'untitled-4','http://www4.clikpic.com/lauramcg/images/untitled-4_thumb.jpg',130, 98,0, 0,'','','','','','');
photos[33] = new photo(1112732,'81261','','gallery','http://www4.clikpic.com/lauramcg/images/gladoli.jpg',380,380,'gladoli','http://www4.clikpic.com/lauramcg/images/gladoli_thumb.jpg',130, 130,0, 0,'','','','','','');
photos[34] = new photo(1112734,'81261','','gallery','http://www4.clikpic.com/lauramcg/images/pink tulip.jpg',380,380,'pink tulip','http://www4.clikpic.com/lauramcg/images/pink tulip_thumb.jpg',130, 130,0, 0,'','','','','','');
photos[35] = new photo(1112736,'81261','','gallery','http://www4.clikpic.com/lauramcg/images/sunflower.jpg',380,380,'sunflower','http://www4.clikpic.com/lauramcg/images/sunflower_thumb.jpg',130, 130,0, 0,'','','','','','');
photos[36] = new photo(1112738,'81261','','gallery','http://www4.clikpic.com/lauramcg/images/purple tinted rose.jpg',380,380,'purple tinted rose','http://www4.clikpic.com/lauramcg/images/purple tinted rose_thumb.jpg',130, 130,0, 0,'','','','','','');
photos[37] = new photo(1112739,'81261','','gallery','http://www4.clikpic.com/lauramcg/images/untitled-5.jpg',380,380,'untitled-5','http://www4.clikpic.com/lauramcg/images/untitled-5_thumb.jpg',130, 130,0, 0,'','','','','','');
photos[38] = new photo(1112740,'81261','','gallery','http://www4.clikpic.com/lauramcg/images/untitled-6.jpg',400,286,'untitled-6','http://www4.clikpic.com/lauramcg/images/untitled-6_thumb.jpg',130, 93,0, 0,'','','','','','');
photos[39] = new photo(1112741,'81261','','gallery','http://www4.clikpic.com/lauramcg/images/red tulip.jpg',380,380,'red tulip','http://www4.clikpic.com/lauramcg/images/red tulip_thumb.jpg',130, 130,0, 0,'','','','','','');
photos[40] = new photo(1112745,'81261','','gallery','http://www4.clikpic.com/lauramcg/images/stargazer.jpg',380,380,'stargazer lilly','http://www4.clikpic.com/lauramcg/images/stargazer_thumb.jpg',130, 130,0, 0,'','','','','','');
photos[41] = new photo(1115049,'81261','','gallery','http://www4.clikpic.com/lauramcg/images/untitled-7.jpg',380,285,'untitled-7','http://www4.clikpic.com/lauramcg/images/untitled-7_thumb.jpg',130, 98,0, 0,'','','','','','');
photos[42] = new photo(1115054,'81261','','gallery','http://www4.clikpic.com/lauramcg/images/pink rose.jpg',380,380,'pink rose','http://www4.clikpic.com/lauramcg/images/pink rose_thumb.jpg',130, 130,0, 1,'','','','','','');
photos[43] = new photo(1115080,'81261','','gallery','http://www4.clikpic.com/lauramcg/images/roddendrum.jpg',370,370,'rhodendron','http://www4.clikpic.com/lauramcg/images/roddendrum_thumb.jpg',130, 130,0, 0,'','','','','','');
photos[44] = new photo(1115150,'81261','','gallery','http://www4.clikpic.com/lauramcg/images/aechema.jpg',380,380,'aechema','http://www4.clikpic.com/lauramcg/images/aechema_thumb.jpg',130, 130,0, 0,'','','','','','');
photos[45] = new photo(1129391,'81261','','gallery','http://www4.clikpic.com/lauramcg/images/untitled12.jpg',400,400,'untitled1','http://www4.clikpic.com/lauramcg/images/untitled12_thumb.jpg',130, 130,1, 0,'','','','','','');
photos[46] = new photo(1261766,'81261','','gallery','http://www4.clikpic.com/lauramcg/images/pink cala row.jpg',390,260,'pink calla row','http://www4.clikpic.com/lauramcg/images/pink cala row_thumb.jpg',130, 87,0, 0,'','','','','','');

/***************************************************************************
* Create the array of Gallery objects                                      *
***************************************************************************/
galleries = new Array();
galleries[0] = new gallery(82107,'1123865','Colour','gallery');
galleries[1] = new gallery(81689,'1115215','Flowers Part Two','gallery');
galleries[2] = new gallery(81261,'1115054','Flowers Part One','gallery');

