/***************************************************************************
* 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('3567875,3567238');
	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('3567875,3567238');
	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 = 'Jason Boa 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(3618196,'221695','','gallery','http://www3.clikpic.com/elvisboa/images/enztec_commercial_jason_boa.jpg',600,314,'','http://www3.clikpic.com/elvisboa/images/enztec_commercial_jason_boa_thumb.jpg',130, 68,0, 0,'Medical Instruments','','','','','');
photos[1] = new photo(3625316,'221695','','gallery','http://admin.clikpic.com/elvisboa/images/make_up_product_jason_boa.JPG',380,500,'','http://admin.clikpic.com/elvisboa/images/make_up_product_jason_boa_thumb.JPG',130, 171,0, 0,'','','','','','');
photos[2] = new photo(3625324,'221695','','gallery','http://admin.clikpic.com/elvisboa/images/necklace_product_jasonboa.jpg',333,500,'','http://admin.clikpic.com/elvisboa/images/necklace_product_jasonboa_thumb.jpg',130, 195,0, 0,'Jewellry range','','','','','');
photos[3] = new photo(3625089,'218053','','gallery','http://www3.clikpic.com/elvisboa/images/britomart_industrial_jason_boa.jpg',467,600,'','http://www3.clikpic.com/elvisboa/images/britomart_industrial_jason_boa_thumb.jpg',130, 167,0, 0,'','','','','','');
photos[4] = new photo(3567887,'218053','','gallery','http://www3.clikpic.com/elvisboa/images/Beckenham_library_architectural_jason_boa.jpg',553,600,'','http://www3.clikpic.com/elvisboa/images/Beckenham_library_architectural_jason_boa_thumb.jpg',130, 141,0, 0,'','','','','','');
photos[5] = new photo(3618200,'218053','','gallery','http://www3.clikpic.com/elvisboa/images/karndeen_commercial_jason_boa.jpg',600,400,'','http://www3.clikpic.com/elvisboa/images/karndeen_commercial_jason_boa_thumb.jpg',130, 87,0, 0,'Karndean Flooring','','','','','');
photos[6] = new photo(3567769,'218034','','gallery','http://www3.clikpic.com/elvisboa/images/catalogue_fashion_fashion_jason_boa.JPG',421,600,'','http://www3.clikpic.com/elvisboa/images/catalogue_fashion_fashion_jason_boa_thumb.JPG',130, 185,0, 0,'','','','','','');
photos[7] = new photo(3567881,'218034','','gallery','http://www3.clikpic.com/elvisboa/images/christine_fashion_jason_boa.jpg',400,600,'','http://www3.clikpic.com/elvisboa/images/christine_fashion_jason_boa_thumb.jpg',130, 195,0, 0,'Rodney Wayne: L\'Oreal Colour Trophy Competition Entry','','JAson Boa','','','');
photos[8] = new photo(3618191,'218034','','gallery','http://www3.clikpic.com/elvisboa/images/Blazey_commercial_jason_boa.jpg',400,600,'','http://www3.clikpic.com/elvisboa/images/Blazey_commercial_jason_boa_thumb.jpg',130, 195,0, 0,'','','','','','');
photos[9] = new photo(3618192,'218034','','gallery','http://www3.clikpic.com/elvisboa/images/Andy_Ellis_commercial_jason_boa.JPG',395,600,'','http://www3.clikpic.com/elvisboa/images/Andy_Ellis_commercial_jason_boa_thumb.JPG',130, 197,0, 0,'','','','','','');
photos[10] = new photo(3567786,'218054','','gallery','http://www3.clikpic.com/elvisboa/images/scott_technology_industrial_jason_boa.jpg',600,393,'','http://www3.clikpic.com/elvisboa/images/scott_technology_industrial_jason_boa_thumb.jpg',130, 85,0, 0,'Close-up of engineering work at Scott Technology','','','','','');
photos[11] = new photo(3567875,'218054','','gallery','http://www3.clikpic.com/elvisboa/images/geo_thermal_plant_industrial_jason_boa.jpg',130,88,'','http://www3.clikpic.com/elvisboa/images/geo_thermal_plant_industrial_jason_boa_thumb.jpg',130, 88,1, 0,'Taupo.  Bronze Award: Epson NZ Professional Photography Awards 2006.','','Jason Boa','','','');
photos[12] = new photo(3618199,'218055','','gallery','http://www3.clikpic.com/elvisboa/images/Nigel_Foley_editorial_jason_boa.jpg',600,393,'','http://www3.clikpic.com/elvisboa/images/Nigel_Foley_editorial_jason_boa_thumb.jpg',130, 85,0, 0,'Portrait: Unlimited','','','','','');
photos[13] = new photo(3625134,'218055','','gallery','http://www3.clikpic.com/elvisboa/images/Mito_editorial_jason_boa.JPG',500,359,'','http://www3.clikpic.com/elvisboa/images/Mito_editorial_jason_boa_thumb.JPG',130, 93,0, 0,'Portrait: MITO','','','','','');
photos[14] = new photo(3567765,'218055','','gallery','http://www3.clikpic.com/elvisboa/images/search_and_rescue_editorial_jason_boa.jpg',600,400,'','http://www3.clikpic.com/elvisboa/images/search_and_rescue_editorial_jason_boa_thumb.jpg',130, 87,0, 0,'HERALD ON SUNDAY','','','','','');
photos[15] = new photo(3618202,'218055','','gallery','http://www3.clikpic.com/elvisboa/images/petra_editorial_jason_boa.JPG',400,600,'','http://www3.clikpic.com/elvisboa/images/petra_editorial_jason_boa_thumb.JPG',130, 195,0, 0,'NEXT magazine','','','','','');
photos[16] = new photo(3625123,'218055','','gallery','http://www3.clikpic.com/elvisboa/images/David_Murray_editorial_jason_boa.jpg',333,500,'','http://www3.clikpic.com/elvisboa/images/David_Murray_editorial_jason_boa_thumb.jpg',130, 195,0, 0,'','','','','','');
photos[17] = new photo(3625154,'218055','','gallery','http://www3.clikpic.com/elvisboa/images/boa-4345.jpg',333,500,'','http://www3.clikpic.com/elvisboa/images/boa-4345_thumb.jpg',130, 195,0, 0,'The Listener','','','','','');
photos[18] = new photo(3618203,'218055','','gallery','http://www3.clikpic.com/elvisboa/images/shearing_editorial_jason_boa.jpg',410,600,'','http://www3.clikpic.com/elvisboa/images/shearing_editorial_jason_boa_thumb.jpg',130, 190,0, 0,'Sheep shearing','','','','','');
photos[19] = new photo(3625143,'218055','','gallery','http://www3.clikpic.com/elvisboa/images/Sandra_Manderson_Portrait_jason_boa.jpg',440,500,'','http://www3.clikpic.com/elvisboa/images/Sandra_Manderson_Portrait_jason_boa_thumb.jpg',130, 148,0, 0,'Portrait: The Listener','','','','','');
photos[20] = new photo(3625137,'218055','','gallery','http://www3.clikpic.com/elvisboa/images/phil_koegan_editorial_jason_boa.JPG',396,500,'','http://www3.clikpic.com/elvisboa/images/phil_koegan_editorial_jason_boa_thumb.JPG',130, 164,0, 0,'Portrait: The Listener','','','','','');
photos[21] = new photo(3625126,'218055','','gallery','http://www3.clikpic.com/elvisboa/images/janes_organic_meat_editorial_jason_boa_035w.jpg',500,500,'','http://www3.clikpic.com/elvisboa/images/janes_organic_meat_editorial_jason_boa_035w_thumb.jpg',130, 130,0, 0,'Portrait: Cuisine','','','','','');
photos[22] = new photo(3567897,'218052','','gallery','http://www3.clikpic.com/elvisboa/images/Sir_Peter_Elworthy_portrait_jason_boa.jpg',569,600,'','http://www3.clikpic.com/elvisboa/images/Sir_Peter_Elworthy_portrait_jason_boa_thumb.jpg',130, 137,0, 0,'Portrait for NZ House & Garden story','','Jason Boa','','','');
photos[23] = new photo(3618209,'218033','','gallery','http://www3.clikpic.com/elvisboa/images/new_brighton_pier_lanscape_jason_boa.jpg',600,416,'','http://www3.clikpic.com/elvisboa/images/new_brighton_pier_lanscape_jason_boa_thumb.jpg',130, 90,0, 0,'','','','','','');
photos[24] = new photo(3618210,'218033','','gallery','http://www3.clikpic.com/elvisboa/images/estuary_landscape_jason_boa.jpg',600,331,'','http://www3.clikpic.com/elvisboa/images/estuary_landscape_jason_boa_thumb.jpg',130, 72,0, 0,'','','','','','');
photos[25] = new photo(3567261,'218033','','gallery','http://www3.clikpic.com/elvisboa/images/lampost_landscape_jason_boa.jpg',600,599,'','http://www3.clikpic.com/elvisboa/images/lampost_landscape_jason_boa_thumb.jpg',130, 130,0, 0,'Bronze Award: Canon NZ Professional Photography Awards 2005','','','','','');
photos[26] = new photo(3567196,'218033','','gallery','http://www3.clikpic.com/elvisboa/images/New_Brighton_Pier_Landscape_Jason_Boa.jpg',566,600,'','http://www3.clikpic.com/elvisboa/images/New_Brighton_Pier_Landscape_Jason_Boa_thumb.jpg',130, 138,0, 0,'Night shot.  Silver Award: Epson NZ Professional Photography Awards 2006','','Jason Boa','','','');
photos[27] = new photo(3567760,'218033','','gallery','http://www3.clikpic.com/elvisboa/images/surfers_editorial_jason_boa.jpg',600,600,'','http://www3.clikpic.com/elvisboa/images/surfers_editorial_jason_boa_thumb.jpg',130, 130,0, 0,'Bronze Award: Canon NZ Professional Photography Awards 2005 (Editorial)','','','','','');
photos[28] = new photo(3567262,'218033','','gallery','http://www3.clikpic.com/elvisboa/images/fern_abstract_jason_boa.jpg',600,450,'','http://www3.clikpic.com/elvisboa/images/fern_abstract_jason_boa_thumb.jpg',130, 98,0, 0,'','','','','','');
photos[29] = new photo(3567238,'218033','','gallery','http://www3.clikpic.com/elvisboa/images/Flax_Landscape_Jason_Boa.jpg',600,198,'','http://www3.clikpic.com/elvisboa/images/Flax_Landscape_Jason_Boa_thumb.jpg',130, 43,1, 0,'','','','','','');
photos[30] = new photo(3567259,'218033','','gallery','http://www3.clikpic.com/elvisboa/images/cabbage_tree_landscape_jason_boa.jpg',600,511,'','http://www3.clikpic.com/elvisboa/images/cabbage_tree_landscape_jason_boa_thumb.jpg',130, 111,0, 0,'','','','','','');
photos[31] = new photo(3567191,'218033','','gallery','http://www3.clikpic.com/elvisboa/images/Fern_Fronds_Landscape_Jason_Boa.jpg',400,600,'','http://www3.clikpic.com/elvisboa/images/Fern_Fronds_Landscape_Jason_Boa_thumb.jpg',130, 195,0, 0,'Silver Award: Epson NZ Professional Photography Awards 2006','','','','','');
photos[32] = new photo(3567256,'218033','','gallery','http://www3.clikpic.com/elvisboa/images/architectural_jewel_abstract_jason_boa.jpg',403,600,'','http://www3.clikpic.com/elvisboa/images/architectural_jewel_abstract_jason_boa_thumb.jpg',130, 194,0, 0,'','','','','','');
photos[33] = new photo(3567221,'218033','','gallery','http://www3.clikpic.com/elvisboa/images/Lighthouse_New_Brighton_Landscape_Jason_Boa.jpg',451,600,'','http://www3.clikpic.com/elvisboa/images/Lighthouse_New_Brighton_Landscape_Jason_Boa_thumb.jpg',130, 173,0, 0,'Bronze Award: Epson NZ Professional Photography Awards 2007','','','','','');

/***************************************************************************
* Create the array of Gallery objects                                      *
***************************************************************************/
galleries = new Array();
galleries[0] = new gallery(221694,'3625324,3625316,3618196','COMMERCIAL 1','gallery');
galleries[1] = new gallery(221695,'3625324,3625316,3618196','PRODUCT','gallery');
galleries[2] = new gallery(218053,'3625089,3618200,3567887','ARCHITECTURE','gallery');
galleries[3] = new gallery(218034,'3618192,3618191,3567881,3567769','COMMERCIAL','gallery');
galleries[4] = new gallery(218055,'3625154,3625143,3625137,3625134,3625126,3625123,3618203,3618202,3618199,3567765','EDITORIAL','gallery');
galleries[5] = new gallery(218054,'3567875,3567786','INDUSTRIAL','gallery');
galleries[6] = new gallery(218052,'3567897','PORTRAITS','gallery');
galleries[7] = new gallery(218033,'3618210,3618209,3567760,3567262,3567261,3567259,3567256,3567238,3567221,3567196','ART PRINTS','gallery');

