/***************************************************************************
* 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('3063329');
	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('3063329');
	for (j = 0; j < photos.length; j++) {
		if (photos[j].id == imageID) {
			if ('section233070' != '') {
						if (photos[j].galleries_id != '') {
						document.write('<a href="' + photos[j].section_code + '_' + photos[j].galleries_id + '.html">');
						}
						else {
						document.write('<a href="section233070.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 ('section233070' != '') {
				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 = 'Uber Glam - Simon Phillips 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(3063335,'188354','Ryan I','section233071','http://www1.clikpic.com/stickysi/images/ryan re worked.jpg',459,600,'Ryan I','http://www1.clikpic.com/stickysi/images/ryan re worked_thumb.jpg',130, 170,0, 0,'Sprayed stencil cut<br>\r\n30 x 40 cm','10/11/08','Simon Phillips','London','','');
photos[1] = new photo(3063336,'188354','Ryan goes swimming','section233071','http://www1.clikpic.com/stickysi/images/ryan swim hat 01.jpg',450,600,'Ryan goes swimming','http://www1.clikpic.com/stickysi/images/ryan swim hat 01_thumb.jpg',130, 173,0, 0,'Sprayed stencil cut.<br>\r\n30 x 40 cm','05/10/08','Simon Phillips','London','','');
photos[2] = new photo(3063324,'188353','Jonny Woo remix','section233070','http://www1.clikpic.com/stickysi/images/09.jpg',400,600,'Jonny Woo remix','http://www1.clikpic.com/stickysi/images/09_thumb.jpg',130, 195,0, 0,'Photography.<br>\r\nDigital file.','02/10/08','Simon Phillips','Whitechapel - London','','');
photos[3] = new photo(3063329,'','Self Portrait I','','http://www1.clikpic.com/stickysi/images/20.jpg',600,615,'Self portrait I','http://www1.clikpic.com/stickysi/images/20_thumb.jpg',130, 133,1, 0,'Photography.<br>\r\nDigtal print.','22/09/08','Simon Phillips','Whitechapel - London','','');
photos[4] = new photo(3063325,'188354','Simon & Trevor','section233071','http://www1.clikpic.com/stickysi/images/11.jpg',600,450,'Simon & Trevor','http://www1.clikpic.com/stickysi/images/11_thumb.jpg',130, 98,0, 0,'Painted photograph cast in resin.<br>\r\n90 x 60 cm','05/08/08','Simon Phillips','London','','');
photos[5] = new photo(1502957,'188353','International Woman of Mr E','section233070','http://www1.clikpic.com/stickysi/images/01.jpg',400,600,'International Woman of Mr E','http://www1.clikpic.com/stickysi/images/01_thumb.jpg',130, 195,0, 0,'Photography.<br>\r\nDigital file.','15/06/08','Simon Phillips','Angel - London','','');
photos[6] = new photo(3063338,'188354','Ryan II','section233071','http://www1.clikpic.com/stickysi/images/ryan web.jpg',442,600,'Ryan II','http://www1.clikpic.com/stickysi/images/ryan web_thumb.jpg',130, 176,0, 0,'Painted photograph cast in resin.<br>\r\n60 x 90','06/06/08','Simon Phillips','London','','');
photos[7] = new photo(1502962,'188353','Russella\'s got feathers','section233070','http://www1.clikpic.com/stickysi/images/15.jpg',400,600,'Russella\'s got feathers','http://www1.clikpic.com/stickysi/images/15_thumb.jpg',130, 195,0, 0,'Photography.<br>\r\nDigital file.','14/05/08','','Hackney - London','','');
photos[8] = new photo(3063340,'188354','High Rise','section233071','http://www1.clikpic.com/stickysi/images/shoe ready.jpg',300,225,'High Rise','http://www1.clikpic.com/stickysi/images/shoe ready_thumb.jpg',130, 98,0, 0,'Inked photograph.<br>\r\n90 x 60 cm','11/02/08','Simon Phillips','London','','');
photos[9] = new photo(1502972,'188353','Jonny Woo - Tranny Talent Series','section233070','http://www1.clikpic.com/stickysi/images/chroma 11.jpg',400,600,'Jonny Woo - Tranny Talent Series','http://www1.clikpic.com/stickysi/images/chroma 11_thumb.jpg',130, 195,0, 0,'Photography<br>\r\nInkjet on Aluminium<br>\r\n60 x 90 cm','10/11/07','Simon Phillips','Angel - London','','');
photos[10] = new photo(3064465,'188353','Untitled - Drag Ball 2007','section233070','http://admin.clikpic.com/stickysi/images/ web_1.jpg',400,600,'Untitled - Drag Ball 2007','http://admin.clikpic.com/stickysi/images/ web_1_thumb.jpg',130, 195,0, 0,'Photography.<br>\r\nDigital file.','01/08/07','Simon Phillips','Vauxhall - London','','');
photos[11] = new photo(1502976,'188353','Jodie\'s Harsh','section233070','http://www1.clikpic.com/stickysi/images/jodie harsh.jpg',400,600,'Jodie\'s Harsh','http://www1.clikpic.com/stickysi/images/jodie harsh_thumb.jpg',130, 195,0, 0,'Photography.<br>\r\nDigital image.','07/06/07','','Vauxhall - London','','');
photos[12] = new photo(3063331,'188354','Beauties and Demons I','section233071','http://www1.clikpic.com/stickysi/images/223.jpg',600,471,'Beauties and Demon I','http://www1.clikpic.com/stickysi/images/223_thumb.jpg',130, 102,0, 0,'Painted photograph cast in resin.<br>\r\n120 x 90 cm','02/05/07','Simon Phillips','Prague - London','','');
photos[13] = new photo(3063332,'188354','Beauties and Demons II','section233071','http://www1.clikpic.com/stickysi/images/finished for web site .jpg',407,600,'Beauties and Demons II','http://www1.clikpic.com/stickysi/images/finished for web site _thumb.jpg',130, 192,0, 0,'Painted photograph cast in resin.<br>\r\n60 x 90 cm','02/05/07','Simon Phillips','Prague - London','','');
photos[14] = new photo(1502955,'','','','http://www1.clikpic.com/stickysi/images/001.jpg',400,600,'','http://www1.clikpic.com/stickysi/images/001_thumb.jpg',130, 195,0, 0,'','','','','','');
photos[15] = new photo(1502961,'','','','http://www1.clikpic.com/stickysi/images/05.jpg',400,600,'','http://www1.clikpic.com/stickysi/images/05_thumb.jpg',130, 195,0, 0,'','','','','','');
photos[16] = new photo(1502964,'','','','http://www1.clikpic.com/stickysi/images/57.jpg',400,600,'','http://www1.clikpic.com/stickysi/images/57_thumb.jpg',130, 195,0, 0,'','','','','','');
photos[17] = new photo(1502965,'','','','http://www1.clikpic.com/stickysi/images/andy sizzle blonde cropped.jpg',400,550,'','http://www1.clikpic.com/stickysi/images/andy sizzle blonde cropped_thumb.jpg',130, 179,0, 0,'','','','','','');
photos[18] = new photo(1502969,'','','','http://www1.clikpic.com/stickysi/images/annie lenox trannie.jpg',400,602,'','http://www1.clikpic.com/stickysi/images/annie lenox trannie_thumb.jpg',130, 196,0, 0,'','','','','','');
photos[19] = new photo(1502971,'','','','http://www1.clikpic.com/stickysi/images/booby attitude.jpg',400,600,'','http://www1.clikpic.com/stickysi/images/booby attitude_thumb.jpg',130, 195,0, 0,'','','','','','');
photos[20] = new photo(1502974,'','','','http://www1.clikpic.com/stickysi/images/Copy of taylor close up 01.jpg',400,600,'','http://www1.clikpic.com/stickysi/images/Copy of taylor close up 01_thumb.jpg',130, 195,0, 0,'','','','','','');
photos[21] = new photo(1502979,'','','','http://www1.clikpic.com/stickysi/images/johnny woo final show copy 30x45 cm 300dpi.jpg',400,600,'','http://www1.clikpic.com/stickysi/images/johnny woo final show copy 30x45 cm 300dpi_thumb.jpg',130, 195,0, 0,'','','','','','');
photos[22] = new photo(1502982,'','','','http://www1.clikpic.com/stickysi/images/selfridges show 076.jpg',400,600,'','http://www1.clikpic.com/stickysi/images/selfridges show 076_thumb.jpg',130, 195,0, 0,'','','','','','');
photos[23] = new photo(1502984,'','','','http://www1.clikpic.com/stickysi/images/trannyshack08book copy.jpg',400,600,'','http://www1.clikpic.com/stickysi/images/trannyshack08book copy_thumb.jpg',130, 195,0, 0,'','','','','','');
photos[24] = new photo(1502986,'','','','http://www1.clikpic.com/stickysi/images/trannyshack book copy03.jpg',400,571,'','http://www1.clikpic.com/stickysi/images/trannyshack book copy03_thumb.jpg',130, 186,0, 0,'','','','','','');
photos[25] = new photo(1503032,'','','','http://www1.clikpic.com/stickysi/images/ WEB.jpg',400,600,'','http://www1.clikpic.com/stickysi/images/ WEB_thumb.jpg',130, 195,0, 0,'','','','','','');
photos[26] = new photo(3063328,'','Jonny Legs','','http://www1.clikpic.com/stickysi/images/13.jpg',339,600,'','http://www1.clikpic.com/stickysi/images/13_thumb.jpg',130, 230,0, 0,'','','Simon Phillips','','','');
photos[27] = new photo(1502981,'188353','Butcher wears Louis','section233070','http://www1.clikpic.com/stickysi/images/louie viton shoesre touched finished.jpg',400,600,'Butcher wears Louis','http://www1.clikpic.com/stickysi/images/louie viton shoesre touched finished_thumb.jpg',130, 195,0, 0,'Photography.<br>\r\nInkjet on aluminium.<br>\r\n60 x 90 cm','07/07/06','Simon Phillips','Shoreditch - London','','');
photos[28] = new photo(3064488,'188353','Ryan IV','section233070','http://www1.clikpic.com/stickysi/images/web 03.jpg',400,600,'Ryan IV','http://www1.clikpic.com/stickysi/images/web 03_thumb.jpg',130, 195,0, 0,'Photography<br>\r\nDigital file','19/09/07','Simon Phillips','Hackney - London','','');
photos[29] = new photo(1502959,'','Ryan III','','http://www1.clikpic.com/stickysi/images/03.jpg',400,568,'Ryan III','http://www1.clikpic.com/stickysi/images/03_thumb.jpg',130, 185,0, 0,'Photography.<br>\r\nDigital print.','07/09/07','Simon Phillips','Hackney - London','','');
photos[30] = new photo(1502958,'188353','At home with Russella','section233070','http://www1.clikpic.com/stickysi/images/02.jpg',400,600,'At home with Russella','http://www1.clikpic.com/stickysi/images/02_thumb.jpg',130, 195,0, 0,'Photography<br>\r\nDigital file.','10/03/08','Simon Phillips','Hackney - London','','');

/***************************************************************************
* Create the array of Gallery objects                                      *
***************************************************************************/
galleries = new Array();
galleries[0] = new gallery(188354,'3063340,3063338,3063336,3063335,3063332,3063331,3063325','Paintings & Mix Media','section233071');
galleries[1] = new gallery(188353,'3064488,3064465,3063324,1502981,1502976,1502972,1502962,1502958,1502957','Photography','section233070');

