/***************************************************************************
* 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('1803973');
	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('1803973');
	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)) {
		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;
			document.title = 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(1800839,'121011','','gallery','http://www1.clikpic.com/concertcamera/images/DSC_6650.jpg',428,640,'','http://www1.clikpic.com/concertcamera/images/DSC_6650_thumb.jpg',130, 194,0, 0,'','','Ian Wood','','','');
photos[1] = new photo(1800840,'121011','','gallery','http://www1.clikpic.com/concertcamera/images/DSC_6675.jpg',428,640,'','http://www1.clikpic.com/concertcamera/images/DSC_6675_thumb.jpg',130, 194,0, 0,'','','Ian Wood','','','');
photos[2] = new photo(1800841,'121011','','gallery','http://www1.clikpic.com/concertcamera/images/DSC_6695.jpg',428,640,'','http://www1.clikpic.com/concertcamera/images/DSC_6695_thumb.jpg',130, 194,0, 0,'','','Ian Wood','','','');
photos[3] = new photo(1800842,'121011','','gallery','http://www1.clikpic.com/concertcamera/images/DSC_6662.jpg',428,640,'','http://www1.clikpic.com/concertcamera/images/DSC_6662_thumb.jpg',130, 194,0, 0,'','','Ian Wood','','','');
photos[4] = new photo(1800843,'121011','','gallery','http://www1.clikpic.com/concertcamera/images/DSC_6798.jpg',428,640,'','http://www1.clikpic.com/concertcamera/images/DSC_6798_thumb.jpg',130, 194,0, 1,'','','Ian Wood','','','');
photos[5] = new photo(1800844,'121011','','gallery','http://www1.clikpic.com/concertcamera/images/DSC_7023.jpg',428,640,'','http://www1.clikpic.com/concertcamera/images/DSC_7023_thumb.jpg',130, 194,0, 0,'','','Ian Wood','','','');
photos[6] = new photo(1800845,'121011','','gallery','http://www1.clikpic.com/concertcamera/images/DSC_6875.jpg',600,401,'','http://www1.clikpic.com/concertcamera/images/DSC_6875_thumb.jpg',130, 87,0, 0,'','','Ian Wood','','','');
photos[7] = new photo(1800808,'121006','','gallery','http://www1.clikpic.com/concertcamera/images/DSC_7822.jpg',428,640,'','http://www1.clikpic.com/concertcamera/images/DSC_7822_thumb.jpg',130, 194,0, 0,'','','Ian Wood','','','');
photos[8] = new photo(1800810,'121006','','gallery','http://www1.clikpic.com/concertcamera/images/DSC_7978.jpg',428,640,'','http://www1.clikpic.com/concertcamera/images/DSC_7978_thumb.jpg',130, 194,0, 0,'','','Ian Wood','','','');
photos[9] = new photo(1800812,'121006','','gallery','http://www1.clikpic.com/concertcamera/images/DSC_8138.jpg',428,640,'','http://www1.clikpic.com/concertcamera/images/DSC_8138_thumb.jpg',130, 194,0, 1,'','','Ian Wood','','','');
photos[10] = new photo(1800813,'121006','','gallery','http://www1.clikpic.com/concertcamera/images/DSC_8214.jpg',428,640,'','http://www1.clikpic.com/concertcamera/images/DSC_8214_thumb.jpg',130, 194,0, 0,'','','Ian Wood','','','');
photos[11] = new photo(1800814,'121006','','gallery','http://www1.clikpic.com/concertcamera/images/DSC_8228.jpg',428,640,'','http://www1.clikpic.com/concertcamera/images/DSC_8228_thumb.jpg',130, 194,0, 0,'','','Ian Wood','','','');
photos[12] = new photo(1800815,'121006','','gallery','http://www1.clikpic.com/concertcamera/images/DSC_8790.jpg',600,401,'','http://www1.clikpic.com/concertcamera/images/DSC_8790_thumb.jpg',130, 87,0, 0,'','','Ian Wood','','','');
photos[13] = new photo(1800817,'121006','','gallery','http://www1.clikpic.com/concertcamera/images/DSC_8905.jpg',428,640,'','http://www1.clikpic.com/concertcamera/images/DSC_8905_thumb.jpg',130, 194,0, 0,'','','Ian Wood','','','');
photos[14] = new photo(1800818,'121006','','gallery','http://www1.clikpic.com/concertcamera/images/DSC_9368.jpg',428,640,'','http://www1.clikpic.com/concertcamera/images/DSC_9368_thumb.jpg',130, 194,0, 0,'','','Ian Wood','','','');
photos[15] = new photo(1800819,'121006','','gallery','http://www1.clikpic.com/concertcamera/images/DSC_9435.jpg',600,401,'','http://www1.clikpic.com/concertcamera/images/DSC_9435_thumb.jpg',130, 87,0, 0,'','','Ian Wood','','','');
photos[16] = new photo(1800821,'121006','','gallery','http://www1.clikpic.com/concertcamera/images/DSC_9447.jpg',428,640,'','http://www1.clikpic.com/concertcamera/images/DSC_9447_thumb.jpg',130, 194,0, 0,'','','Ian Wood','','','');
photos[17] = new photo(1800823,'121006','','gallery','http://www1.clikpic.com/concertcamera/images/DSC_9440.jpg',600,401,'','http://www1.clikpic.com/concertcamera/images/DSC_9440_thumb.jpg',130, 87,0, 0,'','','Ian Wood','','','');
photos[18] = new photo(2664893,'168627','','gallery','http://www1.clikpic.com/concertcamera/images/DSC_5561.jpg',600,402,'John Davies/Koffi Missah','http://www1.clikpic.com/concertcamera/images/DSC_5561_thumb.jpg',130, 87,0, 1,'','','','','','');
photos[19] = new photo(2664894,'168627','','gallery','http://www1.clikpic.com/concertcamera/images/DSC_5604.jpg',600,402,'John Davies/Koffi Missah','http://www1.clikpic.com/concertcamera/images/DSC_5604_thumb.jpg',130, 87,0, 0,'','','','','','');
photos[20] = new photo(2664895,'168627','','gallery','http://www1.clikpic.com/concertcamera/images/DSC_5597.jpg',600,402,'John Davies/Koffi Missah','http://www1.clikpic.com/concertcamera/images/DSC_5597_thumb.jpg',130, 87,0, 0,'','','','','','');
photos[21] = new photo(1803924,'121017','','gallery','http://www1.clikpic.com/concertcamera/images/100 (4).jpg',600,238,'','http://www1.clikpic.com/concertcamera/images/100 (4)_thumb.jpg',130, 52,0, 0,'','','Ian Wood','','','');
photos[22] = new photo(1803926,'121017','','gallery','http://www1.clikpic.com/concertcamera/images/100 (6).jpg',600,381,'','http://www1.clikpic.com/concertcamera/images/100 (6)_thumb.jpg',130, 83,0, 1,'','','Ian Wood','','','');
photos[23] = new photo(1803928,'121017','','gallery','http://www1.clikpic.com/concertcamera/images/100 (5).jpg',403,600,'','http://www1.clikpic.com/concertcamera/images/100 (5)_thumb.jpg',130, 194,0, 0,'','','Ian Wood','','','');
photos[24] = new photo(1803930,'121017','','gallery','http://www1.clikpic.com/concertcamera/images/100 (10).jpg',401,600,'','http://www1.clikpic.com/concertcamera/images/100 (10)_thumb.jpg',130, 195,0, 0,'','','Ian Wood','','','');
photos[25] = new photo(1803932,'121017','','gallery','http://www1.clikpic.com/concertcamera/images/100 (11).jpg',600,401,'','http://www1.clikpic.com/concertcamera/images/100 (11)_thumb.jpg',130, 87,0, 0,'','','Ian Wood','','','');
photos[26] = new photo(1803936,'121017','','gallery','http://www1.clikpic.com/concertcamera/images/100 (9).jpg',600,362,'','http://www1.clikpic.com/concertcamera/images/100 (9)_thumb.jpg',130, 78,0, 0,'','','Ian Wood','','','');
photos[27] = new photo(1803941,'121017','','gallery','http://www1.clikpic.com/concertcamera/images/100 (24).jpg',600,372,'','http://www1.clikpic.com/concertcamera/images/100 (24)_thumb.jpg',130, 81,0, 0,'','','Ian Wood','','','');
photos[28] = new photo(1803943,'121017','','gallery','http://www1.clikpic.com/concertcamera/images/100 (25).jpg',403,600,'','http://www1.clikpic.com/concertcamera/images/100 (25)_thumb.jpg',130, 194,0, 0,'','','Ian Wood','','','');
photos[29] = new photo(1803947,'121017','','gallery','http://www1.clikpic.com/concertcamera/images/100 (16).jpg',403,600,'','http://www1.clikpic.com/concertcamera/images/100 (16)_thumb.jpg',130, 194,0, 0,'','','Ian Wood','','','');
photos[30] = new photo(1800833,'121010','','gallery','http://www1.clikpic.com/concertcamera/images/DSC_6048.jpg',600,456,'','http://www1.clikpic.com/concertcamera/images/DSC_6048_thumb.jpg',130, 99,0, 0,'','','Ian Wood','','','');
photos[31] = new photo(1800834,'121010','','gallery','http://www1.clikpic.com/concertcamera/images/DSC_6358.jpg',428,640,'','http://www1.clikpic.com/concertcamera/images/DSC_6358_thumb.jpg',130, 194,0, 1,'','','Ian Wood','','','');
photos[32] = new photo(1800835,'121010','','gallery','http://www1.clikpic.com/concertcamera/images/DSC_6426.jpg',428,640,'','http://www1.clikpic.com/concertcamera/images/DSC_6426_thumb.jpg',130, 194,0, 0,'','','Ian Wood','','','');
photos[33] = new photo(1803685,'121269','','gallery','http://www1.clikpic.com/concertcamera/images/Disco Inferno16Olympic Stadium1.jpg',393,600,'','http://www1.clikpic.com/concertcamera/images/Disco Inferno16Olympic Stadium1_thumb.jpg',130, 198,0, 0,'','','Ian Wood','','','');
photos[34] = new photo(1803973,'121269','','gallery','http://www1.clikpic.com/concertcamera/images/Disco Inferno20Olympic Stadium1.jpg',600,375,'','http://www1.clikpic.com/concertcamera/images/Disco Inferno20Olympic Stadium1_thumb.jpg',130, 81,1, 0,'','','','','','');
photos[35] = new photo(1803974,'121269','','gallery','http://www1.clikpic.com/concertcamera/images/Disco Inferno35Olympic Stadium2.jpg',400,600,'','http://www1.clikpic.com/concertcamera/images/Disco Inferno35Olympic Stadium2_thumb.jpg',130, 195,0, 1,'','','','','','');
photos[36] = new photo(1803975,'121269','','gallery','http://www1.clikpic.com/concertcamera/images/Disco Inferno12Olympic Stadium2.jpg',378,600,'','http://www1.clikpic.com/concertcamera/images/Disco Inferno12Olympic Stadium2_thumb.jpg',130, 206,0, 0,'','','','','','');
photos[37] = new photo(1803976,'121269','','gallery','http://www1.clikpic.com/concertcamera/images/Disco Inferno39Olympic Stadium1.jpg',439,600,'','http://www1.clikpic.com/concertcamera/images/Disco Inferno39Olympic Stadium1_thumb.jpg',130, 178,0, 0,'','','','','','');
photos[38] = new photo(1803977,'121269','','gallery','http://www1.clikpic.com/concertcamera/images/Disco Inferno24Olympic Stadium1.jpg',600,403,'','http://www1.clikpic.com/concertcamera/images/Disco Inferno24Olympic Stadium1_thumb.jpg',130, 87,0, 0,'','','','','','');
photos[39] = new photo(1803978,'121269','','gallery','http://www1.clikpic.com/concertcamera/images/Disco Inferno40Olympic Stadium1.jpg',600,350,'','http://www1.clikpic.com/concertcamera/images/Disco Inferno40Olympic Stadium1_thumb.jpg',130, 76,0, 0,'','','','','','');
photos[40] = new photo(1803980,'121269','','gallery','http://www1.clikpic.com/concertcamera/images/Disco Inferno44Olympic Stadium1.jpg',600,260,'','http://www1.clikpic.com/concertcamera/images/Disco Inferno44Olympic Stadium1_thumb.jpg',130, 56,0, 0,'','','','','','');
photos[41] = new photo(1803985,'121269','','gallery','http://www1.clikpic.com/concertcamera/images/Disco Inferno34Olympic Stadium.jpg',600,502,'','http://www1.clikpic.com/concertcamera/images/Disco Inferno34Olympic Stadium_thumb.jpg',130, 109,0, 0,'','','','','','');
photos[42] = new photo(1803952,'121268','','gallery','http://www1.clikpic.com/concertcamera/images/Andy Great Shots03.jpg',442,600,'','http://www1.clikpic.com/concertcamera/images/Andy Great Shots03_thumb.jpg',130, 176,0, 0,'','','Ian Wood','','','');
photos[43] = new photo(1803953,'121268','','gallery','http://www1.clikpic.com/concertcamera/images/Andy Great Shots04.jpg',600,392,'','http://www1.clikpic.com/concertcamera/images/Andy Great Shots04_thumb.jpg',130, 85,0, 0,'','','Ian Wood','','','');
photos[44] = new photo(1803954,'121268','','gallery','http://www1.clikpic.com/concertcamera/images/Andy Great Shots08.jpg',600,436,'','http://www1.clikpic.com/concertcamera/images/Andy Great Shots08_thumb.jpg',130, 94,0, 0,'','','Ian Wood','','','');
photos[45] = new photo(1803955,'121268','','gallery','http://www1.clikpic.com/concertcamera/images/1 (3).jpg',419,600,'','http://www1.clikpic.com/concertcamera/images/1 (3)_thumb.jpg',130, 186,0, 0,'','','Ian Wood','','','');
photos[46] = new photo(1803956,'121268','','gallery','http://www1.clikpic.com/concertcamera/images/1 (5).jpg',600,401,'','http://www1.clikpic.com/concertcamera/images/1 (5)_thumb.jpg',130, 87,0, 0,'','','Ian Wood','','','');
photos[47] = new photo(1803957,'121268','','gallery','http://www1.clikpic.com/concertcamera/images/1 (7).jpg',382,600,'','http://www1.clikpic.com/concertcamera/images/1 (7)_thumb.jpg',130, 204,0, 1,'','','Ian Wood','','','');
photos[48] = new photo(1803958,'121268','','gallery','http://www1.clikpic.com/concertcamera/images/1 (12).jpg',403,600,'','http://www1.clikpic.com/concertcamera/images/1 (12)_thumb.jpg',130, 194,0, 0,'','','Ian Wood','','','');
photos[49] = new photo(2664849,'168624','','gallery','http://www1.clikpic.com/concertcamera/images/AdDisplayforDesertDiamondTwistShout1.jpg',418,600,'TWIST & SHOUT USA','http://www1.clikpic.com/concertcamera/images/AdDisplayforDesertDiamondTwistShout1_thumb.jpg',130, 187,0, 1,'','','','','','');
photos[50] = new photo(2664851,'168624','','gallery','http://www1.clikpic.com/concertcamera/images/flyer1.jpg',464,600,'Tony Kishman USA','http://www1.clikpic.com/concertcamera/images/flyer1_thumb.jpg',130, 168,0, 0,'','','','','','');
photos[51] = new photo(2664853,'168624','','gallery','http://www1.clikpic.com/concertcamera/images/small.jpg',600,402,'THANK YOU FOR THE MUSIC Group Shot','http://www1.clikpic.com/concertcamera/images/small_thumb.jpg',130, 87,0, 0,'','','','','','');

/***************************************************************************
* Create the array of Gallery objects                                      *
***************************************************************************/
galleries = new Array();
galleries[0] = new gallery(121011,'1800843','Trondheym','gallery');
galleries[1] = new gallery(121006,'1800812','ABBA - Thank you For The Music','gallery');
galleries[2] = new gallery(168627,'2664893','John Davies/Koffi Missah','gallery');
galleries[3] = new gallery(121017,'1803926','ALL YOU NEED IS LOVE','gallery');
galleries[4] = new gallery(121010,'1800834','Tony Kishman','gallery');
galleries[5] = new gallery(121269,'1803974','Disco Inferno - Live','gallery');
galleries[6] = new gallery(121268,'1803957','Stars In Concert','gallery');
galleries[7] = new gallery(168624,'2664849','Publicity','gallery');

