/***************************************************************************
* 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('2906239,2906237');
	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('2906239,2906237');
	for (j = 0; j < photos.length; j++) {
		if (photos[j].id == imageID) {
			if ('section224951' != '') {
						if (photos[j].galleries_id != '') {
						document.write('<a href="' + photos[j].section_code + '_' + photos[j].galleries_id + '.html">');
						}
						else {
						document.write('<a href="section224951.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 ('section224951' != '') {
				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 && !((1) || (1))) {
		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 = 'robleaphotography: ' + 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(2906130,'180014','','gallery','http://admin.clikpic.com/roblea/images/casino21.jpg',422,600,'Chamonix casino','http://admin.clikpic.com/roblea/images/casino21_thumb.jpg',129, 184,0, 0,'','','','',35.00,'');
photos[1] = new photo(2906131,'180014','','gallery','http://admin.clikpic.com/roblea/images/casinonights1.jpg',400,600,'Chamonix casino at night','http://admin.clikpic.com/roblea/images/casinonights1_thumb.jpg',129, 194,0, 0,'','','','',35.00,'');
photos[2] = new photo(2906133,'180014','','gallery','http://admin.clikpic.com/roblea/images/chamonixtown1.jpg',600,454,'Chamonix','http://admin.clikpic.com/roblea/images/chamonixtown1_thumb.jpg',130, 98,0, 1,'','','','',35.00,'');
photos[3] = new photo(2906135,'180014','','gallery','http://admin.clikpic.com/roblea/images/chamonixtown2.jpg',600,458,'Chamonix 2','http://admin.clikpic.com/roblea/images/chamonixtown2_thumb.jpg',130, 99,0, 0,'','','','',35.00,'');
photos[4] = new photo(2906138,'180014','','gallery','http://admin.clikpic.com/roblea/images/chamonixvalleywinter.jpg',600,450,'Chamonix valley in Winter','http://admin.clikpic.com/roblea/images/chamonixvalleywinter_thumb.jpg',130, 97,0, 0,'','','','',35.00,'');
photos[5] = new photo(2906139,'180014','','gallery','http://admin.clikpic.com/roblea/images/letourwinter.jpg',600,465,'Le Tour and glacier in Winter','http://admin.clikpic.com/roblea/images/letourwinter_thumb.jpg',130, 100,0, 0,'','','','',35.00,'');
photos[6] = new photo(2906140,'180014','','gallery','http://admin.clikpic.com/roblea/images/localproduce.jpg',600,394,'Local produce','http://admin.clikpic.com/roblea/images/localproduce_thumb.jpg',130, 85,0, 0,'','','','',35.00,'');
photos[7] = new photo(2906150,'180014','','gallery','http://admin.clikpic.com/roblea/images/mountainbike1.jpg',400,600,'Mountain biking','http://admin.clikpic.com/roblea/images/mountainbike1_thumb.jpg',129, 194,0, 0,'','','','',35.00,'');
photos[8] = new photo(2906151,'180014','','gallery','http://admin.clikpic.com/roblea/images/mountainbike2.jpg',400,600,'Mountain biking 2','http://admin.clikpic.com/roblea/images/mountainbike2_thumb.jpg',129, 194,0, 0,'','','','',35.00,'');
photos[9] = new photo(2906155,'180014','','gallery','http://admin.clikpic.com/roblea/images/ski1.jpg',600,414,'Skiing 1','http://admin.clikpic.com/roblea/images/ski1_thumb.jpg',130, 89,0, 0,'','','','',35.00,'');
photos[10] = new photo(2906184,'180014','','gallery','http://admin.clikpic.com/roblea/images/ski4.jpg',600,443,'Skiing 4','http://admin.clikpic.com/roblea/images/ski4_thumb.jpg',130, 95,0, 0,'','','','',35.00,'');
photos[11] = new photo(2906187,'180014','','gallery','http://admin.clikpic.com/roblea/images/skichamonix.jpg',600,450,'Ski Chamonix','http://admin.clikpic.com/roblea/images/skichamonix_thumb.jpg',130, 97,0, 0,'','','','',35.00,'');
photos[12] = new photo(2906190,'180014','','gallery','http://admin.clikpic.com/roblea/images/snowboard.jpg',400,600,'Snowboarding','http://admin.clikpic.com/roblea/images/snowboard_thumb.jpg',129, 194,0, 0,'','','','',35.00,'');
photos[13] = new photo(2906191,'180014','','gallery','http://admin.clikpic.com/roblea/images/snowshoe.jpg',600,450,'Snowshoeing 1','http://admin.clikpic.com/roblea/images/snowshoe_thumb.jpg',130, 97,0, 0,'','','','',35.00,'');
photos[14] = new photo(2906194,'180014','','gallery','http://admin.clikpic.com/roblea/images/snowshoe2.jpg',405,600,'Snowshoeing 2','http://admin.clikpic.com/roblea/images/snowshoe2_thumb.jpg',129, 192,0, 0,'','','','',35.00,'');
photos[15] = new photo(2906196,'180014','','gallery','http://admin.clikpic.com/roblea/images/valleeblanche1.jpg',600,450,'Ski the vallee blanche','http://admin.clikpic.com/roblea/images/valleeblanche1_thumb.jpg',130, 97,0, 0,'','','','',35.00,'');
photos[16] = new photo(2906201,'180014','','gallery','http://admin.clikpic.com/roblea/images/winterchairlift.jpg',600,518,'Winter chair lift','http://admin.clikpic.com/roblea/images/winterchairlift_thumb.jpg',130, 112,0, 0,'','','','',35.00,'');
photos[17] = new photo(2906210,'179702','','gallery','http://admin.clikpic.com/roblea/images/banner13.jpg',600,132,'Banner 1','http://admin.clikpic.com/roblea/images/banner13_thumb.jpg',130, 28,0, 0,'','','','',35.00,'');
photos[18] = new photo(2906212,'179702','','gallery','http://admin.clikpic.com/roblea/images/banner21.jpg',600,132,'Banner 2','http://admin.clikpic.com/roblea/images/banner21_thumb.jpg',130, 28,0, 0,'','','','',35.00,'');
photos[19] = new photo(2906213,'179702','','gallery','http://admin.clikpic.com/roblea/images/banner31.jpg',600,132,'Banner 3','http://admin.clikpic.com/roblea/images/banner31_thumb.jpg',130, 28,0, 0,'','','','',35.00,'');
photos[20] = new photo(2906214,'179702','','gallery','http://admin.clikpic.com/roblea/images/banner41.jpg',600,132,'Banner 4','http://admin.clikpic.com/roblea/images/banner41_thumb.jpg',130, 28,0, 0,'','','','',35.00,'');
photos[21] = new photo(2906218,'179702','','gallery','http://admin.clikpic.com/roblea/images/banner51.jpg',600,132,'Banner 5','http://admin.clikpic.com/roblea/images/banner51_thumb.jpg',130, 28,0, 0,'','','','',35.00,'');
photos[22] = new photo(2906220,'179702','','gallery','http://admin.clikpic.com/roblea/images/banner61.jpg',600,132,'Banner 6','http://admin.clikpic.com/roblea/images/banner61_thumb.jpg',130, 28,0, 0,'','','','',35.00,'');
photos[23] = new photo(2906223,'179702','','gallery','http://admin.clikpic.com/roblea/images/banner71.jpg',600,132,'Banner 7','http://admin.clikpic.com/roblea/images/banner71_thumb.jpg',130, 28,0, 0,'','','','',35.00,'');
photos[24] = new photo(2906225,'179702','','gallery','http://admin.clikpic.com/roblea/images/banner81.jpg',600,132,'Banner 8','http://admin.clikpic.com/roblea/images/banner81_thumb.jpg',130, 28,0, 0,'','','','',35.00,'');
photos[25] = new photo(2906227,'179702','','gallery','http://admin.clikpic.com/roblea/images/banner91.jpg',600,132,'Banner 9','http://admin.clikpic.com/roblea/images/banner91_thumb.jpg',130, 28,0, 0,'','','','',35.00,'');
photos[26] = new photo(2906228,'179702','','gallery','http://admin.clikpic.com/roblea/images/banner101.jpg',600,132,'Banner 10','http://admin.clikpic.com/roblea/images/banner101_thumb.jpg',130, 28,0, 0,'','','','',35.00,'');
photos[27] = new photo(2906231,'179702','','gallery','http://admin.clikpic.com/roblea/images/banner111.jpg',600,132,'Banner 11','http://admin.clikpic.com/roblea/images/banner111_thumb.jpg',130, 28,0, 0,'','','','',35.00,'');
photos[28] = new photo(2906232,'179702','','gallery','http://admin.clikpic.com/roblea/images/banner121.jpg',600,132,'Banner 12','http://admin.clikpic.com/roblea/images/banner121_thumb.jpg',130, 28,0, 0,'','','','',35.00,'');
photos[29] = new photo(2906237,'179391','','section224951','http://admin.clikpic.com/roblea/images/aiguillesdechamonix.jpg',600,226,'Aiguilles de Chamonix','http://admin.clikpic.com/roblea/images/aiguillesdechamonix_thumb.jpg',130, 48,1, 1,'','','','',145.00,'Limited Edition print.  Dimensions: 45 by 17 inches (this includes a 2 inch white border)');
photos[30] = new photo(2906239,'179391','','section224951','http://admin.clikpic.com/roblea/images/lacdescheserysetmontblanc.jpg',600,259,'Lac des Cheserys and Mont Blanc','http://admin.clikpic.com/roblea/images/lacdescheserysetmontblanc_thumb.jpg',130, 56,1, 0,'','','','',145.00,'Limited Edition Print.  Dimensions: 39 by 17 inches (including a one inch white border)');
photos[31] = new photo(2906242,'179391','','section224951','http://admin.clikpic.com/roblea/images/montblancmassif.jpg',600,243,'Mont Blanc Massif','http://admin.clikpic.com/roblea/images/montblancmassif_thumb.jpg',130, 52,0, 0,'','','','',125.00,'Limited Edition print.  Dimensions: 42 by 17 inches (this includes a 1 inch white border)');
photos[32] = new photo(2906248,'179391','','section224951','http://admin.clikpic.com/roblea/images/valleydechamonix.jpg',600,355,'Chamonix valley','http://admin.clikpic.com/roblea/images/valleydechamonix_thumb.jpg',130, 76,0, 0,'','','','',105.00,'Limited Edition print.  Dimensions: 29 by 17 inches (this includes a 1 inch white border)');
photos[33] = new photo(2906246,'179391','','section224951','http://admin.clikpic.com/roblea/images/valleeblanche2.jpg',600,382,'Vallee Blanche','http://admin.clikpic.com/roblea/images/valleeblanche2_thumb.jpg',130, 82,0, 0,'','','','',125.00,'Limited Edition print.  Dimensions: 27 by 17 inches (this includes a 1 inch white border)');
photos[34] = new photo(2906238,'179391','','section224951','http://admin.clikpic.com/roblea/images/aiguilleverte1.jpg',600,379,'Aiguille Verte','http://admin.clikpic.com/roblea/images/aiguilleverte1_thumb.jpg',130, 82,0, 0,'','','','',125.00,'Limited Edition print.  Dimensions: 27 by 17 inches (this includes a 1 inch white border)');
photos[35] = new photo(2906245,'179391','','section224951','http://admin.clikpic.com/roblea/images/Skichamonixvalley1.jpg',600,405,'Ski Chamonix Valley','http://admin.clikpic.com/roblea/images/Skichamonixvalley1_thumb.jpg',130, 87,0, 0,'','','','',105.00,'Limited Edition print.  Dimensions: 25 by 17 inches (this includes a 1 inch white border)');
photos[36] = new photo(2906241,'179391','','section224951','http://admin.clikpic.com/roblea/images/leshoucheseglise1.jpg',470,633,'Les Houches','http://admin.clikpic.com/roblea/images/leshoucheseglise1_thumb.jpg',129, 175,0, 0,'','','','',95.00,'Limited Edition print.  Dimensions: 15 by 11 inches (this includes a 1 inch white border)');
photos[37] = new photo(2906236,'179391','','section224951','http://admin.clikpic.com/roblea/images/aiguilledumidi1.jpg',600,303,'Aiguille du Midi','http://admin.clikpic.com/roblea/images/aiguilledumidi1_thumb.jpg',130, 65,0, 0,'','','','',125.00,'Limited Edition print.  Dimensions: 36 by 17 inches (this includes a 1 inch white border)');

/***************************************************************************
* Create the array of Gallery objects                                      *
***************************************************************************/
galleries = new Array();
galleries[0] = new gallery(179702,'2906232,2906231,2906228,2906227,2906225,2906223,2906220,2906218,2906214,2906213','Banners','gallery');
galleries[1] = new gallery(180014,'2906133','general website images','gallery');
galleries[2] = new gallery(179391,'2906237','Limited Edition Prints','section224951');

