/***************************************************************************
* 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('2516920,2516918,2516914,2516911,2516909,2516902,2516898,2516895,2508245,2508242,2508240,2508239,2508238,2508237,2508236,2508233,2508232,2508231,2508230,2508229,2508227,2508226,2508225,2508224,2508223,2508221,2508220,2508219,2508218,2508217,2508215,2508210,2508209,2508208,2508207,2508206,2508205,2508203,2508200,2508199,2508198,2508197,2508196,2508195,2508194,2508192,2508191');
	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('2516920,2516918,2516914,2516911,2516909,2516902,2516898,2516895,2508245,2508242,2508240,2508239,2508238,2508237,2508236,2508233,2508232,2508231,2508230,2508229,2508227,2508226,2508225,2508224,2508223,2508221,2508220,2508219,2508218,2508217,2508215,2508210,2508209,2508208,2508207,2508206,2508205,2508203,2508200,2508199,2508198,2508197,2508196,2508195,2508194,2508192,2508191');
	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)) {
		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 + '" border="0">';
						field.value = photos[nextImg].id;
			document.getElementById('imageTitle').innerHTML = photos[nextImg].caption;
			document.title = 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(2508191,'95499','','gallery','http://admin.clikpic.com/natalieguess/images/A_Snook_Naturally.jpg',500,203,'A Snook Naturally','http://admin.clikpic.com/natalieguess/images/A_Snook_Naturally_thumb.jpg',130, 53,0, 0,'','','','','','');
photos[1] = new photo(2508192,'95499','','gallery','http://admin.clikpic.com/natalieguess/images/Clarke\'s_Gourmet.jpg',500,350,'Clarke\'s Gourmet','http://admin.clikpic.com/natalieguess/images/Clarke\'s_Gourmet_thumb.jpg',130, 91,0, 0,'','','','','','');
photos[2] = new photo(2508194,'164123','','gallery','http://admin.clikpic.com/natalieguess/images/Colorful_Egret.jpg',500,598,'Colorful Egret','http://admin.clikpic.com/natalieguess/images/Colorful_Egret_thumb.jpg',130, 155,0, 0,'','','','','','');
photos[3] = new photo(2508195,'95499','','gallery','http://admin.clikpic.com/natalieguess/images/Egret_Amidst_Bamboo.jpg',485,600,'Egret Amidst Bamboo','http://admin.clikpic.com/natalieguess/images/Egret_Amidst_Bamboo_thumb.jpg',130, 161,0, 0,'','','','','','');
photos[4] = new photo(2508196,'95499','','gallery','http://admin.clikpic.com/natalieguess/images/Egret_Close_Up.jpg',500,374,'Egret Close Up','http://admin.clikpic.com/natalieguess/images/Egret_Close_Up_thumb.jpg',130, 97,0, 0,'','','','','','');
photos[5] = new photo(2508197,'164123','','gallery','http://admin.clikpic.com/natalieguess/images/Egret_in_the_Mangrove.jpg',500,488,'Egret in the Mangrove','http://admin.clikpic.com/natalieguess/images/Egret_in_the_Mangrove_thumb.jpg',130, 127,0, 0,'','','','','','');
photos[6] = new photo(2508198,'95499','','gallery','http://admin.clikpic.com/natalieguess/images/Egret_On_Blue.jpg',315,600,'Egret on Blue','http://admin.clikpic.com/natalieguess/images/Egret_On_Blue_thumb.jpg',130, 248,0, 0,'','','','','','');
photos[7] = new photo(2508199,'95499','','gallery','http://admin.clikpic.com/natalieguess/images/Feeding_in_the_Swamp.jpg',500,343,'Feeding in the Swamp','http://admin.clikpic.com/natalieguess/images/Feeding_in_the_Swamp_thumb.jpg',130, 89,0, 0,'','','','','','');
photos[8] = new photo(2508200,'95499','','gallery','http://admin.clikpic.com/natalieguess/images/Field_Of_Sunflowers.jpg',251,600,'Field of Sunflowers','http://admin.clikpic.com/natalieguess/images/Field_Of_Sunflowers_thumb.jpg',130, 311,0, 0,'','','','','','');
photos[9] = new photo(2508203,'95499','','gallery','http://admin.clikpic.com/natalieguess/images/Fifth_Avenue_Coffee_Co.jpg',472,600,'Fifth Avenue Coffee Co','http://admin.clikpic.com/natalieguess/images/Fifth_Avenue_Coffee_Co_thumb.jpg',130, 165,0, 0,'','','','','','');
photos[10] = new photo(2508205,'95499','','gallery','http://admin.clikpic.com/natalieguess/images/ghost_orchid.jpg',489,600,'Ghost Orchid','http://admin.clikpic.com/natalieguess/images/ghost_orchid_thumb.jpg',130, 160,0, 0,'','','','','','');
photos[11] = new photo(2508206,'95499','','gallery','http://admin.clikpic.com/natalieguess/images/Iris.jpg',500,545,'Iris','http://admin.clikpic.com/natalieguess/images/Iris_thumb.jpg',130, 142,0, 0,'','','','','','');
photos[12] = new photo(2508207,'95499','','gallery','http://admin.clikpic.com/natalieguess/images/Lilies_And_Pads.jpg',258,600,'Lilies and Pads','http://admin.clikpic.com/natalieguess/images/Lilies_And_Pads_thumb.jpg',130, 302,0, 0,'','','','','','');
photos[13] = new photo(2508208,'164123','','gallery','http://admin.clikpic.com/natalieguess/images/Lily_Pond_With_Koi.jpg',500,334,'Lily Pond with Koi','http://admin.clikpic.com/natalieguess/images/Lily_Pond_With_Koi_thumb.jpg',130, 87,0, 0,'','','','','','');
photos[14] = new photo(2508209,'95499','','gallery','http://admin.clikpic.com/natalieguess/images/Little_Green_Heron.jpg',500,300,'Little Green Heron','http://admin.clikpic.com/natalieguess/images/Little_Green_Heron_thumb.jpg',130, 78,0, 0,'','','','','','');
photos[15] = new photo(2508210,'95499','','gallery','http://admin.clikpic.com/natalieguess/images/Long_View_of_the_Pier.jpg',500,196,'Long View of the Pier','http://admin.clikpic.com/natalieguess/images/Long_View_of_the_Pier_thumb.jpg',130, 51,0, 0,'','','','','','');
photos[16] = new photo(2508215,'164123','','gallery','http://admin.clikpic.com/natalieguess/images/Looking_Over.jpg',500,408,'Looking Over','http://admin.clikpic.com/natalieguess/images/Looking_Over_thumb.jpg',130, 106,0, 0,'','','','','','');
photos[17] = new photo(2508217,'95499','','gallery','http://admin.clikpic.com/natalieguess/images/Midwest_Barn.jpg',500,392,'Midwest Barn','http://admin.clikpic.com/natalieguess/images/Midwest_Barn_thumb.jpg',130, 102,0, 0,'','','','','','');
photos[18] = new photo(2508218,'95499','','gallery','http://admin.clikpic.com/natalieguess/images/On_The_Hunt.jpg',500,323,'On the Hunt','http://admin.clikpic.com/natalieguess/images/On_The_Hunt_thumb.jpg',130, 84,0, 0,'','','','','','');
photos[19] = new photo(2508219,'95499','','gallery','http://admin.clikpic.com/natalieguess/images/Resting_By_The_Wall.jpg',500,376,'Resting By the Wall','http://admin.clikpic.com/natalieguess/images/Resting_By_The_Wall_thumb.jpg',130, 98,0, 0,'','','','','','');
photos[20] = new photo(2508220,'95499','','gallery','http://admin.clikpic.com/natalieguess/images/Rug_Cat.jpg',500,475,'Rug Cat','http://admin.clikpic.com/natalieguess/images/Rug_Cat_thumb.jpg',130, 124,0, 0,'','','','','','');
photos[21] = new photo(2508221,'95499','','gallery','http://admin.clikpic.com/natalieguess/images/Searching.jpg',500,329,'Searching','http://admin.clikpic.com/natalieguess/images/Searching_thumb.jpg',130, 86,0, 0,'','','','','','');
photos[22] = new photo(2508223,'95499','','gallery','http://admin.clikpic.com/natalieguess/images/Shadows_Of_Paradise.jpg',500,358,'Shadows of Paradise','http://admin.clikpic.com/natalieguess/images/Shadows_Of_Paradise_thumb.jpg',130, 93,0, 0,'','','','','','');
photos[23] = new photo(2508224,'95499','','gallery','http://admin.clikpic.com/natalieguess/images/Steppin_Out.jpg',441,600,'Steppin Out','http://admin.clikpic.com/natalieguess/images/Steppin_Out_thumb.jpg',130, 177,0, 0,'','','','','','');
photos[24] = new photo(2508225,'95499','','gallery','http://admin.clikpic.com/natalieguess/images/Strand_Theatre.jpg',413,600,'Strand Theatre','http://admin.clikpic.com/natalieguess/images/Strand_Theatre_thumb.jpg',130, 189,0, 0,'','','','','','');
photos[25] = new photo(2508226,'95499','','gallery','http://admin.clikpic.com/natalieguess/images/Sunday_at_the_Beach.jpg',500,417,'Sunday at the Beach','http://admin.clikpic.com/natalieguess/images/Sunday_at_the_Beach_thumb.jpg',130, 108,0, 0,'','','','','','');
photos[26] = new photo(2508227,'95499','','gallery','http://admin.clikpic.com/natalieguess/images/Tropical_View.jpg',500,310,'Tropical View','http://admin.clikpic.com/natalieguess/images/Tropical_View_thumb.jpg',130, 81,0, 0,'','','','','','');
photos[27] = new photo(2508229,'164123','','gallery','http://admin.clikpic.com/natalieguess/images/View_of_Lake_Como.jpg',500,332,'View of Lake Como','http://admin.clikpic.com/natalieguess/images/View_of_Lake_Como_thumb.jpg',130, 86,0, 0,'','','','','','');
photos[28] = new photo(2508230,'95499','','gallery','http://admin.clikpic.com/natalieguess/images/Waitin.jpg',500,367,'Waitin','http://admin.clikpic.com/natalieguess/images/Waitin_thumb.jpg',130, 95,0, 0,'','','','','','');
photos[29] = new photo(2508231,'95499','','gallery','http://admin.clikpic.com/natalieguess/images/Window_Display.jpg',500,458,'Window Display','http://admin.clikpic.com/natalieguess/images/Window_Display_thumb.jpg',130, 119,0, 0,'','','','','','');
photos[30] = new photo(2508232,'95499','','gallery','http://admin.clikpic.com/natalieguess/images/Wine_Barrell_Still_Life.jpg',417,600,'Wine Barrell Still Life','http://admin.clikpic.com/natalieguess/images/Wine_Barrell_Still_Life_thumb.jpg',130, 187,0, 0,'','','','','','');
photos[31] = new photo(2508233,'95499','','gallery','http://admin.clikpic.com/natalieguess/images/Woodstork_Fishing.jpg',500,362,'Woodstork Fishing','http://admin.clikpic.com/natalieguess/images/Woodstork_Fishing_thumb.jpg',130, 94,0, 0,'','','','','','');
photos[32] = new photo(2508236,'95499','','gallery','http://admin.clikpic.com/natalieguess/images/Anhinga_At_Corkscrew.jpg',500,357,'Anhinga at Corkscrew','http://admin.clikpic.com/natalieguess/images/Anhinga_At_Corkscrew_thumb.jpg',130, 93,0, 0,'','','','','','');
photos[33] = new photo(2508237,'95499','','gallery','http://admin.clikpic.com/natalieguess/images/Beach_View_Through_The_Palm.jpg',428,600,'Beach View through the Palm','http://admin.clikpic.com/natalieguess/images/Beach_View_Through_The_Palm_thumb.jpg',130, 182,0, 0,'','','','','','');
photos[34] = new photo(2508238,'164123','','gallery','http://admin.clikpic.com/natalieguess/images/Blue_Shuttered_Window_in_Co.jpg',500,353,'Blue Shutter Window','http://admin.clikpic.com/natalieguess/images/Blue_Shuttered_Window_in_Co_thumb.jpg',130, 92,0, 0,'','','','','','');
photos[35] = new photo(2508239,'164123','','gallery','http://admin.clikpic.com/natalieguess/images/Colorful_Street_In_San_Migu.jpg',500,379,'Colorful Street in San Miguel','http://admin.clikpic.com/natalieguess/images/Colorful_Street_In_San_Migu_thumb.jpg',130, 99,0, 0,'','','','','','');
photos[36] = new photo(2508240,'95499','','gallery','http://admin.clikpic.com/natalieguess/images/Egret_With_Verrigated_Leave.jpg',500,333,'Egret with Verrigated Leave','http://admin.clikpic.com/natalieguess/images/Egret_With_Verrigated_Leave_thumb.jpg',130, 87,0, 0,'','','','','','');
photos[37] = new photo(2508242,'164123','','gallery','http://admin.clikpic.com/natalieguess/images/Family_Time_At_The_Pier.jpg',462,600,'Family Time at the Pier','http://admin.clikpic.com/natalieguess/images/Family_Time_At_The_Pier_thumb.jpg',130, 169,0, 0,'','','','','','');
photos[38] = new photo(2508245,'95499','','gallery','http://admin.clikpic.com/natalieguess/images/Lily_Pond_at_Caribbean_Gard.jpg',464,600,'Lily Pond at Caribbean Gardens','http://admin.clikpic.com/natalieguess/images/Lily_Pond_at_Caribbean_Gard_thumb.jpg',130, 168,0, 0,'','','','','','');
photos[39] = new photo(2516895,'164123','','gallery','http://admin.clikpic.com/natalieguess/images/A Fly low res.jpg',284,432,'A Fly','http://admin.clikpic.com/natalieguess/images/A Fly low res_thumb.jpg',130, 198,0, 0,'','','','','','');
photos[40] = new photo(2516898,'95499','','gallery','http://admin.clikpic.com/natalieguess/images/Banana Trees Triptich low res.jpg',500,355,'Banana Tree','http://admin.clikpic.com/natalieguess/images/Banana Trees Triptich low res_thumb.jpg',130, 92,0, 0,'','','','','','');
photos[41] = new photo(2516902,'164123','','gallery','http://admin.clikpic.com/natalieguess/images/Beach Sunset Silhouettes low res.jpg',500,156,'Beach Sunset','http://admin.clikpic.com/natalieguess/images/Beach Sunset Silhouettes low res_thumb.jpg',130, 41,0, 0,'','','','','','');
photos[42] = new photo(2516909,'164123','','gallery','http://admin.clikpic.com/natalieguess/images/Everglades Sunset On Hand Woven Silk low res.jpg',500,215,'Everglades Sunset on Hand Woven Silk','http://admin.clikpic.com/natalieguess/images/Everglades Sunset On Hand Woven Silk low res_thumb.jpg',130, 56,0, 0,'','','','','','');
photos[43] = new photo(2516911,'164123','','gallery','http://admin.clikpic.com/natalieguess/images/Great Blue In Flight Over The Everglades low res.jpg',500,405,'Great Blue in Flight Over the Everglades','http://admin.clikpic.com/natalieguess/images/Great Blue In Flight Over The Everglades low res_thumb.jpg',130, 105,0, 0,'','','','','','');
photos[44] = new photo(2516914,'95499','','gallery','http://admin.clikpic.com/natalieguess/images/Out The Window low res.jpg',296,426,'Out the Window','http://admin.clikpic.com/natalieguess/images/Out The Window low res_thumb.jpg',130, 187,0, 0,'','','','','','');
photos[45] = new photo(2516918,'95499','','gallery','http://admin.clikpic.com/natalieguess/images/What\'s Next low res.jpg',412,432,'What\'s Next','http://admin.clikpic.com/natalieguess/images/What\'s Next low res_thumb.jpg',130, 136,0, 0,'','','','','','');
photos[46] = new photo(2516920,'95499','','gallery','http://admin.clikpic.com/natalieguess/images/Who Me low res.jpg',305,432,'Who Me?','http://admin.clikpic.com/natalieguess/images/Who Me low res_thumb.jpg',130, 184,0, 0,'','','','','','');

/***************************************************************************
* Create the array of Gallery objects                                      *
***************************************************************************/
galleries = new Array();
galleries[0] = new gallery(164123,'2516911,2516909,2516902,2516895,2508242,2508239,2508238,2508229,2508215,2508208','Batik Paintings','gallery');
galleries[1] = new gallery(95499,'2516920,2516918,2516914,2516898,2508245,2508240,2508237,2508236,2508233,2508232','Gallery of Batik','gallery');

