/***************************************************************************
* 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('3480278');
	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('3480278');
	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 = 'Nuala Whales Artist: ' + 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>Artist </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(3480278,'212837','','gallery','http://www3.clikpic.com/nwhales/images/IMG_3756 (Large).JPG',400,236,'Days Gone By 1','http://www3.clikpic.com/nwhales/images/IMG_3756 (Large)_thumb.JPG',130, 77,1, 1,'Rusty wreck near Shell Bay in Poole Harbour<br>\r\nOriginal Oil on Canvas<br>\r\n£375 Framed','','Nuala Whales','',375.00,'Framed Original Oil on Canvas');
photos[1] = new photo(3480329,'212837','','gallery','http://www3.clikpic.com/nwhales/images/IMG_3755 (Large).JPG',400,236,'Days Gone By 2','http://www3.clikpic.com/nwhales/images/IMG_3755 (Large)_thumb.JPG',130, 77,0, 0,'Rusty Wreck near Shell Bay in Poole Harbour<br>\r\nOriginal Oil on Canvas<br>\r\n£375 Framed','','Nuala Whales','',375.00,'Framed Original Oil on Canvas');
photos[2] = new photo(3482540,'212837','','gallery','http://www3.clikpic.com/nwhales/images/White Sails [1024x768].jpg',400,402,'White Sails off Cowes','http://www3.clikpic.com/nwhales/images/White Sails [1024x768]_thumb.jpg',130, 131,0, 0,'White Sails off Cowes<br>\r\nOriginal Oils on canvas<br>\r\n£500 (framed)','','Nuala Whales','','','');
photos[3] = new photo(3482548,'212837','','gallery','http://www3.clikpic.com/nwhales/images/Into the Swash Channel [1024x768].jpg',400,401,'Into the Swash Channel Poole','http://www3.clikpic.com/nwhales/images/Into the Swash Channel [1024x768]_thumb.jpg',130, 130,0, 0,'Into the Swash Channel Poole<br>\r\nOriginal oils on canvas<br>\r\n£350 (framed)','','Nuala Whales','','','');
photos[4] = new photo(3482554,'212837','','gallery','http://www3.clikpic.com/nwhales/images/Norma Jean  OS [1024x768].jpg',400,410,'Norma Jean Comes Home','http://www3.clikpic.com/nwhales/images/Norma Jean  OS [1024x768]_thumb.jpg',130, 133,0, 0,'Norma Jean Comes Home<br>\r\nOriginal oils on canvas<br>\r\n£350 (framed)','','Nuala Whales','','','');
photos[5] = new photo(3482562,'212837','','gallery','http://www3.clikpic.com/nwhales/images/Fine day at Harry\'s Rocks [1024x768].jpg',400,395,'Fine day at Old Harry\'s','http://www3.clikpic.com/nwhales/images/Fine day at Harry\'s Rocks [1024x768]_thumb.jpg',130, 128,0, 0,'Fine Day at Old Harry\'s Rock Dorset<br>\r\nOriginal Oil on canvas<br>\r\n£350 (framed)','','Nuala Whales','','','');
photos[6] = new photo(3482572,'212837','','gallery','http://www3.clikpic.com/nwhales/images/Hearts a Spinnaker [1024x768]1.jpg',400,272,'Hearts a Spinnaker','http://www3.clikpic.com/nwhales/images/Hearts a Spinnaker [1024x768]1_thumb.jpg',130, 88,0, 0,'Hearts a Spinnaker<br>\r\nOriginal Oils on canvas<br>\r\n£380 (framed)','','Nuala Whales','','','');
photos[7] = new photo(3482712,'212954','','gallery','http://www3.clikpic.com/nwhales/images/Nu- One Yaght copy [1024x768].jpg',400,397,'One Yacht','http://www3.clikpic.com/nwhales/images/Nu- One Yaght copy [1024x768]_thumb.jpg',130, 129,0, 1,'One Yacht <br>\r\nOriginal Oils on Canvas<br>\r\n£sold','','Nuala Whales','','','');
photos[8] = new photo(3482721,'212954','','gallery','http://www3.clikpic.com/nwhales/images/Nu- Three Pink sails [1024x768].jpg',400,399,'Three Pink Sails','http://www3.clikpic.com/nwhales/images/Nu- Three Pink sails [1024x768]_thumb.jpg',130, 130,0, 0,'Three Pink Sails<br>\r\nOriginal Oil on Canvas<br>\r\n£350 (framed)','','Nuala Whales','','','');
photos[9] = new photo(3480292,'212838','','gallery','http://www3.clikpic.com/nwhales/images/IMG_3761 (Large).jpg',400,398,'A Welsh Tree','http://www3.clikpic.com/nwhales/images/IMG_3761 (Large)_thumb.jpg',130, 129,0, 0,'A typical scene in the hills, the title says it all<br>\r\nOriginal Oil on Canvas<br>\r\n£375 Framed','','Nuala Whales','','','');
photos[10] = new photo(3482456,'212838','','gallery','http://www3.clikpic.com/nwhales/images/IMG_0280 [1024x768].JPG',400,399,'Tartan Fields 1','http://www3.clikpic.com/nwhales/images/IMG_0280 [1024x768]_thumb.JPG',130, 130,0, 0,'Tartan Fields 1<br>\r\nOriginal Oil on Canvas<br>\r\n£ SOLD','','Nuala Whales','','','');
photos[11] = new photo(3482457,'212838','','gallery','http://www3.clikpic.com/nwhales/images/IMG_0281 [1024x768].JPG',400,403,'Tartan Fields 2','http://www3.clikpic.com/nwhales/images/IMG_0281 [1024x768]_thumb.JPG',130, 131,0, 0,'Tartan Fields 2<br>\r\nOriginal Oil on Canvas<br>\r\n£ SOLD','','Nuala Whales','','','');
photos[12] = new photo(3512719,'212838','','gallery','http://admin.clikpic.com/nwhales/images/IMG_2366 [1024x768].jpg',400,388,'Landscape with a river','http://admin.clikpic.com/nwhales/images/IMG_2366 [1024x768]_thumb.jpg',130, 126,0, 0,'Landscape with a river<br>\r\nOriginal Oil on Canvas<br>\r\n£250','','Nuala Whales','','','');
photos[13] = new photo(3480328,'212838','','gallery','http://www3.clikpic.com/nwhales/images/IMG_2621 (Large).jpg',400,287,'Landscape 1','http://www3.clikpic.com/nwhales/images/IMG_2621 (Large)_thumb.jpg',130, 93,0, 1,'A walk in Wash Common near Newbury<br>\r\nOriginal Oil on Canvas<br>\r\n£185 (Framed)','','Nuala Whales','','','');
photos[14] = new photo(3482499,'212838','','gallery','http://www3.clikpic.com/nwhales/images/IMG_2840 [1024x768].JPG',400,279,'Landscape 2','http://www3.clikpic.com/nwhales/images/IMG_2840 [1024x768]_thumb.JPG',130, 91,0, 0,'Landscape 2<br>\r\nOriginal Oil on Canvas<br>\r\n£185 (Framed)','','Nuala Whales','','','');
photos[15] = new photo(3481464,'212924','','gallery','http://www3.clikpic.com/nwhales/images/Love Christmas Card 1 [Desktop Resolution].jpg',400,402,'Love Christmas','http://www3.clikpic.com/nwhales/images/Love Christmas Card 1 [Desktop Resolution]_thumb.jpg',130, 131,0, 0,'Christmas Image<br>\r\nOriginal Oil on Canvas<br>\r\n£','','Nuala Whales','','','');
photos[16] = new photo(3482147,'212924','','gallery','http://www3.clikpic.com/nwhales/images/St Mary work 3 [1024x768].jpg',400,551,'St. Mary','http://www3.clikpic.com/nwhales/images/St Mary work 3 [1024x768]_thumb.jpg',130, 179,0, 0,'','','Nuala Whales','','','');
photos[17] = new photo(3482219,'212924','','gallery','http://www3.clikpic.com/nwhales/images/IMG_0275 copy [1024x768].jpg',400,399,'Monks \'n Prayer Flags','http://www3.clikpic.com/nwhales/images/IMG_0275 copy [1024x768]_thumb.jpg',130, 130,0, 0,'Tibetan Monks<br>\r\nOriginal Oil on Canvas<br>\r\n£','','Nuala Whales','','','');
photos[18] = new photo(3482255,'212924','','gallery','http://www3.clikpic.com/nwhales/images/Giraff Tpot for cards [1024x768].jpg',400,400,'Giraffe Tea Pot','http://www3.clikpic.com/nwhales/images/Giraff Tpot for cards [1024x768]_thumb.jpg',130, 130,0, 0,'Giraffe Tea Pot<br>\r\nOriginal Oil on Canvas<br>\r\n£ SOLD','','Nuala Whales','','','');
photos[19] = new photo(3482297,'212924','','gallery','http://www3.clikpic.com/nwhales/images/leo Tpot for card [1024x768].jpg',400,400,'Leopard Tea Pot','http://www3.clikpic.com/nwhales/images/leo Tpot for card [1024x768]_thumb.jpg',130, 130,0, 0,'Leopard Tea Pot<br>\r\nOriginal Oil on Canvas<br>\r\n£ SOLD','','Nuala Whales','','','');
photos[20] = new photo(3482304,'212924','','gallery','http://www3.clikpic.com/nwhales/images/Zebra Tpot for cards [1024x768].jpg',400,400,'Zebra Tea Pot','http://www3.clikpic.com/nwhales/images/Zebra Tpot for cards [1024x768]_thumb.jpg',130, 130,0, 0,'Zebra Tea Pot<br>\r\nOriginal Oil on Canvas<br>\r\n£ SOLD','','Nuala Whales','','','');
photos[21] = new photo(3480586,'212854','','gallery','http://www3.clikpic.com/nwhales/images/IMG_2640 (Large).JPG',400,267,'Framing Studio','http://www3.clikpic.com/nwhales/images/IMG_2640 (Large)_thumb.JPG',130, 87,0, 0,'Innerpiece Framing Studio','','','','','');
photos[22] = new photo(3481723,'212854','','gallery','http://www3.clikpic.com/nwhales/images/Innerpiece Studio Pat 027 [1024x768].jpg',400,300,'Nu at work','http://www3.clikpic.com/nwhales/images/Innerpiece Studio Pat 027 [1024x768]_thumb.jpg',130, 98,0, 0,'Nuala working in her Framing Studio','','','','','');
photos[23] = new photo(3481603,'212854','','gallery','http://www3.clikpic.com/nwhales/images/GCF4.jpg',300,304,'Guild Commended Framer','http://www3.clikpic.com/nwhales/images/GCF4_thumb.jpg',130, 132,0, 1,'Nuala Whales in the owner/operator of Inner Piece Framing Studio. A member of the Fine Art Trade Guild she has passed the necessary exams to become a Commended Framer.','','','','','');

/***************************************************************************
* Create the array of Gallery objects                                      *
***************************************************************************/
galleries = new Array();
galleries[0] = new gallery(212837,'3480278','Solent & Dorset Coast','gallery');
galleries[1] = new gallery(212954,'3482712','Beach Scenes','gallery');
galleries[2] = new gallery(212838,'3480328','Landscapes','gallery');
galleries[3] = new gallery(212924,'3482304,3482297,3482255,3482219,3482147,3481464','General Interest','gallery');
galleries[4] = new gallery(212854,'3481603','Nu\'s Framing Studio','gallery');

