/***************************************************************************
* 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('254703');
	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('254703');
	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)) {
		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 + '" border="0">';
						field.value = photos[nextImg].id;
			document.getElementById('imageTitle').innerHTML = 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(249758,'22649','','gallery','http://www1.clikpic.com/meddler/images/belly.jpg',600,450,'Belly','http://www1.clikpic.com/meddler/images/belly_thumb.jpg',130, 98,0, 0,'','','','','','');
photos[1] = new photo(249760,'22649','','gallery','http://www1.clikpic.com/meddler/images/bubbleface.jpg',600,450,'Bubble Face','http://www1.clikpic.com/meddler/images/bubbleface_thumb.jpg',130, 98,0, 0,'','','','','','');
photos[2] = new photo(249761,'22649','','gallery','http://www1.clikpic.com/meddler/images/reversecrown.jpg',600,450,'Reverse Crown','http://www1.clikpic.com/meddler/images/reversecrown_thumb.jpg',130, 98,0, 0,'','','','','','');
photos[3] = new photo(249763,'22649','','gallery','http://www1.clikpic.com/meddler/images/geyser.jpg',480,640,'Geyser','http://www1.clikpic.com/meddler/images/geyser_thumb.jpg',130, 173,0, 0,'','','','','','');
photos[4] = new photo(249765,'22649','','gallery','http://www1.clikpic.com/meddler/images/jacuzzi.jpg',480,640,'Jaccuzi','http://www1.clikpic.com/meddler/images/jacuzzi_thumb.jpg',130, 173,0, 0,'','','','','','');
photos[5] = new photo(249767,'22649','','gallery','http://www1.clikpic.com/meddler/images/volcano.jpg',480,640,'Volcano','http://www1.clikpic.com/meddler/images/volcano_thumb.jpg',130, 173,0, 0,'','','','','','');
photos[6] = new photo(249768,'22649','','gallery','http://www1.clikpic.com/meddler/images/explode-blue.jpg',480,640,'Explode','http://www1.clikpic.com/meddler/images/explode-blue_thumb.jpg',130, 173,0, 0,'','','','','','');
photos[7] = new photo(249770,'22649','','gallery','http://www1.clikpic.com/meddler/images/gush-blue.jpg',480,640,'Gush','http://www1.clikpic.com/meddler/images/gush-blue_thumb.jpg',130, 173,0, 0,'','','','','','');
photos[8] = new photo(249772,'22649','','gallery','http://www1.clikpic.com/meddler/images/strangeplanet.jpg',480,640,'Strange Planet','http://www1.clikpic.com/meddler/images/strangeplanet_thumb.jpg',130, 173,0, 1,'','','','','','');
photos[9] = new photo(249774,'22651','Groin Detail 1','gallery','http://www1.clikpic.com/meddler/images/PICT5585.JPG',426,640,'Groin Detail 1','http://www1.clikpic.com/meddler/images/PICT5585_thumb.JPG',130, 195,0, 0,'','','','','','');
photos[10] = new photo(249775,'22651','','gallery','http://www1.clikpic.com/meddler/images/PICT5588.JPG',426,640,'Groin Detail 2','http://www1.clikpic.com/meddler/images/PICT5588_thumb.JPG',130, 195,0, 0,'','','','','','');
photos[11] = new photo(249776,'22651','','gallery','http://www1.clikpic.com/meddler/images/PICT5590.JPG',426,640,'Groin Detail 3','http://www1.clikpic.com/meddler/images/PICT5590_thumb.JPG',130, 195,0, 0,'','','','','','');
photos[12] = new photo(249780,'22651','','gallery','http://www1.clikpic.com/meddler/images/PICT5593.JPG',426,640,'Pebble','http://www1.clikpic.com/meddler/images/PICT5593_thumb.JPG',130, 195,0, 0,'','','','','','');
photos[13] = new photo(249783,'22652','','gallery','http://www1.clikpic.com/meddler/images/PICT2181.JPG',426,640,'Flag Waving','http://www1.clikpic.com/meddler/images/PICT2181_thumb.JPG',130, 195,0, 0,'','','','','','');
photos[14] = new photo(249785,'22652','','gallery','http://www1.clikpic.com/meddler/images/PICT1600.JPG',426,640,'Miniature Steamer','http://www1.clikpic.com/meddler/images/PICT1600_thumb.JPG',130, 195,0, 0,'','','','','','');
photos[15] = new photo(249786,'22652','','gallery','http://www1.clikpic.com/meddler/images/PICT1638.JPG',426,640,'Chopper','http://www1.clikpic.com/meddler/images/PICT1638_thumb.JPG',130, 195,0, 0,'','','','','','');
photos[16] = new photo(249788,'22652','','gallery','http://www1.clikpic.com/meddler/images/PICT2098.JPG',426,640,'Cheerleader Cheering','http://www1.clikpic.com/meddler/images/PICT2098_thumb.JPG',130, 195,0, 0,'','','','','','');
photos[17] = new photo(249789,'22652','','gallery','http://www1.clikpic.com/meddler/images/PICT2021.JPG',426,640,'Morris Dancer','http://www1.clikpic.com/meddler/images/PICT2021_thumb.JPG',130, 195,0, 0,'','','','','','');
photos[18] = new photo(249791,'22652','','gallery','http://www1.clikpic.com/meddler/images/PICT1632.JPG',426,640,'Playing The Flute','http://www1.clikpic.com/meddler/images/PICT1632_thumb.JPG',130, 195,0, 0,'','','','','','');
photos[19] = new photo(254703,'','','','http://www1.clikpic.com/meddler/images/square-2.jpg',400,400,'Paulo Rodrigues','http://www1.clikpic.com/meddler/images/square-2_thumb.jpg',130, 130,1, 0,'','','','','','');
photos[20] = new photo(411343,'33048','','gallery','http://www1.clikpic.com/meddler/images/PICT9148.JPG',401,600,'Hot Tongs','http://www1.clikpic.com/meddler/images/PICT9148_thumb.JPG',130, 195,0, 1,'A model has her hair styled live on stage','','','','','');
photos[21] = new photo(411344,'33048','','gallery','http://www1.clikpic.com/meddler/images/PICT8667.JPG',399,600,'Pro-Line Model','http://www1.clikpic.com/meddler/images/PICT8667_thumb.JPG',130, 195,0, 0,'A model promoting pro-line international poses for the camera','','','','','');
photos[22] = new photo(249793,'22654','','gallery','http://www1.clikpic.com/meddler/images/cornered.JPG',427,640,'cornered','http://www1.clikpic.com/meddler/images/cornered_thumb.JPG',130, 195,0, 0,'','','','','','');
photos[23] = new photo(249794,'22654','','gallery','http://www1.clikpic.com/meddler/images/PICT8059.JPG',426,640,'Leaning','http://www1.clikpic.com/meddler/images/PICT8059_thumb.JPG',130, 195,0, 0,'','','','','','');
photos[24] = new photo(249795,'22654','','gallery','http://www1.clikpic.com/meddler/images/redcorner.JPG',426,640,'The Red Corner','http://www1.clikpic.com/meddler/images/redcorner_thumb.JPG',130, 195,0, 0,'','','','','','');
photos[25] = new photo(249799,'22654','','gallery','http://www1.clikpic.com/meddler/images/PICT7965.JPG',426,640,'Leaning','http://www1.clikpic.com/meddler/images/PICT7965_thumb.JPG',130, 195,0, 0,'','','','','','');
photos[26] = new photo(249800,'22654','','gallery','http://www1.clikpic.com/meddler/images/PICT8016.JPG',427,640,'Sitting','http://www1.clikpic.com/meddler/images/PICT8016_thumb.JPG',130, 195,0, 0,'','','','','','');
photos[27] = new photo(249802,'22654','','gallery','http://www1.clikpic.com/meddler/images/PICT8027.JPG',426,640,'Shy','http://www1.clikpic.com/meddler/images/PICT8027_thumb.JPG',130, 195,0, 0,'','','','','','');
photos[28] = new photo(249803,'22654','','gallery','http://www1.clikpic.com/meddler/images/PICT79021.JPG',426,640,'Strong','http://www1.clikpic.com/meddler/images/PICT79021_thumb.JPG',130, 195,0, 0,'','','','','','');
photos[29] = new photo(249804,'22654','','gallery','http://www1.clikpic.com/meddler/images/PICT79283.JPG',427,640,'Space','http://www1.clikpic.com/meddler/images/PICT79283_thumb.JPG',130, 195,0, 1,'','','','','','');
photos[30] = new photo(249805,'22654','','gallery','http://www1.clikpic.com/meddler/images/PICT79201.JPG',600,399,'Pensive','http://www1.clikpic.com/meddler/images/PICT79201_thumb.JPG',130, 86,0, 0,'','','','','','');
photos[31] = new photo(411331,'22654','','gallery','http://www1.clikpic.com/meddler/images/PICT2150.JPG',399,600,'Hair Spray','http://www1.clikpic.com/meddler/images/PICT2150_thumb.JPG',130, 195,0, 0,'','','','','','');
photos[32] = new photo(411325,'22654','','gallery','http://www1.clikpic.com/meddler/images/philretouches.jpg',399,600,'Hot Hot Hot','http://www1.clikpic.com/meddler/images/philretouches_thumb.jpg',130, 195,0, 1,'','','','','','');
photos[33] = new photo(411332,'22654','','gallery','http://www1.clikpic.com/meddler/images/PICT2278.jpg',399,600,'That Yellow Dress','http://www1.clikpic.com/meddler/images/PICT2278_thumb.jpg',130, 195,0, 0,'','','','','','');
photos[34] = new photo(248275,'22478','','gallery','http://www1.clikpic.com/meddler/images/pict0070_1.jpg',426,640,'Ms Invincible','http://www1.clikpic.com/meddler/images/pict0070_1_thumb.jpg',130, 195,0, 0,'','','','London','','');
photos[35] = new photo(249726,'22478','','gallery','http://www1.clikpic.com/meddler/images/pict0069_1.jpg',426,640,'Marching for HMS Westminster','http://www1.clikpic.com/meddler/images/pict0069_1_thumb.jpg',130, 195,0, 0,'','','','','','');
photos[36] = new photo(249728,'22478','','gallery','http://www1.clikpic.com/meddler/images/pict0098_1.jpg',426,640,'The Boys are Behind You','http://www1.clikpic.com/meddler/images/pict0098_1_thumb.jpg',130, 195,0, 1,'','','','','','');
photos[37] = new photo(249731,'22478','','gallery','http://www1.clikpic.com/meddler/images/pict0114_1.jpg',426,640,'Cadet Marching','http://www1.clikpic.com/meddler/images/pict0114_1_thumb.jpg',130, 195,0, 0,'','','','','','');
photos[38] = new photo(249736,'22478','','gallery','http://www1.clikpic.com/meddler/images/pict0134_1.jpg',426,640,'Flower Girl','http://www1.clikpic.com/meddler/images/pict0134_1_thumb.jpg',130, 195,0, 0,'','','','','','');
photos[39] = new photo(249741,'22478','','gallery','http://www1.clikpic.com/meddler/images/pict0224_1.jpg',426,640,'Pearly Queen','http://www1.clikpic.com/meddler/images/pict0224_1_thumb.jpg',130, 195,0, 0,'','','','','','');
photos[40] = new photo(249744,'22478','','gallery','http://www1.clikpic.com/meddler/images/pict0344_1.jpg',429,640,'The Brown Jacket','http://www1.clikpic.com/meddler/images/pict0344_1_thumb.jpg',130, 194,0, 0,'','','','','','');
photos[41] = new photo(249749,'22478','','gallery','http://www1.clikpic.com/meddler/images/pict0311.jpg',426,640,'Blowing','http://www1.clikpic.com/meddler/images/pict0311_thumb.jpg',130, 195,0, 0,'','','','','','');
photos[42] = new photo(249752,'22478','','gallery','http://www1.clikpic.com/meddler/images/pict0559.jpg',426,640,'The Tuba','http://www1.clikpic.com/meddler/images/pict0559_thumb.jpg',130, 195,0, 0,'','','','','','');
photos[43] = new photo(249806,'22656','','gallery','http://www1.clikpic.com/meddler/images/fullface.JPG',600,450,'Less Than One','http://www1.clikpic.com/meddler/images/fullface_thumb.JPG',130, 98,0, 0,'','','','','','');
photos[44] = new photo(249808,'22656','','gallery','http://www1.clikpic.com/meddler/images/helplessbw.JPG',600,450,'Helpless','http://www1.clikpic.com/meddler/images/helplessbw_thumb.JPG',130, 98,0, 0,'','','','','','');
photos[45] = new photo(249809,'22656','','gallery','http://www1.clikpic.com/meddler/images/PICT5713.JPG',427,640,'Absorbed','http://www1.clikpic.com/meddler/images/PICT5713_thumb.JPG',130, 195,0, 0,'','','','','','');
photos[46] = new photo(249810,'22656','','gallery','http://www1.clikpic.com/meddler/images/PICT0094.JPG',427,640,'Portrait','http://www1.clikpic.com/meddler/images/PICT0094_thumb.JPG',130, 195,0, 0,'','','','','','');
photos[47] = new photo(249811,'22656','','gallery','http://www1.clikpic.com/meddler/images/PICT0226.JPG',426,640,'Oxford Graduation ','http://www1.clikpic.com/meddler/images/PICT0226_thumb.JPG',130, 195,0, 0,'','','','','','');
photos[48] = new photo(249812,'22656','','gallery','http://www1.clikpic.com/meddler/images/PICT76121.JPG',426,640,'Embankment','http://www1.clikpic.com/meddler/images/PICT76121_thumb.JPG',130, 195,0, 0,'','','','','','');
photos[49] = new photo(249813,'22656','','gallery','http://www1.clikpic.com/meddler/images/PICT76341.JPG',426,640,'South Bank Sitting','http://www1.clikpic.com/meddler/images/PICT76341_thumb.JPG',130, 195,0, 1,'','','','','','');
photos[50] = new photo(411338,'22656','','gallery','http://www1.clikpic.com/meddler/images/PICT0758.JPG',532,800,'The Hustler','http://www1.clikpic.com/meddler/images/PICT0758_thumb.JPG',130, 195,0, 0,'','','','','','');
photos[51] = new photo(411335,'22656','','gallery','http://www1.clikpic.com/meddler/images/PICT08352.JPG',533,800,'Hustler','http://www1.clikpic.com/meddler/images/PICT08352_thumb.JPG',130, 195,0, 0,'','','','','','');
photos[52] = new photo(411336,'22656','','gallery','http://www1.clikpic.com/meddler/images/PICT0900.JPG',532,800,'Imran','http://www1.clikpic.com/meddler/images/PICT0900_thumb.JPG',130, 195,0, 0,'','','','','','');
photos[53] = new photo(261140,'23408','','gallery','http://www1.clikpic.com/meddler/images/File0126.jpg',600,404,'Before','http://www1.clikpic.com/meddler/images/File0126_thumb.jpg',130, 88,0, 0,'This photo has been badly creased, destroying half the face of one of the children.','','','','','');
photos[54] = new photo(261142,'23408','','gallery','http://www1.clikpic.com/meddler/images/fancydress.jpg',600,392,'After','http://www1.clikpic.com/meddler/images/fancydress_thumb.jpg',130, 85,0, 0,'The image has had all of the creases restored using detail from adjacent parts of the picture, even the partially destroyed face has been restored.','','','','','');

/***************************************************************************
* Create the array of Gallery objects                                      *
***************************************************************************/
galleries = new Array();
galleries[0] = new gallery(33048,'411343','Afro Hair and Beauty Show 2006','gallery');
galleries[1] = new gallery(22651,'249780,249776,249775,249774','Nature','gallery');
galleries[2] = new gallery(22652,'249791,249789,249788,249786,249785,249783','New Years Day Parade 2006','gallery');
galleries[3] = new gallery(22649,'249772','Water','gallery');
galleries[4] = new gallery(22654,'411325,249804','Studio','gallery');
galleries[5] = new gallery(22656,'249813','Location','gallery');
galleries[6] = new gallery(22478,'249728','Lord Mayor\'s Show 2005','gallery');
galleries[7] = new gallery(22471,'411343,249728','Events','gallery');
galleries[8] = new gallery(22648,'249772','Abstract','gallery');
galleries[9] = new gallery(23408,'261142,261140','Restoration','gallery');

