/***************************************************************************
* 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('2717146,2300901,2300899,2300896,2297032,2297021,2296726,1834026');
	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('2717146,2300901,2300899,2300896,2297032,2297021,2296726,1834026');
	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 = 'Zoi Interiors -  Design by Tracy Smyth: ' + 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(2717134,'171308','','gallery','http://www1.clikpic.com/tracysmyth/images/1.JPG',500,375,'Guest Bedroom - Victorian House, Albourne - view 1','http://www1.clikpic.com/tracysmyth/images/1_thumb.JPG',130, 98,0, 0,'This room was completely refurbished, with all skirting and picture rails being replaced, and most walls replastered following water damage.  The reclaimed Victorian fire surround was installed in the chimney wall for decorative purposes only, bringing in another black item to the room. The only items to be retained by the customer were the antique bed and black cat wall canvas.  This inspired the use of pure white on all walls and woodwork, so allowing for dramatic colour to be introduced by way of the curtaining.  Designers Guild fabric was used for the window treatment.','','','','','');
photos[1] = new photo(2717138,'171308','','gallery','http://www1.clikpic.com/tracysmyth/images/2.JPG',500,375,'Guest Bedroom - Victorian House, Albourne - View 2','http://www1.clikpic.com/tracysmyth/images/2_thumb.JPG',130, 98,0, 0,'A large bolster cushion was made to bring the vibrant colours from the curtains into the opposite side of the room.   The client wants to accessorize the room with turquoise items so the turquoise band of colour from the fabric was used at either end of the cushion.  The end sections were gathered to the middle and finished off by the addition of a large black tassle.<br>\r\nAn exisiting ottomen was reupholstered in black suede and lined in turquoise silk.<br>\r\nDesigners Guild wallpaper was used on a feature wall.','','','','','');
photos[2] = new photo(2717141,'171308','','gallery','http://www1.clikpic.com/tracysmyth/images/3.JPG',500,375,'Master Bedroom - View 1','http://www1.clikpic.com/tracysmyth/images/3_thumb.JPG',130, 98,0, 0,'The existing wardrobes originally had steel, industrial handles, so by replacing these with crystal cut glass knobs, the overall look was softened and became more in keeping with the age of the property.  The chimney breast was open and draughty, so this was blocked and then filled with cut logs to create an interesting focal point.  As the opening was off set, the picture was hung above the opening and the vase of twigs was added to balnce the look of the wall.','','','','','');
photos[3] = new photo(2717143,'171308','','gallery','http://www1.clikpic.com/tracysmyth/images/4.JPG',500,375,'Master Bedroom - View 2','http://www1.clikpic.com/tracysmyth/images/4_thumb.JPG',130, 98,0, 0,'A darker shade of cream paint was used on the woodwork rather than white to warm up an otherwise cold room.  The existing headboard was recovered in a heavily textured cream fabric to tie in with the neutral, but tactile scheme.','','','','','');
photos[4] = new photo(2717146,'171308','','gallery','http://www1.clikpic.com/tracysmyth/images/5.JPG',500,375,'Master Bedroom - View 3','http://www1.clikpic.com/tracysmyth/images/5_thumb.JPG',130, 98,1, 0,'The colours for this scheme were taken from the wall print from Vietnam. A neutral theme was required but a splash of red and gold adds some depth to the scheme.  Swan neck adjustable wall lights were installed either side of the bed as the client had seen them in a hotel.','','','','','');
photos[5] = new photo(2300894,'110262','','gallery','http://www1.clikpic.com/tracysmyth/images/kitchen1.jpg',500,375,'Kitchen - View 1','http://www1.clikpic.com/tracysmyth/images/kitchen1_thumb.jpg',130, 98,0, 0,'Prep area showing maple units with a black granite worktop. Black wall tiling has a stainless steel tile trim running through it.','','','','','');
photos[6] = new photo(2300896,'110262','','gallery','http://www1.clikpic.com/tracysmyth/images/kitchen2.jpg',500,375,'Kitchen - view 2','http://www1.clikpic.com/tracysmyth/images/kitchen2_thumb.jpg',130, 98,1, 0,'A plain kitchen wall has been made into a feature with a radiator cabinet used to centralise an off-set radiator. Grouping pictures together also adds interest.','','','','','');
photos[7] = new photo(2300897,'110262','','gallery','http://www1.clikpic.com/tracysmyth/images/kitchen3.jpg',500,375,'Kitchen - view 3','http://www1.clikpic.com/tracysmyth/images/kitchen3_thumb.jpg',130, 98,0, 0,'Kitchen utility area.','','','','','');
photos[8] = new photo(2300899,'110264','','gallery','http://www1.clikpic.com/tracysmyth/images/living1.jpg',500,375,'Seating area','http://www1.clikpic.com/tracysmyth/images/living1_thumb.jpg',130, 98,1, 0,'Interest is added to a sofa by using cushions in assorted textures and designs, but keeping to the same colour palette.','','','','','');
photos[9] = new photo(2300901,'110264','','gallery','http://www1.clikpic.com/tracysmyth/images/living2.jpg',500,375,'Seating area','http://www1.clikpic.com/tracysmyth/images/living2_thumb.jpg',130, 98,1, 0,'A feature wallpaper influences the overall colour scheme for the room.  Cut logs in a fire surround give the effect of a real fireplace.','','','','','');
photos[10] = new photo(1834025,'110339','','gallery','http://www1.clikpic.com/tracysmyth/images/conservatory.jpg',500,375,'Conservatory','http://www1.clikpic.com/tracysmyth/images/conservatory_thumb.jpg',130, 98,0, 1,'Brief: Design a minimalistic scheme for a conservatory to complement adjoining dining area','','','','','');
photos[11] = new photo(1834027,'110340','','gallery','http://www1.clikpic.com/tracysmyth/images/dining-room.jpg',500,375,'Dining Area','http://www1.clikpic.com/tracysmyth/images/dining-room_thumb.jpg',130, 98,0, 1,'Brief: Design a minimalistic dining area for up to 8 people. Design must continue into adjoining lounge area and conservatory.','','','','','');
photos[12] = new photo(1834026,'110340','','gallery','http://www1.clikpic.com/tracysmyth/images/dining-2.jpg',500,375,'Dining Area','http://www1.clikpic.com/tracysmyth/images/dining-2_thumb.jpg',130, 98,1, 1,'Feature wall in dining area with bespoke canvas art to complement overall scheme.','','','','','');
photos[13] = new photo(2297015,'110341','','gallery','http://www1.clikpic.com/tracysmyth/images/georgias.jpg',500,472,'Girl\'s bedroom','http://www1.clikpic.com/tracysmyth/images/georgias_thumb.jpg',130, 123,0, 0,'By adding wall stickers, a plain wall can be made more interesting and individual.','','','','','');
photos[14] = new photo(2297021,'110341','','gallery','http://www1.clikpic.com/tracysmyth/images/jakes room.jpg',500,375,'Boy\'s bedroom - feature wall','http://www1.clikpic.com/tracysmyth/images/jakes room_thumb.jpg',130, 98,1, 0,'A wall of slate (wallpaper!!) gives this room a quirky edge.  By using a splash of red in the accessories and the bespoke canvas art, colour is injected into an otherwise muted colour scheme.','','','','','');
photos[15] = new photo(2297091,'110341','','gallery','http://www1.clikpic.com/tracysmyth/images/jakes room 3.jpg',500,375,'Boys Bedroom - Feature clock','http://www1.clikpic.com/tracysmyth/images/jakes room 3_thumb.jpg',130, 98,0, 0,'An awkward space has been utilised to provide an eye catching feature.','','','','','');
photos[16] = new photo(2296726,'110263','','gallery','http://www1.clikpic.com/tracysmyth/images/bathroom1.jpg',500,689,'Family bathroom','http://www1.clikpic.com/tracysmyth/images/bathroom1_thumb.jpg',130, 179,1, 1,'A hollywood style vanity mirror was the inspiration for a \'girlie\' bathroom.  The client wanted a bright, vibrant scheme but with lots of light reflective surfaces.  The finished room looks sleek and clean.','','','','','');
photos[17] = new photo(2297032,'110263','','gallery','http://www1.clikpic.com/tracysmyth/images/toilet.jpg',500,667,'Downstairs cloakroom','http://www1.clikpic.com/tracysmyth/images/toilet_thumb.jpg',130, 173,1, 0,'As this room is the smallest in the house, the client wished to make a statement with the design, whilst incorporating existing framed pictures of zebras.','','','','','');
photos[18] = new photo(2296729,'110338','','gallery','http://www1.clikpic.com/tracysmyth/images/canas2.jpg',500,375,'The Cat House, Henfield © Tracy Smyth 2008','http://www1.clikpic.com/tracysmyth/images/canas2_thumb.jpg',130, 98,0, 0,'Gouache on canvas (10\" x 12\") Worked from photographs.','','','','','');
photos[19] = new photo(2297014,'110338','','gallery','http://www1.clikpic.com/tracysmyth/images/canvas1.jpg',500,382,'St Peter\'s Church, Henfield © Tracy Smyth 2008','http://www1.clikpic.com/tracysmyth/images/canvas1_thumb.jpg',130, 99,0, 0,'Gouache on canvas (8\" x 8\"). Worked from photographs.','','','','','');
photos[20] = new photo(1834031,'110338','','gallery','http://www1.clikpic.com/tracysmyth/images/tulips.jpg',500,375,'Red Tulips <br>\r\n           <br>\r\n© Tracy Smyth 2008','http://www1.clikpic.com/tracysmyth/images/tulips_thumb.jpg',130, 98,0, 1,'Original commissioned art work in gouache medium. Triptych is made up of 3 individual canvas each 12\" x 24\".','','','','','');
photos[21] = new photo(1834029,'110338','','gallery','http://www1.clikpic.com/tracysmyth/images/rose.jpg',500,375,'Abstract Rose <br>\r\n<br>\r\n© Tracy Smyth 2007','http://www1.clikpic.com/tracysmyth/images/rose_thumb.jpg',130, 98,0, 0,'Original commissioned art work designed to complement customer\'s existing decor.  Gouache medium with silver highlight. Canvas size 24\" x 24\".','','','','','');
photos[22] = new photo(1834032,'110338','','gallery','http://www1.clikpic.com/tracysmyth/images/VW.jpg',500,375,'Vee Dub <br>\r\n<br>\r\n© Tracy Smyth 2008','http://www1.clikpic.com/tracysmyth/images/VW_thumb.jpg',130, 98,0, 1,'Collage using gouache/leather/felt/wire.  Canvas size 8\" x 8\".','','','','','');
photos[23] = new photo(1834022,'110338','','gallery','http://www1.clikpic.com/tracysmyth/images/balamory.jpg',500,375,'Tobermory Harbour © Tracy Smyth 2007','http://www1.clikpic.com/tracysmyth/images/balamory_thumb.jpg',130, 98,0, 0,'Original commissioned art work in gouache medium.  Worked from photographs.  Canvas size 30\" x 20\".','','','','','');
photos[24] = new photo(1834028,'110338','','gallery','http://www1.clikpic.com/tracysmyth/images/house-view.jpg',500,375,'Scottish View © Tracy Smyth 2007','http://www1.clikpic.com/tracysmyth/images/house-view_thumb.jpg',130, 98,0, 0,'Original commissioned art work in gouache medium. Worked from photographs.  Canvas size 36\" x 12\".','','','','','');
photos[25] = new photo(1834030,'110338','','gallery','http://www1.clikpic.com/tracysmyth/images/skye.jpg',500,375,'Scottish Scenes<br>\r\n© Tracy Smyth 2007','http://www1.clikpic.com/tracysmyth/images/skye_thumb.jpg',130, 98,0, 0,'Various Scottish scenes depicted in gouache medium with collage details in stones and heather.  Each canvas 8\" x 8\".','','','','','');
photos[26] = new photo(2717148,'110338','','gallery','http://www1.clikpic.com/tracysmyth/images/6.jpg',500,375,'LEAVES ON THE WATER','http://www1.clikpic.com/tracysmyth/images/6_thumb.jpg',130, 98,0, 0,'A triptych canvas with collage and gouache medium','','','','','');
photos[27] = new photo(2297023,'110345','','gallery','http://www1.clikpic.com/tracysmyth/images/mood1.jpg',500,358,'Bedroom scheme - option 1','http://www1.clikpic.com/tracysmyth/images/mood1_thumb.jpg',130, 93,0, 0,'','','','','','');
photos[28] = new photo(2297024,'110345','','gallery','http://www1.clikpic.com/tracysmyth/images/mood2.jpg',500,369,'Bedroom scheme - option 2','http://www1.clikpic.com/tracysmyth/images/mood2_thumb.jpg',130, 96,0, 0,'','','','','','');
photos[29] = new photo(2297030,'110345','','gallery','http://www1.clikpic.com/tracysmyth/images/mood3.jpg',500,374,'Bedroom scheme - option 3','http://www1.clikpic.com/tracysmyth/images/mood3_thumb.jpg',130, 97,0, 0,'','','','','','');

/***************************************************************************
* Create the array of Gallery objects                                      *
***************************************************************************/
galleries = new Array();
galleries[0] = new gallery(171308,'2717146,2717143,2717141,2717138,2717134','Bedroom','gallery');
galleries[1] = new gallery(110262,'2300897,2300896,2300894','Kitchen','gallery');
galleries[2] = new gallery(110264,'2300901,2300899','Living Room','gallery');
galleries[3] = new gallery(110339,'1834025','Conservatory','gallery');
galleries[4] = new gallery(110340,'1834027,1834026','Dining Room','gallery');
galleries[5] = new gallery(110341,'2297091,2297021,2297015','Children\'s Room','gallery');
galleries[6] = new gallery(110263,'2296726','Bathroom','gallery');
galleries[7] = new gallery(110338,'1834032,1834031','Canvas Art','gallery');
galleries[8] = new gallery(110345,'2297030,2297024,2297023','Sample Boards','gallery');

