/***************************************************************************
* 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('3555748,3554412,3554403,3554366,3554362,3554357,3554350,3554344,3554338,3554330,3554328,3554319,3554313,3554305,3554299,3554044,3554041,3554039,3554038,3554035,3554033,3551337,3551332,3551328,3551317,3551310,3551305,3551299,3551296,3551290,3551285,3551279,3551258');
	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('3555748,3554412,3554403,3554366,3554362,3554357,3554350,3554344,3554338,3554330,3554328,3554319,3554313,3554305,3554299,3554044,3554041,3554039,3554038,3554035,3554033,3551337,3551332,3551328,3551317,3551310,3551305,3551299,3551296,3551290,3551285,3551279,3551258');
	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 = 'Christieart: ' + 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(3555748,'','','','http://admin.clikpic.com/MaryChristie/images/Mugshot_eyes_open.jpg',500,667,'Mary Christie','http://admin.clikpic.com/MaryChristie/images/Mugshot_eyes_open_thumb.jpg',130, 173,0, 0,'','','','','','');
photos[1] = new photo(3551328,'216932','','gallery','http://admin.clikpic.com/MaryChristie/images/Dobbin.jpg',500,375,'Dobbin','http://admin.clikpic.com/MaryChristie/images/Dobbin_thumb.jpg',130, 98,0, 0,'Pastel on Ingres paper<br>\r\n<br>\r\n61cm x 51cm<br>\r\n<br>\r\n£35','','','','','');
photos[2] = new photo(3554038,'217410','','gallery','http://admin.clikpic.com/MaryChristie/images/Life_Class_2.jpg',500,375,'Life Class','http://admin.clikpic.com/MaryChristie/images/Life_Class_2_thumb.jpg',130, 98,0, 0,'Acrylic on deep-edge canvas<br>\r\n<br>\r\nBrings a smile to both young and old, especially the socks! Won SAA figure category prize.<br>\r\n<br>\r\n100cm x 80cm<br>\r\n<br>\r\n£895','','','','','');
photos[3] = new photo(3554044,'217410','','gallery','http://admin.clikpic.com/MaryChristie/images/Mother__Child_last.jpg',500,667,'Mother & Child','http://admin.clikpic.com/MaryChristie/images/Mother__Child_last_thumb.jpg',130, 173,0, 0,'Oil on canvas board<br>\r\n<br>\r\nSOLD','','','','','');
photos[4] = new photo(3554313,'217410','','gallery','http://admin.clikpic.com/MaryChristie/images/The_Orphan.jpg',500,667,'The orphan','http://admin.clikpic.com/MaryChristie/images/The_Orphan_thumb.jpg',130, 173,0, 0,'Acrylic on canvas<br>\r\n<br>\r\n41cm x 51cm<br>\r\n<br>\r\n£195','','','','','');
photos[5] = new photo(3554319,'217410','','gallery','http://admin.clikpic.com/MaryChristie/images/Turquoise_nude_.jpg',500,404,'Turquoise nude','http://admin.clikpic.com/MaryChristie/images/Turquoise_nude__thumb.jpg',130, 105,0, 0,'Oil on canvas<br>\r\n<br>\r\n61cm x 76cm<br>\r\n<br>\r\n£195','','','','','');
photos[6] = new photo(3551258,'217410','','gallery','http://admin.clikpic.com/MaryChristie/images/Ballerinas.jpg',500,508,'Ballerinas','http://admin.clikpic.com/MaryChristie/images/Ballerinas_thumb.jpg',130, 132,0, 0,'Acrylic on canvas<br>\r\n<br>\r\nSOLD','','','','','');
photos[7] = new photo(3551285,'217411','','gallery','http://admin.clikpic.com/MaryChristie/images/Arctic_mural.jpg',500,375,'Arctic mural','http://admin.clikpic.com/MaryChristie/images/Arctic_mural_thumb.jpg',130, 98,0, 0,'Mural in acrylics painted on grandson\'s bedroom wall.<br>\r\n<br>\r\nCommissions welcomed.','','','','','');
photos[8] = new photo(3551290,'217411','','gallery','http://admin.clikpic.com/MaryChristie/images/Bluebell_wood_1.jpg',500,667,'Bluebell wood','http://admin.clikpic.com/MaryChristie/images/Bluebell_wood_1_thumb.jpg',130, 173,0, 0,'Acrylic on canvas, inspired by bluebells in Sherdley Park, St Helens.<br>\r\n<br>\r\n31cm x 41cm<br>\r\n<br>\r\n£55','','','','','');
photos[9] = new photo(3551296,'217411','','gallery','http://admin.clikpic.com/MaryChristie/images/Bluebell_wood_2.jpg',500,667,'Bluebell wood 2','http://admin.clikpic.com/MaryChristie/images/Bluebell_wood_2_thumb.jpg',130, 173,0, 0,'Acrylic on canvas, inspired by bluebells in Sherdley Park, St Helens<br>\r\n<br>\r\n31cm 41cm<br>\r\n<br>\r\n£55','','','','','');
photos[10] = new photo(3551299,'217411','','gallery','http://admin.clikpic.com/MaryChristie/images/Bluebells__Sherdley.JPG',500,415,'Bluebells, Sherdley Park','http://admin.clikpic.com/MaryChristie/images/Bluebells__Sherdley_thumb.JPG',130, 108,0, 0,'Acrylic on deep-edge canvas. One of a series of bluebell studies.<br>\r\n<br>\r\n77cm x 77cm<br>\r\n<br>\r\n£295','','','','','');
photos[11] = new photo(3551317,'217411','','gallery','http://admin.clikpic.com/MaryChristie/images/Dawn__Formby_Beach.jpg',500,667,'Dawn, Formby Beach','http://admin.clikpic.com/MaryChristie/images/Dawn__Formby_Beach_thumb.jpg',130, 173,0, 0,'Acrylic on canvas, inspired by walks on Formby beach, Merseyside.<br>\r\n<br>\r\n31cm x 41cm<br>\r\n<br>\r\n£55','','','','','');
photos[12] = new photo(3554039,'217411','','gallery','http://admin.clikpic.com/MaryChristie/images/Mansion_House.jpg',500,375,'Mansion House','http://admin.clikpic.com/MaryChristie/images/Mansion_House_thumb.jpg',130, 98,0, 0,'Oil on canvas<br>\r\n<br>\r\nSOLD','','','','','');
photos[13] = new photo(3554041,'217411','','gallery','http://admin.clikpic.com/MaryChristie/images/Monets_garden.jpg',500,375,'Monet\'s Garden','http://admin.clikpic.com/MaryChristie/images/Monets_garden_thumb.jpg',130, 98,0, 0,'Oil on canvas, inspired by Monet\'s paintings and a visit to his garden in Giverny, France.<br>\r\n<br>\r\n61cm x 51cm<br>\r\n<br>\r\n£149','','','','','');
photos[14] = new photo(3554357,'217411','','gallery','http://admin.clikpic.com/MaryChristie/images/Cerulean_Sea.jpg',300,355,'Cerulean Sea','http://admin.clikpic.com/MaryChristie/images/Cerulean_Sea_thumb.jpg',130, 154,0, 0,'Acrylic on canvas with textured finish. Painted for my daughter.<br>\r\n<br>\r\n<br>\r\n80cm x 100cm<br>\r\n<br>\r\nSOLD','','','','','');
photos[15] = new photo(3551279,'217413','','gallery','http://admin.clikpic.com/MaryChristie/images/Abstract_nude1.jpg',256,500,'Abstract nude','http://admin.clikpic.com/MaryChristie/images/Abstract_nude1_thumb.jpg',130, 254,0, 0,'Acrylic on canvas<br>\r\n<br>\r\n51cm x 77cm<br>\r\n<br>\r\n£195','','','','','');
photos[16] = new photo(3551305,'217413','','gallery','http://admin.clikpic.com/MaryChristie/images/Orange_nude_small_1.JPG',500,735,'Orange nude 2','http://admin.clikpic.com/MaryChristie/images/Orange_nude_small_1_thumb.JPG',130, 191,0, 0,'Acylic on canvas<br>\r\n<br>\r\n24cm x 30cm<br>\r\n<br>\r\n£50','','','','','');
photos[17] = new photo(3551332,'217413','','gallery','http://admin.clikpic.com/MaryChristie/images/Dormant.jpg',500,375,'Dormant','http://admin.clikpic.com/MaryChristie/images/Dormant_thumb.jpg',130, 98,0, 0,'Oil on canvas<br>\r\n<br>\r\n61cm x 76cm<br>\r\n<br>\r\nSOLD','','','','','');
photos[18] = new photo(3551337,'217413','','gallery','http://admin.clikpic.com/MaryChristie/images/Dreamer.jpg',500,667,'Dreamer','http://admin.clikpic.com/MaryChristie/images/Dreamer_thumb.jpg',130, 173,0, 0,'Acylic on grey linen canvas<br>\r\n<br>\r\n50cm x 50cm<br>\r\n<br>\r\nSOLD','','','','','');
photos[19] = new photo(3554299,'217413','','gallery','http://admin.clikpic.com/MaryChristie/images/Orange_nude_large.jpg',499,500,'Orange nude 3','http://admin.clikpic.com/MaryChristie/images/Orange_nude_large_thumb.jpg',130, 130,0, 0,'Acrylic on canvas<br>\r\n<br>\r\n77cm x 77cm<br>\r\n<br>\r\nSOLD','','','','','');
photos[20] = new photo(3554305,'217413','','gallery','http://admin.clikpic.com/MaryChristie/images/Reclining_Nude_3.JPG',500,202,'Reclining nude','http://admin.clikpic.com/MaryChristie/images/Reclining_Nude_3_thumb.JPG',130, 53,0, 0,'Acrylic on canvas<br>\r\n<br>\r\n46cm x 16cm<br>\r\n<br>\r\n£95','','','','','');
photos[21] = new photo(3554328,'217413','','gallery','http://admin.clikpic.com/MaryChristie/images/3_Graces_again.jpg',500,375,'Three Graces','http://admin.clikpic.com/MaryChristie/images/3_Graces_again_thumb.jpg',130, 98,0, 0,'Series of three nude acrylic paintings on canvas<br>\r\n<br>\r\nSOLD','','','','','');
photos[22] = new photo(3554330,'217413','','gallery','http://admin.clikpic.com/MaryChristie/images/Three_Graces_i_small.jpg',366,500,'Three Graces 1','http://admin.clikpic.com/MaryChristie/images/Three_Graces_i_small_thumb.jpg',130, 178,0, 0,'First in this series of nudes - Acrylic on canvas<br>\r\n<br>\r\nSOLD','','','','','');
photos[23] = new photo(3554338,'217413','','gallery','http://admin.clikpic.com/MaryChristie/images/Three_graces_4.jpg',500,667,'Three Graces 4','http://admin.clikpic.com/MaryChristie/images/Three_graces_4_thumb.jpg',130, 173,0, 0,'4th in this series, acrylic on canvas<br>\r\n<br>\r\nSOLD','','','','','');
photos[24] = new photo(3554344,'217413','','gallery','http://admin.clikpic.com/MaryChristie/images/Three_graces_5.jpg',500,667,'Three Graces 5','http://admin.clikpic.com/MaryChristie/images/Three_graces_5_thumb.jpg',130, 173,0, 0,'5th in this series of nudes - Acrylic on canvas<br>\r\n<br>\r\nSOLD','','','','','');
photos[25] = new photo(3554350,'217413','','gallery','http://admin.clikpic.com/MaryChristie/images/Three_graces_6.jpg',500,667,'Three Graces 6','http://admin.clikpic.com/MaryChristie/images/Three_graces_6_thumb.jpg',130, 173,0, 0,'Last in this series of nudes - Acrylic on canvas<br>\r\n<br>\r\nSOLD','','','','','');
photos[26] = new photo(3554362,'217413','','gallery','http://admin.clikpic.com/MaryChristie/images/Yellow_nude_small.jpg',380,500,'Yellow nude','http://admin.clikpic.com/MaryChristie/images/Yellow_nude_small_thumb.jpg',130, 171,0, 0,'Oil on canvas<br>\r\n<br>\r\nSOLD','','','','','');
photos[27] = new photo(3551310,'217414','','gallery','http://admin.clikpic.com/MaryChristie/images/Daniel__Amanda.jpg',500,375,'Daniel & Amanda','http://admin.clikpic.com/MaryChristie/images/Daniel__Amanda_thumb.jpg',130, 98,0, 0,'','','','','','');
photos[28] = new photo(3554033,'217414','','gallery','http://admin.clikpic.com/MaryChristie/images/Joss.JPG',500,503,'Joss','http://admin.clikpic.com/MaryChristie/images/Joss_thumb.JPG',130, 131,0, 0,'Portrait of singer Joss Stone<br>\r\n<br>\r\n77cm x 77cm<br>\r\n<br>\r\n£395','','','','','');
photos[29] = new photo(3554035,'217414','','gallery','http://admin.clikpic.com/MaryChristie/images/Katie.JPG',500,487,'Katie','http://admin.clikpic.com/MaryChristie/images/Katie_thumb.JPG',130, 127,0, 0,'Portrait of singer Katie Melua<br>\r\n<br>\r\n77cm x 77cm<br>\r\n<br>\r\n£395','','','','','');
photos[30] = new photo(3554403,'217414','','gallery','http://admin.clikpic.com/MaryChristie/images/Michael_001.jpg',500,667,'Michael','http://admin.clikpic.com/MaryChristie/images/Michael_001_thumb.jpg',130, 173,0, 0,'Commissioned portrait of friend\'s husband. Acrylic on canvas.<br>\r\n<br>\r\n51cm x 41cm<br>\r\n<br>\r\nSOLD','','','','','');
photos[31] = new photo(3554412,'217414','','gallery','http://admin.clikpic.com/MaryChristie/images/Michael_005.jpg',500,667,'Michael 2','http://admin.clikpic.com/MaryChristie/images/Michael_005_thumb.jpg',130, 173,0, 0,'Second portrait of friend\'s husband, painted as a gift. Acrylic on canvas.<br>\r\n<br>\r\nGIFT','','','','','');
photos[32] = new photo(3554366,'217415','','gallery','http://admin.clikpic.com/MaryChristie/images/Plumptious_Fruits.jpg',380,282,'Plumptious Fruits','http://admin.clikpic.com/MaryChristie/images/Plumptious_Fruits_thumb.jpg',130, 96,0, 0,'Pastel on red Ingres paper with royal blue mount in red wooden frame and glare-proof glass. <br>\r\n<br>\r\n56cm x 44cm<br>\r\n<br>\r\n£95','','','','','');

/***************************************************************************
* Create the array of Gallery objects                                      *
***************************************************************************/
galleries = new Array();
galleries[0] = new gallery(216931,'','Abstracts','gallery');
galleries[1] = new gallery(216932,'3551328','Drawings','gallery');
galleries[2] = new gallery(217410,'3554319,3554313,3554044,3554038,3551258','Figures','gallery');
galleries[3] = new gallery(217411,'3554357,3554041,3554039,3551317,3551299,3551296,3551290,3551285','Landscapes','gallery');
galleries[4] = new gallery(217413,'3554362,3554350,3554344,3554338,3554330,3554328,3554305,3554299,3551337,3551332','Nudes','gallery');
galleries[5] = new gallery(217414,'3554412,3554403,3554035,3554033,3551310','Portraits','gallery');
galleries[6] = new gallery(217415,'3554366','Still Life','gallery');

