/***************************************************************************
* 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) {
	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;
}
/***************************************************************************
* 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('688724,648071,647863,475729,475207');
	for (j = 0; j < photos.length; j++) {
		if (photos[j].id == imageID) {
			if (!basic) {
			img.src = 'images/' + 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 = 'images/' + 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('688724,648071,647863,475729,475207');
	for (j = 0; j < photos.length; j++) {
		if (photos[j].id == imageID) {
			if ('section73417' != '') {
						if (photos[j].galleries_id != '') {
						document.write('<a href="' + photos[j].section_code + '_' + photos[j].galleries_id + '.html">');
						}
						else {
						document.write('<a href="section73417.html">');
						}
			}
			document.write('<img src="images/' + photos[j].src + '" width="' + photos[j].width + '" height="' + photos[j].height + '" class="mainhomepageimage" id="mainSample" name="mainSample" alt="' + photos[j].caption  + '" border="0">');
			if ('section73417' != '') {
				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="images/' + 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 = 'images/' + 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(647863,'37502','','gallery','Carling Academy 388.jpg',500,333,'Carling Academy in Islington ','Carling Academy 3881.jpg',130, 87,1, 0,'','09/12/06','','');
photos[1] = new photo(475193,'37502','','gallery','AllCrewpics2002.jpg',500,332,'DJ Rap','AllCrewpics20022.jpg',130, 86,0, 0,'','','','');
photos[2] = new photo(475199,'37502','','gallery','Breakbeat1.jpg',500,333,'Hug','Breakbeat11.jpg',130, 87,0, 0,'','','','');
photos[3] = new photo(475207,'37502','','gallery','Breakbeat0.jpg',500,333,'Dancing','Breakbeat01.jpg',130, 87,1, 0,'','','','');
photos[4] = new photo(475215,'37502','','gallery','HYPE_at_DESIRE_8th_March_97.jpg',500,331,'DJ Hype','HYPE_at_DESIRE_8th_March_971.jpg',130, 86,0, 0,'','','','');
photos[5] = new photo(475216,'37502','','gallery','IMG_4704.jpg',500,191,'turnmills, London EC1','IMG_47041.jpg',130, 50,0, 0,'','','','');
photos[6] = new photo(475228,'37502','','gallery','IMG_5999.jpg',500,333,'Sheffield','IMG_59991.jpg',130, 87,0, 0,'','','','');
photos[7] = new photo(475229,'37502','','gallery','BookCoverUS.jpg',500,397,'','BookCoverUS1.jpg',130, 103,0, 0,'','','','');
photos[8] = new photo(475231,'37502','','gallery','IMG_6835.jpg',500,333,'Mist','IMG_68351.jpg',130, 87,0, 0,'','','','');
photos[9] = new photo(475232,'37502','','gallery','Leisure_Lounge_Metalheadz.jpg',500,348,'Metalheadz','Leisure_Lounge_Metalheadz1.jpg',130, 90,0, 0,'','','','');
photos[10] = new photo(475233,'37502','','gallery','Raindance_98.jpg',500,351,'Raindance','Raindance_981.jpg',130, 91,0, 0,'','','','');
photos[11] = new photo(475235,'37502','','gallery','Club_Sin_159.jpg',500,425,'','Club_Sin_1591.jpg',130, 111,0, 0,'','','','');
photos[12] = new photo(475257,'37502','','gallery','IMG_5210.jpg',500,115,'Marco V','IMG_52101.jpg',130, 30,0, 0,'','','','');
photos[13] = new photo(475258,'37502','','gallery','IMG_6700.jpg',500,333,'Eyes','IMG_67001.jpg',130, 87,0, 0,'','','','');
photos[14] = new photo(475661,'37502','','gallery','Love_Box22.jpg',500,333,'Oxfam','Love_Box221.jpg',130, 87,0, 0,'','','','');
photos[15] = new photo(475666,'37502','','gallery','Mini_Chill_1.jpg',500,333,'Smoothie','Mini_Chill_11.jpg',130, 87,0, 0,'','','','');
photos[16] = new photo(475679,'37502','','gallery','Breakbeat6.jpg',500,333,'Going for it','Breakbeat61.jpg',130, 87,0, 0,'','','','');
photos[17] = new photo(475692,'37502','','gallery','Helter_skelter_Milton_Keyne.jpg',500,335,'Helter Skelter at the Sancutary in Milton Keynes.','Helter_skelter_Milton_Keyne1.jpg',130, 87,0, 0,'','','','');
photos[18] = new photo(475695,'37502','','gallery','ICA.jpg',500,333,'The ICA in London','ICA1.jpg',130, 87,0, 0,'','','','');
photos[19] = new photo(475723,'37502','','gallery','IMG_4745.jpg',500,333,'Lasers','IMG_47451.jpg',130, 87,0, 0,'','','','');
photos[20] = new photo(475729,'37502','','gallery','IMG_5085.jpg',500,180,'Green Beams','IMG_50851.jpg',130, 47,1, 0,'','','','');
photos[21] = new photo(475733,'37502','','gallery','IMG_5097.jpg',500,333,'10000 people dressed in white.','IMG_50971.jpg',130, 87,0, 0,'','','','');
photos[22] = new photo(475737,'37502','','gallery','IMG_5268.jpg',500,333,'It\'s Hot.','IMG_52681.jpg',130, 87,0, 0,'','','','');
photos[23] = new photo(475741,'37502','','gallery','IMG_5700.jpg',500,333,'Marco V in UK.','IMG_57001.jpg',130, 87,0, 0,'','','','');
photos[24] = new photo(475744,'37502','','gallery','IMG_5743.jpg',500,333,'Goodgreef.','IMG_57431.jpg',130, 87,0, 0,'','','','');
photos[25] = new photo(475752,'37502','','gallery','Love_Box3.jpg',500,333,'Love Box in Victoria Park.','Love_Box31.jpg',130, 87,0, 0,'','','','');
photos[26] = new photo(475755,'37502','','gallery','Love_Box5.jpg',500,333,'Relaxing.','Love_Box51.jpg',130, 87,0, 0,'','','','');
photos[27] = new photo(475757,'37502','','gallery','Love_Box14.jpg',500,333,'Living Room Graffiti.','Love_Box141.jpg',130, 87,0, 0,'','','','');
photos[28] = new photo(475043,'37502','Shower in Heaven is the original name','gallery','SHOWERINHEAVEN.jpg',360,244,'World Dance New years Eve 1995','SHOWERINHEAVEN1.jpg',130, 88,0, 1,'','','','');
photos[29] = new photo(688723,'37502','','gallery','Carling Academy 3882.jpg',500,333,'Carling Academy 388 600','Carling Academy 3882_thumb.jpg',130, 87,0, 0,'','','','');
photos[30] = new photo(475109,'37502','','gallery','IMG_5737.jpg',500,497,'','IMG_57371.jpg',130, 129,0, 0,'DSI Man','','','');
photos[31] = new photo(688724,'37502','','gallery','SeOne 2702.jpg',500,333,'SeOne 270 600','SeOne 2702_thumb.jpg',130, 87,1, 0,'','','','');
photos[32] = new photo(648071,'48273','','gallery','Heaven 282.jpg',500,750,'Heaven','Heaven 2821.jpg',130, 195,1, 1,'','','','');
photos[33] = new photo(686123,'48273','','gallery','Club Sin 2 004.jpg',500,755,'Club SIN','Club Sin 2 004_thumb.jpg',130, 196,0, 0,'','','','');
photos[34] = new photo(686228,'48273','','gallery','IMG_6720.JPG',500,750,'Fish','IMG_6720_thumb.jpg',130, 195,0, 0,'','','','');
photos[35] = new photo(686359,'48273','','gallery','Love Box 4412.jpg',500,750,'Beer','Love Box 4412_thumb.jpg',130, 195,0, 0,'','','','');
photos[36] = new photo(685945,'48273','','gallery','DJ RAP.jpg',500,681,'DJ RAP at the Island Ilford Essex','DJ RAP_thumb.jpg',130, 177,0, 0,'','','','');
photos[37] = new photo(686124,'48273','','gallery','IMG_5060.JPG',500,759,'Making up','IMG_5060_thumb.jpg',130, 197,0, 0,'','','','');
photos[38] = new photo(686229,'48273','','gallery','IMG_6731.JPG',500,750,'Love','IMG_6731_thumb.jpg',130, 195,0, 0,'','','','');
photos[39] = new photo(685946,'48273','','gallery','DJ Vox Pops, Breakbeat (53).jpg',500,750,'Higher State Event','DJ Vox Pops, Breakbeat (53)_thumb.jpg',130, 195,0, 0,'','','','');
photos[40] = new photo(686125,'48273','','gallery','IMG_5106.JPG',500,727,'Aliens Landing','IMG_5106_thumb.jpg',130, 189,0, 0,'','','','');
photos[41] = new photo(686230,'48273','','gallery','Love Box 0271.jpg',500,750,'Glasses','Love Box 0271_thumb.jpg',130, 195,0, 0,'','','','');
photos[42] = new photo(686126,'48273','','gallery','IMG_51281.JPG',500,750,'Tired','IMG_51281_thumb.jpg',130, 195,0, 0,'','','','');
photos[43] = new photo(686231,'48273','','gallery','Love Box 0861.jpg',500,750,'Straw','Love Box 0861_thumb.jpg',130, 195,0, 0,'','','','');
photos[44] = new photo(686362,'48273','','gallery','Love Box 5382.jpg',500,750,'Amazing Graffiti','Love Box 5382_thumb.jpg',130, 195,0, 0,'','','','');
photos[45] = new photo(685948,'48273','','gallery','Gold Lust at Rocket club photo1.jpg',500,741,'Gold Lust (Rocket club, Holloway Rd)','Gold Lust at Rocket club photo1_thumb.jpg',130, 193,0, 0,'','','','');
photos[46] = new photo(686128,'48273','','gallery','IMG_53101.JPG',500,750,'White gloves','IMG_53101_thumb.jpg',130, 195,0, 0,'','','','');
photos[47] = new photo(686233,'48273','','gallery','Love Box 131A1.jpg',500,750,'Under the Magic Tree','Love Box 131A1_thumb.jpg',130, 195,0, 0,'','','','');
photos[48] = new photo(686364,'48273','','gallery','Love Box 6641.jpg',500,750,'Never too late','Love Box 6641_thumb.jpg',130, 195,0, 0,'','','','');
photos[49] = new photo(686129,'48273','','gallery','IMG_53931.JPG',500,750,'IMG 5393','IMG_53931_thumb.jpg',130, 195,0, 0,'DJ Marco V','','','');
photos[50] = new photo(686365,'48273','','gallery','Mini Chill 0101.jpg',500,750,'Champagne','Mini Chill 0101_thumb.jpg',130, 195,0, 0,'','','','');
photos[51] = new photo(686130,'48273','','gallery','IMG_59811.JPG',500,750,'Pink','IMG_59811_thumb.jpg',130, 195,0, 0,'','','','');
photos[52] = new photo(686235,'48273','','gallery','Love Box 1421.jpg',500,750,'Flying High.','Love Box 1421_thumb.jpg',130, 195,0, 0,'','','','');
photos[53] = new photo(685952,'48273','','gallery','Hi(gh)!.jpg',500,714,'Hi(gh)!','Hi(gh)!_thumb.jpg',130, 186,0, 0,'','','','');
photos[54] = new photo(686131,'48273','','gallery','IMG_6209.JPG',500,750,'IMG 6209','IMG_6209_thumb.jpg',130, 195,0, 0,'Texting','','','');
photos[55] = new photo(686236,'48273','','gallery','Love Box 148.jpg',500,750,'Love Box 148','Love Box 148_thumb.jpg',130, 195,0, 0,'Shade','','','');
photos[56] = new photo(685954,'48273','','gallery','ICA Dead Sexy (4).jpg',500,750,'Drums','ICA Dead Sexy (4)_thumb.jpg',130, 195,0, 0,'','','','');
photos[57] = new photo(686369,'48273','','gallery','Mini Chill 255.jpg',500,750,'Mini Chill 255','Mini Chill 255_thumb.jpg',130, 195,0, 0,'My World','','','');
photos[58] = new photo(685955,'48273','','gallery','IMG_4713.JPG',500,750,'Loving it','IMG_4713_thumb.jpg',130, 195,0, 0,'','','','');
photos[59] = new photo(685956,'48273','','gallery','IMG_4980.JPG',500,750,'Feet','IMG_4980_thumb.jpg',130, 195,0, 0,'','','','');
photos[60] = new photo(686241,'48273','','gallery','Love Box 4042.jpg',500,750,'Nice food','Love Box 4042_thumb.jpg',130, 195,0, 0,'','','','');
photos[61] = new photo(685957,'48273','','gallery','IMG_5128.JPG',500,750,'Tired','IMG_5128_thumb.jpg',130, 195,0, 0,'','','','');
photos[62] = new photo(686375,'48273','','gallery','Mini Chill 465.jpg',500,750,'Young Photographer','Mini Chill 465_thumb.jpg',130, 195,0, 0,'','','','');
photos[63] = new photo(686245,'48273','','gallery','Love Box 5171.jpg',500,750,'Bath time','Love Box 5171_thumb.jpg',130, 195,0, 0,'','','','');
photos[64] = new photo(686376,'48273','','gallery','Mini Chill 470.jpg',500,750,'12 year old kids','Mini Chill 470_thumb.jpg',130, 195,0, 0,'','','','');
photos[65] = new photo(686377,'48273','','gallery','Mini Chill 501.jpg',500,750,'Friends','Mini Chill 501_thumb.jpg',130, 195,0, 0,'','','','');
photos[66] = new photo(686378,'48273','','gallery','Mini Chill 622.jpg',500,750,'My mummy','Mini Chill 622_thumb.jpg',130, 195,0, 0,'','','','');
photos[67] = new photo(685960,'48273','','gallery','IMG_6658.JPG',500,750,'The red room','IMG_6658_thumb.jpg',130, 195,0, 0,'','','','');
photos[68] = new photo(688666,'48274','','gallery','IMG_5606.jpg',400,600,'Easter Sunday Stroll','IMG_5606_thumb.jpg',130, 195,0, 0,'','','','');

/***************************************************************************
* Create the array of Gallery objects                                      *
***************************************************************************/
galleries = new Array();
galleries[0] = new gallery(37502,'475043','Clubbing 1','gallery');
galleries[1] = new gallery(48273,'648071','Clubbing 2','gallery');
galleries[2] = new gallery(48274,'688666','Street Photography','gallery');

