/***************************************************************************
* 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('3106704,3106701,3106699,3106697,3054096,3054094');
	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('3106704,3106701,3106699,3106697,3054096,3054094');
	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) || (1))) {
		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 = 'SOHO SCENE: ' + 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(3054094,'187883','Giclee Print   30 x 38 cm   Ed.125 signed','gallery','http://www2.clikpic.com/COLONYROOM/images/thecolonyroomclub.jpg',382,301,'THE COLONY ROOM CLUB','http://www2.clikpic.com/COLONYROOM/images/thecolonyroomclub_thumb.jpg',130, 102,1, 0,'At three o’clock in the afternoon Michael Wojas looks out into Dean Street, Soho. The empty stools are waiting for the painters, writers, and drinkers, such as in the past, Bacon, Farson, and Dylan Thomas,  who sat at the bar in the smoke filled room surrounded by paintings.<br>\r\nThe colony Club was set up by Muriel Belcher in 1948, and is faced with closure in 2008.','','','',240.00,'Ref 094  price is inclusive of Shipping within UK ');
photos[1] = new photo(3054096,'187883','Giclee Print   30 x 38 cm   Ed.125 signed','gallery','http://www2.clikpic.com/COLONYROOM/images/thebaratthecolonyroomclu.jpg',382,289,'THE COLONY ROOM BAR','http://www2.clikpic.com/COLONYROOM/images/thebaratthecolonyroomclu_thumb.jpg',130, 98,1, 0,'When at the bar of the club, the view is the ever changing array of the postcards, notes and letters above the artistic till. The bottles and mirrored back throws into relief the glittering gaiety or quiet reflection of all who have found solace in this tiny atmospheric room in Soho.','','','',240.00,'Ref 096  Price is inclusive of Shipping within UK ');
photos[2] = new photo(3106697,'187883','Giclee Print   30 x 38 cm   Ed.125 signed','gallery','http://www2.clikpic.com/COLONYROOM/images/Proof-black--A-Quarter-to.jpg',400,316,'THE FRENCH HOUSE','http://www2.clikpic.com/COLONYROOM/images/Proof-black--A-Quarter-to_thumb.jpg',130, 103,1, 0,'General De Gaulle wrote upstairs in the York Minster, so it was always called the French. Now renamed, it is the most loved bastion and spiritual home of Soho life, for hundreds of men and women who visit from far away: but have never really left, to remember old faces of their youth, the freedom of expression, the chat, and the acceptance of art. Dan Farson here talks to a young man before lunch, and looks forward to a long Soho day and a long Soho night.','','','',240.00,'Ref 697 Limited edition of 125, signed giclee print');
photos[3] = new photo(3106699,'187883','Giclee Print   25 x 23 cm   Ed.125 signed','gallery','http://www2.clikpic.com/COLONYROOM/images/Annabelle.jpg',300,326,'ANNABELLE IN THE FRENCH HOUSE','http://www2.clikpic.com/COLONYROOM/images/Annabelle_thumb.jpg',130, 141,1, 0,'Created in homage to the painter Edouard Manet, to recreate his painting \'A Bar at the Folies-Bergere\'. Annabelle has a modern air of confidence as she serves wine at the bar of the FrenchHouse, Soho. In his 1882 painting, Manet changes the viewpoint of the background, in reaction to the discovery of photography. The artist in 1997 uses different photographs to show that photography need not be a mirror, but can be manipulated, to express the attractive air of the FrenchHouse as a small bar in Paris.','','','',160.00,'Ref 699 Price is inclusive of Shipping within UK ');
photos[4] = new photo(3106701,'187883','Giclee Print   17 x 18 cm   Ed.125 signed','gallery','http://www2.clikpic.com/COLONYROOM/images/DanielFars.jpg',300,283,'DAN FARSON IN DEAN STREET','http://www2.clikpic.com/COLONYROOM/images/DanielFars_thumb.jpg',130, 123,1, 0,'Dan Farson outside the FrenchHouse in Dean Street, fresh up from North Devon, where he writes of Francis Bacon.<br>\r\nOn one of his ledgendary drinking bouts in Soho, he is ready for his \'Glittering Gutter\'. Also a fine photographer, his black and white portraits of Soho artists and poets are in the nearby National Portrait Gallery.','','','',140.00,'Ref 701  Price is inclusive of Shipping within UK ');
photos[5] = new photo(3106704,'187883','Giclee Print   30 x 36.5 cm   Ed.125 signed','gallery','http://www2.clikpic.com/COLONYROOM/images/VALERIE.jpg',400,330,'PATISSERIE VALERIE','http://www2.clikpic.com/COLONYROOM/images/VALERIE_thumb.jpg',130, 107,1, 0,'A place of French fantasy, of dark coffee highs, of the glamorous artworks in sugar and cream- Charlotte gateau, strawberry Mille Feuille, pear and caramel mousse. A famous place for secret rendezvous for the gentle denizens of Soho.<br>\r\nThe artist here illustrates the street life of 1992, the office worker, the shopper, the homeless, setting up a tight human narrative within the famous shop front at 44 Old Compton Street.','','','',240.00,'Ref 704 Price is inclusive of Shipping within UK ');
photos[6] = new photo(3629565,'187883','Giclee Print   40 x 28 cm   Ed.125 signed','gallery','http://www2.clikpic.com/COLONYROOM/images/shopwindowtwo.jpg',400,277,'SHOP WINDOW, SOHO','http://www2.clikpic.com/COLONYROOM/images/shopwindowtwo_thumb.jpg',130, 90,0, 0,'It is Easter, and memories of the Bunny Club are sighted in the Shop Windows of Soho.','','','',240.00,'Ref 565 Price is inclusive of Shipping within UK ');
photos[7] = new photo(3629596,'187883','Giclee Print   30 x 26 cm   Ed.125 signed','gallery','http://www2.clikpic.com/COLONYROOM/images/green-street.jpg',400,346,'GREEN\'S COURT, SOHO','http://www2.clikpic.com/COLONYROOM/images/green-street_thumb.jpg',130, 112,0, 0,'In the once seedy back Streets and courts of Soho, some might have nostalgia for a hidden way of life.','','','',240.00,'Ref 596 Price is inclusive of Shipping within UK ');
photos[8] = new photo(3629683,'187883','Giclee Print   40 x 31 cm   Ed.125 signed','gallery','http://www2.clikpic.com/COLONYROOM/images/SALMON.jpg',400,312,'SOHO SHOP FRONT','http://www2.clikpic.com/COLONYROOM/images/SALMON_thumb.jpg',130, 101,0, 0,'Model girls immobilized striding in a window as the traffic moves slowly up Wardour Street.','','','',240.00,'REF 683 Price is inclusive of Shipping within UK ');
photos[9] = new photo(3629567,'187883','Giclee Print   25 x 23 cm   Ed.125 signed','gallery','http://www2.clikpic.com/COLONYROOM/images/Berwick.jpg',400,375,'BERWICK STREET MARKET, SOHO','http://www2.clikpic.com/COLONYROOM/images/Berwick_thumb.jpg',130, 122,0, 0,'Established in the 1700\'s, the market is a sinew of fruit and vegetables, clothes, sex shops, music shops and shouts running through the heart of Soho.','','','',160.00,'Ref 567 Price is inclusive of Shipping within UK ');

/***************************************************************************
* Create the array of Gallery objects                                      *
***************************************************************************/
galleries = new Array();
galleries[0] = new gallery(187883,'3629683,3629596,3629567,3629565,3106704,3106701,3106699,3106697,3054096,3054094','Limited edition of  125, signed giclee prints ','gallery');

