/***************************************************************************
* 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('3563148,3562475,3527797,3077398,2441885,2441883,2441882,2441881,2441880,2441879,2441878');
	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('3563148,3562475,3527797,3077398,2441885,2441883,2441882,2441881,2441880,2441879,2441878');
	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 = 'CAPTURE THE MOMENT - Portrait 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].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(2441709,'11543','','gallery','http://www1.clikpic.com/capturethemoment/images/5049_8x10.jpg',293,407,'','http://www1.clikpic.com/capturethemoment/images/5049_8x10_thumb.jpg',130, 181,0, 0,'','','','','','');
photos[1] = new photo(2441718,'11543','','gallery','http://www1.clikpic.com/capturethemoment/images/IMG_7828.jpg',327,407,'','http://www1.clikpic.com/capturethemoment/images/IMG_7828_thumb.jpg',130, 162,0, 0,'','','','','','');
photos[2] = new photo(2441721,'11543','','gallery','http://www1.clikpic.com/capturethemoment/images/IMG_7868.jpg',274,407,'','http://www1.clikpic.com/capturethemoment/images/IMG_7868_thumb.jpg',130, 193,0, 0,'','','','','','');
photos[3] = new photo(2441730,'11543','','gallery','http://www1.clikpic.com/capturethemoment/images/IMG_7906.jpg',327,407,'','http://www1.clikpic.com/capturethemoment/images/IMG_7906_thumb.jpg',130, 162,0, 0,'','','','','','');
photos[4] = new photo(2441731,'11543','','gallery','http://www1.clikpic.com/capturethemoment/images/IMG_7909.jpg',327,407,'','http://www1.clikpic.com/capturethemoment/images/IMG_7909_thumb.jpg',130, 162,0, 0,'','','','','','');
photos[5] = new photo(2441737,'11543','','gallery','http://www1.clikpic.com/capturethemoment/images/WL8F5015_6x4.jpg',274,407,'','http://www1.clikpic.com/capturethemoment/images/WL8F5015_6x4_thumb.jpg',130, 193,0, 0,'','','','','','');
photos[6] = new photo(2441738,'11543','','gallery','http://www1.clikpic.com/capturethemoment/images/WL8F5065_7-10.jpg',287,407,'','http://www1.clikpic.com/capturethemoment/images/WL8F5065_7-10_thumb.jpg',130, 184,0, 0,'','','','','','');
photos[7] = new photo(2441740,'11543','','gallery','http://www1.clikpic.com/capturethemoment/images/WL8F5198_10x10.jpg',400,400,'','http://www1.clikpic.com/capturethemoment/images/WL8F5198_10x10_thumb.jpg',130, 130,0, 0,'','','','','','');
photos[8] = new photo(2441741,'11543','','gallery','http://www1.clikpic.com/capturethemoment/images/WL8F5222a.jpg',327,407,'','http://www1.clikpic.com/capturethemoment/images/WL8F5222a_thumb.jpg',130, 162,0, 1,'','','','','','');
photos[9] = new photo(2441743,'11543','','gallery','http://www1.clikpic.com/capturethemoment/images/WL8F5272_5x10.jpg',400,203,'','http://www1.clikpic.com/capturethemoment/images/WL8F5272_5x10_thumb.jpg',130, 66,0, 0,'','','','','','');
photos[10] = new photo(2441879,'','','','http://www1.clikpic.com/capturethemoment/images/IMG_78681.jpg',269,400,'','http://www1.clikpic.com/capturethemoment/images/IMG_78681_thumb.jpg',130, 193,1, 0,'','','','','','');
photos[11] = new photo(2441881,'','','','http://www1.clikpic.com/capturethemoment/images/WL8F96041.jpg',288,400,'','http://www1.clikpic.com/capturethemoment/images/WL8F96041_thumb.jpg',130, 181,1, 0,'','','','','','');
photos[12] = new photo(2441882,'','','','http://www1.clikpic.com/capturethemoment/images/WL8F5198_10x101.jpg',400,400,'','http://www1.clikpic.com/capturethemoment/images/WL8F5198_10x101_thumb.jpg',130, 130,1, 0,'','','','','','');
photos[13] = new photo(2441883,'','','','http://www1.clikpic.com/capturethemoment/images/WL8F54847-5b+w1.jpg',288,400,'','http://www1.clikpic.com/capturethemoment/images/WL8F54847-5b+w1_thumb.jpg',130, 181,1, 0,'','','','','','');
photos[14] = new photo(2441885,'','','','http://www1.clikpic.com/capturethemoment/images/WL8F5222a1.jpg',321,400,'','http://www1.clikpic.com/capturethemoment/images/WL8F5222a1_thumb.jpg',130, 162,1, 0,'','','','','','');
photos[15] = new photo(3077359,'','','','http://www1.clikpic.com/capturethemoment/images/002EPV0187.jpg',400,267,'','http://www1.clikpic.com/capturethemoment/images/002EPV0187_thumb.jpg',130, 87,0, 0,'','','','','','');
photos[16] = new photo(3563092,'','','','http://www1.clikpic.com/capturethemoment/images/1216-4M3.jpg',300,400,'','http://www1.clikpic.com/capturethemoment/images/1216-4M3_thumb.jpg',130, 173,0, 0,'','','','','','');
photos[17] = new photo(3592937,'','','','http://www1.clikpic.com/capturethemoment/images/DR18.jpg',258,305,'','http://www1.clikpic.com/capturethemoment/images/DR18_thumb.jpg',130, 154,0, 0,'','','','','','');
photos[18] = new photo(2441878,'','','','http://www1.clikpic.com/capturethemoment/images/IMG_77991.jpg',269,400,'','http://www1.clikpic.com/capturethemoment/images/IMG_77991_thumb.jpg',130, 193,1, 0,'','','','','','');
photos[19] = new photo(2441717,'5299','','gallery','http://www1.clikpic.com/capturethemoment/images/IMG_7799.jpg',274,407,'','http://www1.clikpic.com/capturethemoment/images/IMG_7799_thumb.jpg',130, 193,0, 0,'','','','','','');
photos[20] = new photo(2441747,'5299','','gallery','http://www1.clikpic.com/capturethemoment/images/WL8F9223.jpg',327,407,'','http://www1.clikpic.com/capturethemoment/images/WL8F9223_thumb.jpg',130, 162,0, 0,'','','','','','');
photos[21] = new photo(2441748,'5299','','gallery','http://www1.clikpic.com/capturethemoment/images/WL8F9259.jpg',400,321,'','http://www1.clikpic.com/capturethemoment/images/WL8F9259_thumb.jpg',130, 104,0, 0,'','','','','','');
photos[22] = new photo(2441751,'5299','','gallery','http://www1.clikpic.com/capturethemoment/images/WL8F54847-5b+w.jpg',293,407,'','http://www1.clikpic.com/capturethemoment/images/WL8F54847-5b+w_thumb.jpg',130, 181,0, 0,'','','','','','');
photos[23] = new photo(2441880,'5299','','gallery','http://www1.clikpic.com/capturethemoment/images/WL8F91981.jpg',321,400,'','http://www1.clikpic.com/capturethemoment/images/WL8F91981_thumb.jpg',130, 162,1, 1,'','','','','','');
photos[24] = new photo(2441714,'5299','','gallery','http://www1.clikpic.com/capturethemoment/images/IMG_7784.jpg',274,407,'','http://www1.clikpic.com/capturethemoment/images/IMG_7784_thumb.jpg',130, 193,0, 0,'','','','','','');
photos[25] = new photo(3527797,'5299','','gallery','http://www1.clikpic.com/capturethemoment/images/WL8F2192.jpg',268,400,'','http://www1.clikpic.com/capturethemoment/images/WL8F2192_thumb.jpg',130, 194,1, 0,'','','','','','');
photos[26] = new photo(2441744,'5299','','gallery','http://www1.clikpic.com/capturethemoment/images/WL8F5466-Edit.jpg',327,407,'','http://www1.clikpic.com/capturethemoment/images/WL8F5466-Edit_thumb.jpg',130, 162,0, 0,'','','','','','');
photos[27] = new photo(3077398,'5299','','gallery','http://www1.clikpic.com/capturethemoment/images/print-02921.jpg',400,271,'','http://www1.clikpic.com/capturethemoment/images/print-02921_thumb.jpg',130, 88,1, 0,'','','','','','');
photos[28] = new photo(3562475,'5299','','gallery','http://www1.clikpic.com/capturethemoment/images/2416-2.jpg',400,271,'','http://www1.clikpic.com/capturethemoment/images/2416-2_thumb.jpg',130, 88,1, 0,'','','','','','');
photos[29] = new photo(2441712,'5744','','gallery','http://www1.clikpic.com/capturethemoment/images/_MG_1458.jpg',327,407,'','http://www1.clikpic.com/capturethemoment/images/_MG_1458_thumb.jpg',130, 162,0, 0,'','','','','','');
photos[30] = new photo(2441733,'5744','','gallery','http://www1.clikpic.com/capturethemoment/images/IMG_7436090305.jpg',274,407,'','http://www1.clikpic.com/capturethemoment/images/IMG_7436090305_thumb.jpg',130, 193,0, 0,'','','','','','');
photos[31] = new photo(2441735,'5744','','gallery','http://www1.clikpic.com/capturethemoment/images/IMG_7467090305.jpg',400,321,'','http://www1.clikpic.com/capturethemoment/images/IMG_7467090305_thumb.jpg',130, 104,0, 0,'','','','','','');
photos[32] = new photo(2441749,'5744','','gallery','http://www1.clikpic.com/capturethemoment/images/WL8F9604.jpg',293,407,'','http://www1.clikpic.com/capturethemoment/images/WL8F9604_thumb.jpg',130, 181,0, 0,'','','','','','');
photos[33] = new photo(2441750,'5744','','gallery','http://www1.clikpic.com/capturethemoment/images/WL8F9707.jpg',400,321,'','http://www1.clikpic.com/capturethemoment/images/WL8F9707_thumb.jpg',130, 104,0, 0,'','','','','','');
photos[34] = new photo(3527818,'5744','','gallery','http://www1.clikpic.com/capturethemoment/images/WL8F2157.jpg',321,400,'','http://www1.clikpic.com/capturethemoment/images/WL8F2157_thumb.jpg',130, 162,0, 0,'','','','','','');
photos[35] = new photo(3563148,'5744','','gallery','http://www1.clikpic.com/capturethemoment/images/1612-4.jpg',300,400,'','http://www1.clikpic.com/capturethemoment/images/1612-4_thumb.jpg',130, 173,1, 1,'','','','','','');
photos[36] = new photo(3325569,'5744','','gallery','http://www1.clikpic.com/capturethemoment/images/WL8F1711-Edit.jpg',268,400,'','http://www1.clikpic.com/capturethemoment/images/WL8F1711-Edit_thumb.jpg',130, 194,0, 0,'','','','','','');
photos[37] = new photo(3620838,'221482','','gallery','http://www1.clikpic.com/capturethemoment/images/WL8F2641.jpg',400,349,'','http://www1.clikpic.com/capturethemoment/images/WL8F2641_thumb.jpg',130, 113,0, 0,'','','','','','');
photos[38] = new photo(3620855,'221482','','gallery','http://www1.clikpic.com/capturethemoment/images/_C5C44421.jpg',268,400,'','http://www1.clikpic.com/capturethemoment/images/_C5C44421_thumb.jpg',130, 194,0, 0,'','','','','','');
photos[39] = new photo(3620857,'221482','','gallery','http://www1.clikpic.com/capturethemoment/images/WL8F23792.jpg',259,400,'','http://www1.clikpic.com/capturethemoment/images/WL8F23792_thumb.jpg',130, 201,0, 0,'','','','','','');
photos[40] = new photo(3620860,'221482','','gallery','http://www1.clikpic.com/capturethemoment/images/WL8F24191.jpg',267,400,'','http://www1.clikpic.com/capturethemoment/images/WL8F24191_thumb.jpg',130, 195,0, 0,'','','','','','');
photos[41] = new photo(3620862,'221482','','gallery','http://www1.clikpic.com/capturethemoment/images/WL8F24511.jpg',261,400,'','http://www1.clikpic.com/capturethemoment/images/WL8F24511_thumb.jpg',130, 199,0, 0,'','','','','','');
photos[42] = new photo(3620863,'221482','','gallery','http://www1.clikpic.com/capturethemoment/images/WL8F25051.jpg',400,362,'','http://www1.clikpic.com/capturethemoment/images/WL8F25051_thumb.jpg',130, 118,0, 0,'','','','','','');
photos[43] = new photo(3620865,'221482','','gallery','http://www1.clikpic.com/capturethemoment/images/WL8F25381.jpg',264,400,'','http://www1.clikpic.com/capturethemoment/images/WL8F25381_thumb.jpg',130, 197,0, 0,'','','','','','');
photos[44] = new photo(3620866,'221482','','gallery','http://www1.clikpic.com/capturethemoment/images/WL8F25441.jpg',275,400,'','http://www1.clikpic.com/capturethemoment/images/WL8F25441_thumb.jpg',130, 189,0, 0,'','','','','','');
photos[45] = new photo(3620868,'221482','','gallery','http://www1.clikpic.com/capturethemoment/images/WL8F25951.jpg',321,400,'','http://www1.clikpic.com/capturethemoment/images/WL8F25951_thumb.jpg',130, 162,0, 1,'','','','','','');
photos[46] = new photo(3620882,'221482','','gallery','http://www1.clikpic.com/capturethemoment/images/WL8F23232.jpg',268,400,'','http://www1.clikpic.com/capturethemoment/images/WL8F23232_thumb.jpg',130, 194,0, 0,'','','','','','');
photos[47] = new photo(3621812,'221482','','gallery','http://www1.clikpic.com/capturethemoment/images/WL8F2547.jpg',267,400,'','http://www1.clikpic.com/capturethemoment/images/WL8F2547_thumb.jpg',130, 195,0, 0,'','','','','','');
photos[48] = new photo(3562596,'221482','','gallery','http://www1.clikpic.com/capturethemoment/images/1216-4.jpg',300,400,'','http://www1.clikpic.com/capturethemoment/images/1216-4_thumb.jpg',130, 173,0, 0,'','','','','','');
photos[49] = new photo(3345632,'204116','','gallery','http://www1.clikpic.com/capturethemoment/images/WL8F1895Final-300dpib.jpg',400,400,'','http://www1.clikpic.com/capturethemoment/images/WL8F1895Final-300dpib_thumb.jpg',130, 130,0, 0,'','','','','','');

/***************************************************************************
* Create the array of Gallery objects                                      *
***************************************************************************/
galleries = new Array();
galleries[0] = new gallery(11543,'2441741','Weddings','gallery');
galleries[1] = new gallery(5299,'2441880','Portraits','gallery');
galleries[2] = new gallery(5744,'3563148','Pets','gallery');
galleries[3] = new gallery(221482,'3620868','Equestrian','gallery');
galleries[4] = new gallery(204116,'3345632','Commercial','gallery');

