/***************************************************************************
* 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('2739339,2739314,2738752,2738745,2738743,2738739,2738737,2738728,2738727,2738724');
	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('2739339,2739314,2738752,2738745,2738743,2738739,2738737,2738728,2738727,2738724');
	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 && !((1) || (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 = 'Beads To Bedazzle: ' + 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(2738724,'','','','http://admin2.clikpic.com/susanread/images/suereadjewellery 075 copy.jpg',500,453,'','http://admin2.clikpic.com/susanread/images/suereadjewellery 075 copy_thumb.jpg',130, 118,1, 0,'','','','','','');
photos[1] = new photo(2738727,'','','','http://admin2.clikpic.com/susanread/images/suereadjewellery 092 copy.jpg',500,329,'','http://admin2.clikpic.com/susanread/images/suereadjewellery 092 copy_thumb.jpg',130, 86,1, 0,'','','','','','');
photos[2] = new photo(2738728,'','','','http://admin2.clikpic.com/susanread/images/suereadjewellery 127 copy.jpg',500,394,'','http://admin2.clikpic.com/susanread/images/suereadjewellery 127 copy_thumb.jpg',130, 102,1, 0,'','','','','','');
photos[3] = new photo(2738737,'','','','http://admin2.clikpic.com/susanread/images/suereadjewellery 153 copy.jpg',500,357,'','http://admin2.clikpic.com/susanread/images/suereadjewellery 153 copy_thumb.jpg',130, 93,1, 0,'','','','','','');
photos[4] = new photo(2738739,'','','','http://admin2.clikpic.com/susanread/images/suereadjewellery 162 copy.jpg',500,346,'','http://admin2.clikpic.com/susanread/images/suereadjewellery 162 copy_thumb.jpg',130, 90,1, 0,'','','','','','');
photos[5] = new photo(2738743,'','','','http://admin2.clikpic.com/susanread/images/suereadjewellery 231 copy.jpg',500,336,'','http://admin2.clikpic.com/susanread/images/suereadjewellery 231 copy_thumb.jpg',130, 87,1, 0,'','','','','','');
photos[6] = new photo(2738745,'','','','http://admin2.clikpic.com/susanread/images/suereadjewellery 252 copy.jpg',500,340,'','http://admin2.clikpic.com/susanread/images/suereadjewellery 252 copy_thumb.jpg',130, 88,1, 0,'','','','','','');
photos[7] = new photo(2738752,'','','','http://admin2.clikpic.com/susanread/images/suereadjewellery 290 copy.jpg',500,318,'','http://admin2.clikpic.com/susanread/images/suereadjewellery 290 copy_thumb.jpg',130, 83,1, 0,'','','','','','');
photos[8] = new photo(2739314,'','','','http://admin2.clikpic.com/susanread/images/RR1.jpg',427,429,'','http://admin2.clikpic.com/susanread/images/RR1_thumb.jpg',130, 131,1, 0,'','','','','','');
photos[9] = new photo(2739339,'','','','http://admin2.clikpic.com/susanread/images/RR2.jpg',347,345,'','http://admin2.clikpic.com/susanread/images/RR2_thumb.jpg',130, 129,1, 0,'','','','','','');
photos[10] = new photo(2739492,'133606','','gallery','http://admin2.clikpic.com/susanread/images/SR1.jpg',500,375,'SOFYA','http://admin2.clikpic.com/susanread/images/SR1_thumb.jpg',130, 98,0, 0,'Blue/bronze ceramic beads with faceted crystals and cubic zircona.  Gold clasp.<br>\r\nLength: 43cm','','','',60.00,'');
photos[11] = new photo(2739531,'133606','','gallery','http://admin2.clikpic.com/susanread/images/SR2.jpg',500,375,'KARINA','http://admin2.clikpic.com/susanread/images/SR2_thumb.jpg',130, 98,0, 0,'Rubillate agate, red aurora borealis Swarvoski crystals and small Czech crystals.  Silver clasp.<br>\r\nLength: 46cm','','','',60.00,'');
photos[12] = new photo(2739540,'133606','','gallery','http://admin2.clikpic.com/susanread/images/SR9.jpg',500,375,'NATASHA','http://admin2.clikpic.com/susanread/images/SR9_thumb.jpg',130, 98,0, 0,'Smoky quartz, black agate and hematite with large black Swarvoski pendant.  Silver clasp.<br>\r\nLength: 54cm','','','',120.00,'');
photos[13] = new photo(2739598,'133606','','gallery','http://admin2.clikpic.com/susanread/images/SR11.jpg',500,375,'IRINA','http://admin2.clikpic.com/susanread/images/SR11_thumb.jpg',130, 98,0, 0,'Black agate, gold plate diamante, Czech ameythst crytals and large ionic gold plated focal.  Gold clasp.<br>\r\nLength: 49cm','','','',120.00,'');
photos[14] = new photo(2739604,'133606','','gallery','http://admin2.clikpic.com/susanread/images/SR10.jpg',500,375,'TANYA','http://admin2.clikpic.com/susanread/images/SR10_thumb.jpg',130, 98,0, 0,'Gold and orange ceramic beads, bronze fresh water pearls and small Czech crystals.  Gold clasp.<br>\r\nLength: 70cm','','','',85.00,'');
photos[15] = new photo(2739608,'133606','','gallery','http://admin2.clikpic.com/susanread/images/SR6.jpg',500,375,'ALEXANDRA','http://admin2.clikpic.com/susanread/images/SR6_thumb.jpg',130, 98,0, 0,'Hand-made blue glass beads with blue crystals and fire polished crystals.  Set of three necklaces.  Silver clasp.<br>\r\nLengths: 39cm, 44cm & 51cm','','','',105.00,'');
photos[16] = new photo(2739631,'133606','','gallery','http://admin2.clikpic.com/susanread/images/SR81.jpg',500,375,'YELENA','http://admin2.clikpic.com/susanread/images/SR81_thumb.jpg',130, 98,0, 0,'Faceted Cornelian and green crystal.  Silver clasp.<br>\r\nLength: 70cm','','','',65.00,'');
photos[17] = new photo(2047479,'133606','','gallery','http://admin2.clikpic.com/susanread/images/20051.jpg',480,360,'ANNA','http://admin2.clikpic.com/susanread/images/20051_thumb.jpg',130, 98,0, 0,'Beautiful hand-made glass beads with brecciate Amethyst and Hematite.  Silver clasp.<br>\r\nLength: 54cm','','','',125.00,'');
photos[18] = new photo(2028444,'133613','','section173106','http://admin2.clikpic.com/susanread/images/20087.jpg',500,375,'STORM','http://admin2.clikpic.com/susanread/images/20087_thumb.jpg',130, 98,0, 0,'Rutillated quartz with faceted crystals and glass lantern beads.<br>\r\nLength: 66cm','','','',65.00,'');
photos[19] = new photo(2448720,'133613','','section173106','http://admin2.clikpic.com/susanread/images/Susan Read Beads 036.jpg',500,375,'LAGUNA','http://admin2.clikpic.com/susanread/images/Susan Read Beads 036_thumb.jpg',130, 98,0, 0,'Sea bamboo with faceted rock crystal.  Silver clasp.  <br>\r\nLength: 42cm','','','',70.00,'');
photos[20] = new photo(2448949,'133613','','section173106','http://admin2.clikpic.com/susanread/images/Susan Read Beads 020.jpg',500,375,'SALOME - Sold','http://admin2.clikpic.com/susanread/images/Susan Read Beads 020_thumb.jpg',130, 98,0, 0,'Black faceted agate with orange gold stone and grey metal crystals.  Silver clasp.  <br>\r\nLength: 90cm','','','',60.00,'');
photos[21] = new photo(2028478,'133606','','gallery','http://admin2.clikpic.com/susanread/images/20113.jpg',500,375,'VERA','http://admin2.clikpic.com/susanread/images/20113_thumb.jpg',130, 98,0, 0,'Black Agate twist beads with Rock crystal.  Silver clasp.<br>\r\nLength: 48cm','','','',60.00,'');
photos[22] = new photo(2028488,'133613','','section173106','http://admin2.clikpic.com/susanread/images/20110.jpg',500,375,'OKSANA','http://admin2.clikpic.com/susanread/images/20110_thumb.jpg',130, 98,0, 0,'Green Czech glass, lantern and fire polished crystals with faceted Swarovski crystal pendant.  Silver clasp.<br>\r\nLength: 44cm','','','',60.00,'');
photos[23] = new photo(2028507,'133613','','section173106','http://admin2.clikpic.com/susanread/images/20101.jpg',500,375,'ELECTRA - Sold','http://admin2.clikpic.com/susanread/images/20101_thumb.jpg',130, 98,0, 0,'Shell pearls and fire polished crystals with beautiful orange-coloured Swarovski crystal pendant finished with a bow.  Silver clasp.<br>\r\nLength: 45cm','','','',125.00,'');
photos[24] = new photo(2047470,'133614','','section173107','http://admin2.clikpic.com/susanread/images/20038.jpg',480,360,'EKATERINA','http://admin2.clikpic.com/susanread/images/20038_thumb.jpg',130, 98,0, 0,'Botswana agate buttons,rainbow crystals with a beautiful slightly twisted Fire Agate pendant.  Silver clasp.<br>\r\nLength: 46cm','','','',60.00,'');
photos[25] = new photo(2028532,'133614','','section173107','http://admin2.clikpic.com/susanread/images/20128.jpg',500,375,'ELENA','http://admin2.clikpic.com/susanread/images/20128_thumb.jpg',130, 98,0, 0,'Vintage blue crystals and clear crystals with pale Amazonite shaped beads and pendant.  Silver clasp.<br>\r\nLength: 44cm','','','',50.00,'');
photos[26] = new photo(2448644,'133614','','section173107','http://admin2.clikpic.com/susanread/images/Susan Read Beads 0042.jpg',500,375,'FLORA - Sold','http://admin2.clikpic.com/susanread/images/Susan Read Beads 0042_thumb.jpg',130, 98,0, 0,'Beautiful hand made glass flower beads with white jade and green crystals.  Sterling silver clasp.  <br>\r\nLength: 46cm','','','',150.00,'');
photos[27] = new photo(2448647,'133614','','section173107','http://admin2.clikpic.com/susanread/images/Susan Read Beads 027.jpg',500,375,'VIOLA - Sold','http://admin2.clikpic.com/susanread/images/Susan Read Beads 027_thumb.jpg',130, 98,0, 0,'Swarovski gold glass pearls and pendant with fire polished crystals.  Gold clasp.  <br>\r\nLength: 43cm','','','',110.00,'');
photos[28] = new photo(2448680,'133614','','section173107','http://admin2.clikpic.com/susanread/images/Susan Read Beads 0071.jpg',500,375,'ANTIGONE','http://admin2.clikpic.com/susanread/images/Susan Read Beads 0071_thumb.jpg',130, 98,0, 0,'Beautiful gold and ivory handmade glass bead with rock crystals and river shell pearls.  Silver clasp.  <br>\r\nLength: 46cm','','','',95.00,'');

/***************************************************************************
* Create the array of Gallery objects                                      *
***************************************************************************/
galleries = new Array();
galleries[0] = new gallery(133613,'2448949,2448720,2028507,2028488,2028444','Autumn','section173106');
galleries[1] = new gallery(133606,'2739631,2739608,2739604,2739598,2739540,2739531,2739492,2047479,2028478','Love Russia','gallery');
galleries[2] = new gallery(133614,'2448680,2448647,2448644,2047470,2028532','Wedding','section173107');


