/***************************************************************************
* 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('3163930');
	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('3163930');
	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 = 'anna hegarty jewellery: ' + 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(2171679,'','','','http://www1.clikpic.com/annahegarty/images/Web image 1.jpg',500,510,'Leaf and Rose rings, 2008','http://www1.clikpic.com/annahegarty/images/Web image 1_thumb.jpg',130, 133,0, 0,'Selection of silver, gold plated silver, and oxidised silver rings. Can be worn individually or as a pair.','','','','','');
photos[1] = new photo(2172063,'','','','http://www1.clikpic.com/annahegarty/images/Web image 5.jpg',500,534,'Oval Brooch, 2008','http://www1.clikpic.com/annahegarty/images/Web image 5_thumb.jpg',130, 139,0, 0,'Rose patterned silver sheet set in an oval frame with oxidised silver and gold plated silver domed detailing.','','','',220.00,'');
photos[2] = new photo(2172064,'','','','http://www1.clikpic.com/annahegarty/images/Web image 6.jpg',425,567,'Rose Brooch, 2008','http://www1.clikpic.com/annahegarty/images/Web image 6_thumb.jpg',130, 173,0, 0,'Domed silver \'wire\' cage with oxidised silver back.','','','',130.00,'');
photos[3] = new photo(2172067,'','','','http://www1.clikpic.com/annahegarty/images/Web images 7.jpg',425,567,'Rose Neckpiece, 2008','http://www1.clikpic.com/annahegarty/images/Web images 7_thumb.jpg',130, 173,0, 1,'Oxidised silver pendant with gold plated silver detail.','','','',90.00,'');
photos[4] = new photo(2172073,'','','','http://www1.clikpic.com/annahegarty/images/Web image 21.jpg',425,567,'Leaf Neckpiece, 2008','http://www1.clikpic.com/annahegarty/images/Web image 21_thumb.jpg',130, 173,0, 0,'Domed silver \'wire\' cage set in round frame with 9ct gold detail.','','','',130.00,'');
photos[5] = new photo(2172077,'','','','http://www1.clikpic.com/annahegarty/images/Web image 31.jpg',454,567,'Leaf Brooch, 2008','http://www1.clikpic.com/annahegarty/images/Web image 31_thumb.jpg',130, 162,0, 0,'Saw pierced silver sheet with 9ct gold detailing set in a silver frame.','','','',170.00,'');
photos[6] = new photo(2325411,'','','','http://www1.clikpic.com/annahegarty/images/Rose Wire Earrings.jpg',500,340,'Rose Wire Earrings, 2008','http://www1.clikpic.com/annahegarty/images/Rose Wire Earrings_thumb.jpg',130, 88,0, 0,'Domed silver wire structured earrings. Oxidised on the inside, polished silver on the back.','','','','','');
photos[7] = new photo(2325424,'','','','http://www1.clikpic.com/annahegarty/images/Wreath earrings.jpg',500,348,'Leaf Earrings, 2008','http://www1.clikpic.com/annahegarty/images/Wreath earrings_thumb.jpg',130, 90,0, 0,'Patterned silver earrings with oxidised leaf details','','','','','');
photos[8] = new photo(2619909,'','','','http://www1.clikpic.com/annahegarty/images/BroochCluster3.jpg',375,500,'Selection of Brooches, 2008','http://www1.clikpic.com/annahegarty/images/BroochCluster3_thumb.jpg',98, 130,0, 0,'','','','','','');
photos[9] = new photo(3163786,'','','','http://www1.clikpic.com/annahegarty/images/Copy (1) of IMG_3162a.jpg',500,500,'Leaf 2 Stud Earrings, 2008','http://www1.clikpic.com/annahegarty/images/Copy (1) of IMG_3162a_thumb.jpg',130, 130,0, 0,'White Silver and Gold-plated Silver','','','','','');
photos[10] = new photo(3163796,'','','','http://www1.clikpic.com/annahegarty/images/Copy (1) of IMG_3218a.jpg',500,500,'Square Leaf Cluster Earrings, 2008','http://www1.clikpic.com/annahegarty/images/Copy (1) of IMG_3218a_thumb.jpg',130, 130,0, 0,'Oxidised Silver and Gold-plated Silver','','','','','');
photos[11] = new photo(3325013,'','','','http://www1.clikpic.com/annahegarty/images/Leaf 1 Stud Earring (Black).jpg',415,500,'Leaf 1 Stud Earring (Black), 2008','http://www1.clikpic.com/annahegarty/images/Leaf 1 Stud Earring (Black)_thumb.jpg',108, 130,0, 0,'Oxidised Silver','','','','','');
photos[12] = new photo(2171695,'143892','','gallery','http://www1.clikpic.com/annahegarty/images/Web image 7.jpg',500,738,'','http://www1.clikpic.com/annahegarty/images/Web image 7_thumb.jpg',130, 192,0, 1,'','','Anna Hegarty','','','');
photos[13] = new photo(3163965,'143891','','gallery','http://www1.clikpic.com/annahegarty/images/IMG_3202a.jpg',500,500,'Circle Leaf Neckpiece, 2008','http://www1.clikpic.com/annahegarty/images/IMG_3202a_thumb.jpg',130, 130,0, 1,'Silver and 9ct Gold','','','','','');
photos[14] = new photo(2172056,'143892','','gallery','http://www1.clikpic.com/annahegarty/images/Web images 4.jpg',500,664,'','http://www1.clikpic.com/annahegarty/images/Web images 4_thumb.jpg',130, 173,0, 0,'','','Anna Hegarty','','','');
photos[15] = new photo(3163810,'143891','','gallery','http://www1.clikpic.com/annahegarty/images/IMG_3092a.jpg',500,500,'Rose Circle Neckpiece, 2008','http://www1.clikpic.com/annahegarty/images/IMG_3092a_thumb.jpg',130, 130,0, 0,'Oxidised Silver and Gold-plated Silver','','','','','');
photos[16] = new photo(2172049,'143892','','gallery','http://www1.clikpic.com/annahegarty/images/Web images 1.jpg',500,645,'','http://www1.clikpic.com/annahegarty/images/Web images 1_thumb.jpg',130, 168,0, 0,'','','Anna Hegarty','','','');
photos[17] = new photo(3163807,'143891','','gallery','http://www1.clikpic.com/annahegarty/images/IMG_3083_1a.jpg',500,500,'Flat Frame Circle Wire Necklace, 2008','http://www1.clikpic.com/annahegarty/images/IMG_3083_1a_thumb.jpg',130, 130,0, 0,'Gold-plated Silver','','','','','');
photos[18] = new photo(2172052,'143892','','gallery','http://www1.clikpic.com/annahegarty/images/Web images 3.jpg',481,700,'','http://www1.clikpic.com/annahegarty/images/Web images 3_thumb.jpg',130, 189,0, 0,'','','Anna Hegarty','','','');
photos[19] = new photo(3163963,'143891','','gallery','http://www1.clikpic.com/annahegarty/images/IMG_3188a.jpg',500,500,'Flat Frame Circle Necklace, 2008','http://www1.clikpic.com/annahegarty/images/IMG_3188a_thumb.jpg',130, 130,0, 0,'White Silver','','','','','');
photos[20] = new photo(2172129,'143892','','gallery','http://www1.clikpic.com/annahegarty/images/Web images 21.jpg',500,378,'','http://www1.clikpic.com/annahegarty/images/Web images 21_thumb.jpg',130, 98,0, 0,'','','Anna Hegarty','','','');
photos[21] = new photo(3163927,'143891','','gallery','http://www1.clikpic.com/annahegarty/images/IMG_3114a.jpg',500,500,'White Leaf Patterned Brooch with Black Detail, 2008','http://www1.clikpic.com/annahegarty/images/IMG_3114a_thumb.jpg',130, 130,0, 0,'White Silver and Oxidised Silver','','','','','');
photos[22] = new photo(2172055,'143892','','gallery','http://www1.clikpic.com/annahegarty/images/Web images 6.jpg',448,700,'','http://www1.clikpic.com/annahegarty/images/Web images 6_thumb.jpg',130, 203,0, 0,'','','Anna Hegarty','','','');
photos[23] = new photo(3164079,'143891','','gallery','http://www1.clikpic.com/annahegarty/images/IMG_3225a.jpg',500,500,'White Circle Brooch with Leaf Detail, 2008','http://www1.clikpic.com/annahegarty/images/IMG_3225a_thumb.jpg',130, 130,0, 0,'White Silver and Gold-plated Silver','','','','','');
photos[24] = new photo(3163813,'143891','','gallery','http://www1.clikpic.com/annahegarty/images/IMG_3098_1a.jpg',500,500,'Black Circle Brooch with Rose Cluster, 2008','http://www1.clikpic.com/annahegarty/images/IMG_3098_1a_thumb.jpg',130, 130,0, 0,'Oxidised Silver and Gold-plated Silver','','','','','');
photos[25] = new photo(3163930,'143891','','gallery','http://www1.clikpic.com/annahegarty/images/IMG_3135a.jpg',500,500,'Box Leaf Cluster Brooch, 2008','http://www1.clikpic.com/annahegarty/images/IMG_3135a_thumb.jpg',130, 130,1, 0,'White Silver','','','','','');
photos[26] = new photo(3163929,'143891','','gallery','http://www1.clikpic.com/annahegarty/images/IMG_3116_1a.jpg',500,500,'Circle Leaf Pattern Earrings, 2008','http://www1.clikpic.com/annahegarty/images/IMG_3116_1a_thumb.jpg',130, 130,0, 0,'White and Oxidised','','','','','');
photos[27] = new photo(3163820,'143891','','gallery','http://www1.clikpic.com/annahegarty/images/IMG_3105a.jpg',500,500,'Circle Leaf Pattern Earring, 2008','http://www1.clikpic.com/annahegarty/images/IMG_3105a_thumb.jpg',130, 130,0, 0,'Oxidised Silver and Gold-plated Silver','','','','','');
photos[28] = new photo(3324972,'143891','','gallery','http://www1.clikpic.com/annahegarty/images/IMG_3222a.jpg',500,500,'Square Leaf Cluster Earrings (Black), 2008','http://www1.clikpic.com/annahegarty/images/IMG_3222a_thumb.jpg',130, 130,0, 0,'Oxidised Silver','','','','','');
photos[29] = new photo(3324978,'143891','','gallery','http://www1.clikpic.com/annahegarty/images/IMG_3177b.jpg',500,500,'Square Leaf Cluster Earring (Gold-plated), 2008','http://www1.clikpic.com/annahegarty/images/IMG_3177b_thumb.jpg',130, 130,0, 0,'Gold-plated Silver','','','','','');
photos[30] = new photo(3325008,'143891','','gallery','http://www1.clikpic.com/annahegarty/images/IMG_3230_1b.jpg',500,500,'Double Domed Rose CLuster Cufflinks (Black) (Gold-plated), 2008','http://www1.clikpic.com/annahegarty/images/IMG_3230_1b_thumb.jpg',130, 130,0, 0,'Oxidised Silver and Gold-plated Silver','','','','','');
photos[31] = new photo(3163797,'143891','','gallery','http://www1.clikpic.com/annahegarty/images/IMG_3046a.jpg',500,500,'Double Domed Rose Cluster Cufflinks (Black), 2008','http://www1.clikpic.com/annahegarty/images/IMG_3046a_thumb.jpg',130, 130,0, 0,'Oxidised Silver','','','','','');
photos[32] = new photo(3163931,'143891','','gallery','http://www1.clikpic.com/annahegarty/images/IMG_3172a.jpg',500,500,'Double Domed Rose Cluster Ring, 2008','http://www1.clikpic.com/annahegarty/images/IMG_3172a_thumb.jpg',130, 130,0, 0,'White Silver','','','','','');
photos[33] = new photo(3164081,'143891','','gallery','http://www1.clikpic.com/annahegarty/images/IMG_3234a.jpg',500,500,'Flat Frame Oval Drop Earring, 2008','http://www1.clikpic.com/annahegarty/images/IMG_3234a_thumb.jpg',130, 130,0, 0,'White Silver','','','','','');
photos[34] = new photo(3325018,'143891','','gallery','http://www1.clikpic.com/annahegarty/images/IMG_3161a.jpg',500,500,'Leaf 1 Stud Earring (Miniature, Gold-plated), 2008','http://www1.clikpic.com/annahegarty/images/IMG_3161a_thumb.jpg',130, 130,0, 0,'Gold-plated Silver','','','','','');
photos[35] = new photo(3325021,'143891','','gallery','http://www1.clikpic.com/annahegarty/images/IMG_3157a.jpg',500,500,'Leaf 1 Stud Earring (White, Patterned), 2008','http://www1.clikpic.com/annahegarty/images/IMG_3157a_thumb.jpg',130, 130,0, 0,'White Silver','','','','','');
photos[36] = new photo(3325125,'143891','','gallery','http://www1.clikpic.com/annahegarty/images/IMG_3154a.jpg',500,500,'Leaf 1 Stud Earring (Gold-Plated), 2008','http://www1.clikpic.com/annahegarty/images/IMG_3154a_thumb.jpg',130, 130,0, 0,'Gold-plated Silver','','','','','');
photos[37] = new photo(3325030,'143891','','gallery','http://www1.clikpic.com/annahegarty/images/IMG_3155a.jpg',500,500,'Leaf 2 Stud Earring (White), 2008','http://www1.clikpic.com/annahegarty/images/IMG_3155a_thumb.jpg',130, 130,0, 0,'White Silver','','','','','');
photos[38] = new photo(3164083,'143891','','gallery','http://www1.clikpic.com/annahegarty/images/IMG_3235a.jpg',500,500,'Wire Leaf Stud Earring, 2008','http://www1.clikpic.com/annahegarty/images/IMG_3235a_thumb.jpg',130, 130,0, 0,'Gold-plated Silver','','','','','');
photos[39] = new photo(3163966,'143891','','gallery','http://www1.clikpic.com/annahegarty/images/IMG_3208a.jpg',500,500,'Small Wire Leaf Necklace and Small Solid Leaf Necklace, 2008','http://www1.clikpic.com/annahegarty/images/IMG_3208a_thumb.jpg',130, 130,0, 0,'White Silver','','','','','');
photos[40] = new photo(3164077,'143891','','gallery','http://www1.clikpic.com/annahegarty/images/IMG_3217a.jpg',500,500,'Small Solid Leaf Necklace and Leaf Earring','http://www1.clikpic.com/annahegarty/images/IMG_3217a_thumb.jpg',130, 130,0, 0,'White Silver','','','','','');
photos[41] = new photo(3164076,'143891','','gallery','http://www1.clikpic.com/annahegarty/images/IMG_3212a.jpg',500,500,'Small Wire Leaf Necklace and Wire Leaf Earring, 2008','http://www1.clikpic.com/annahegarty/images/IMG_3212a_thumb.jpg',130, 130,0, 0,'White Silver and Gold-plated Silver','','','','','');

/***************************************************************************
* Create the array of Gallery objects                                      *
***************************************************************************/
galleries = new Array();
galleries[0] = new gallery(143891,'3163965','Jewellery','gallery');
galleries[1] = new gallery(143892,'2171695','Photographs','gallery');

