/***************************************************************************
* Create a thumbnail photo object                                          *
***************************************************************************/
function thumbnail(id,galleries_id,caption,src,width,height,server_id) {
	this.id = id;
	this.galleries_id = galleries_id;
	this.caption = caption;
	this.src = getServerPath(server_id) + '/' + src;
	this.width = width;
	this.height = height;
}
/***************************************************************************
* Create a gallery object                                                  *
***************************************************************************/

function gallery(id,featured_images,title,section_code,photoIDs) {
	this.id = id;
	this.featured_images = featured_images;
	this.title = title;
	this.section_code = section_code;	this.photoIDs = photoIDs;}

var thumbnails = new Object();
												thumbnails[1161378] = new thumbnail(1161378,'210754','','IMGP1759_thumb.jpg',130, 86,18);
												thumbnails[1161382] = new thumbnail(1161382,'210754','March 74S','IMGP2398_thumb.jpg',130, 86,18);
												thumbnails[1163460] = new thumbnail(1163460,'210754','1908 racer at Goodwood','fos08-332web_thumb.jpg',130, 86,18);
												thumbnails[3443061] = new thumbnail(3443061,'210754','Pick up truck racing at the DTM meet 2008','dtm08 320 website_thumb.jpg',130, 86,18);
												thumbnails[3443120] = new thumbnail(3443120,'210754','Rain Master.','IMGP8509 website_thumb.jpg',130, 86,18);
												thumbnails[1161516] = new thumbnail(1161516,'210754','Ferrari F1','fos08-026web_thumb.jpg',130, 86,18);
												thumbnails[3443063] = new thumbnail(3443063,'210754','Witsun Trophy, Goodwood Revival 2008','5198 desat website_thumb.jpg',130, 73,18);
												thumbnails[3443074] = new thumbnail(3443074,'210754','Britcar \'Into the Night\' race ','IMGP6642 website_thumb.jpg',130, 86,18);
												thumbnails[3443087] = new thumbnail(3443087,'210754','Willams F1 cars in the donnington Prix Grand P Colection','IMGP0237 website_thumb.jpg',130, 86,18);
												thumbnails[2145807] = new thumbnail(2145807,'210754','A1GP Brands Hatch 4th May 2008','IMGP6658_thumb.jpg',130, 86,18);
												thumbnails[2316713] = new thumbnail(2316713,'210754','','IMGP4654_thumb.jpg',130, 86,18);
												thumbnails[1161284] = new thumbnail(1161284,'210754','Drifting round Druids','IMGP1184_thumb.jpg',130, 86,18);
												thumbnails[1235449] = new thumbnail(1235449,'210754','Porsche 962C','IMGP3550_thumb.jpg',130, 87,18);
												thumbnails[2145811] = new thumbnail(2145811,'210754','A1GP Brands Hatch 4th May 2008','IMGP7226_thumb.jpg',130, 195,18);
												thumbnails[2316723] = new thumbnail(2316723,'210754','Lotus Elise at Brands','IMGP5581_thumb.jpg',130, 195,18);
												thumbnails[3443067] = new thumbnail(3443067,'210754','At the end of the day.','IMGP5297 website_thumb.jpg',130, 195,18);
												thumbnails[1235479] = new thumbnail(1235479,'210754','Group C racers','IMGP3301crop_thumb.jpg',130, 166,18);
												thumbnails[1235407] = new thumbnail(1235407,'210754','Rare line up of Porsche 962\'s','IMGP3298_thumb.jpg',130, 195,18);
												thumbnails[1161505] = new thumbnail(1161505,'210754','Bentley Le Mans Winner','saved-goodwood-FOS20062-024_thumb.jpg',130, 171,18);
												thumbnails[1235464] = new thumbnail(1235464,'210754','Silk Cut Jaguar','IMGP3293_thumb.jpg',130, 195,18);
												thumbnails[4471643] = new thumbnail(4471643,'260363','','IMGP1494web_thumb.jpg',86, 130,18);
												thumbnails[4471645] = new thumbnail(4471645,'260363','','IMGP1494web1_thumb.jpg',86, 130,18);
												thumbnails[4471661] = new thumbnail(4471661,'260363','','IMGP1418crweb_thumb.jpg',130, 93,18);
												thumbnails[4471664] = new thumbnail(4471664,'260363','','IMGP1384web_thumb.jpg',130, 86,18);
												thumbnails[4471665] = new thumbnail(4471665,'260363','','IMGP1300web_thumb.jpg',130, 86,18);
												thumbnails[4471668] = new thumbnail(4471668,'260363','','IMGP1272web_thumb.jpg',130, 86,18);
												thumbnails[4471669] = new thumbnail(4471669,'260363','','IMGP1250web_thumb.jpg',130, 86,18);
												thumbnails[4471670] = new thumbnail(4471670,'260363','','IMGP1067web_thumb.jpg',130, 86,18);
												thumbnails[4471673] = new thumbnail(4471673,'260363','','IMGP0558web_thumb.jpg',130, 86,18);
												thumbnails[4471538] = new thumbnail(4471538,'260362','','_IGP1613web_thumb.jpg',130, 85,18);
												thumbnails[4471544] = new thumbnail(4471544,'260362','','_IGP1625web_thumb.jpg',130, 87,18);
												thumbnails[4471548] = new thumbnail(4471548,'260362','','_IGP2004web_thumb.jpg',86, 130,18);
												thumbnails[4471550] = new thumbnail(4471550,'260362','','_IGP2027web_thumb.jpg',130, 86,18);
												thumbnails[4471553] = new thumbnail(4471553,'260362','','_IGP2109web_thumb.jpg',130, 86,18);
												thumbnails[4471555] = new thumbnail(4471555,'260362','','_IGP2427web_thumb.jpg',130, 86,18);
												thumbnails[4471556] = new thumbnail(4471556,'260362','','_IGP2433crweb_thumb.jpg',130, 81,18);
												thumbnails[4471558] = new thumbnail(4471558,'260362','','_IGP2531_edited-1web_thumb.jpg',130, 86,18);
												thumbnails[4471560] = new thumbnail(4471560,'260362','','_IGP2540web_thumb.jpg',130, 86,18);
												thumbnails[4471562] = new thumbnail(4471562,'260362','','_IGP2548web_thumb.jpg',130, 86,18);
												thumbnails[4471566] = new thumbnail(4471566,'260361','','_IGP3028web_thumb.jpg',130, 86,18);
												thumbnails[4471567] = new thumbnail(4471567,'260361','','_IGP3091web_thumb.jpg',130, 86,18);
												thumbnails[4471568] = new thumbnail(4471568,'260361','','_IGP3301web_thumb.jpg',130, 86,18);
												thumbnails[4471570] = new thumbnail(4471570,'260361','','_IGP3348web_thumb.jpg',130, 86,18);
												thumbnails[4471571] = new thumbnail(4471571,'260361','','_IGP3437web_thumb.jpg',130, 86,18);
												thumbnails[4471573] = new thumbnail(4471573,'260361','','_IGP3458web_thumb.jpg',130, 86,18);
												thumbnails[4471577] = new thumbnail(4471577,'260361','','_IGP3532web_thumb.jpg',130, 86,18);
												thumbnails[4471579] = new thumbnail(4471579,'260361','','_IGP3794web_thumb.jpg',130, 86,18);
												thumbnails[4471581] = new thumbnail(4471581,'260361','','_IGP3815web_thumb.jpg',130, 86,18);
												thumbnails[4471787] = new thumbnail(4471787,'260360','','_IGP4025web_thumb.jpg',86, 130,18);
												thumbnails[4471789] = new thumbnail(4471789,'260360','','_IGP4045web_thumb.jpg',130, 86,18);
												thumbnails[4471793] = new thumbnail(4471793,'260360','','_IGP4153web_thumb.jpg',130, 86,18);
												thumbnails[4471795] = new thumbnail(4471795,'260360','','_IGP4400web_thumb.jpg',130, 86,18);
												thumbnails[4471797] = new thumbnail(4471797,'260360','','_IGP4460web_thumb.jpg',130, 86,18);
												thumbnails[4471799] = new thumbnail(4471799,'260360','','_IGP4609web_thumb.jpg',130, 86,18);
												thumbnails[4471801] = new thumbnail(4471801,'260360','','_IGP4652web_thumb.jpg',130, 86,18);
												thumbnails[4471803] = new thumbnail(4471803,'260360','','_IGP4660web_thumb.jpg',130, 86,18);
												thumbnails[4471804] = new thumbnail(4471804,'260360','','_IGP4705web_thumb.jpg',130, 86,18);
												thumbnails[4471808] = new thumbnail(4471808,'260360','','_IGP4730web_thumb.jpg',130, 86,18);
												thumbnails[4471811] = new thumbnail(4471811,'260360','','_IGP4737web_thumb.jpg',130, 86,18);
												thumbnails[4471812] = new thumbnail(4471812,'260360','','_IGP4787web_thumb.jpg',130, 86,18);
												thumbnails[4471816] = new thumbnail(4471816,'260360','','_IGP4960web_thumb.jpg',130, 86,18);
												thumbnails[4471820] = new thumbnail(4471820,'260360','','_IGP5059web_thumb.jpg',130, 86,18);
												thumbnails[4471823] = new thumbnail(4471823,'260360','','_IGP5139web_thumb.jpg',130, 86,18);
												thumbnails[4471827] = new thumbnail(4471827,'260360','','_IGP5143web_thumb.jpg',130, 86,18);
												thumbnails[4471680] = new thumbnail(4471680,'260359','','_IGP5515web_thumb.jpg',130, 86,18);
												thumbnails[4471682] = new thumbnail(4471682,'260359','','_IGP5538cweb_thumb.jpg',130, 82,18);
												thumbnails[4471683] = new thumbnail(4471683,'260359','','_IGP5545web_thumb.jpg',130, 86,18);
												thumbnails[4471687] = new thumbnail(4471687,'260359','','_IGP5723web_thumb.jpg',130, 86,18);
												thumbnails[4471690] = new thumbnail(4471690,'260359','','_IGP5765web_thumb.jpg',130, 86,18);
												thumbnails[4471691] = new thumbnail(4471691,'260359','','_IGP5829web_thumb.jpg',130, 86,18);
												thumbnails[4471586] = new thumbnail(4471586,'260358','','_IGP6012web_thumb.jpg',130, 86,18);
												thumbnails[4471590] = new thumbnail(4471590,'260358','','_IGP6037web_thumb.jpg',86, 130,18);
												thumbnails[4471591] = new thumbnail(4471591,'260358','','_IGP6166cweb_thumb.jpg',130, 91,18);
												thumbnails[4471594] = new thumbnail(4471594,'260358','','_IGP6172web_thumb.jpg',130, 86,18);
												thumbnails[4471595] = new thumbnail(4471595,'260358','','_IGP6255web_thumb.jpg',130, 86,18);
												thumbnails[4471596] = new thumbnail(4471596,'260358','','_IGP6328ccweb_thumb.jpg',130, 87,18);
												thumbnails[4471599] = new thumbnail(4471599,'260358','','_IGP6478web_thumb.jpg',130, 86,18);
												thumbnails[4471600] = new thumbnail(4471600,'260358','','_IGP6487web_thumb.jpg',130, 86,18);
												thumbnails[4472086] = new thumbnail(4472086,'210755','','_IGP6748web_copy_thumb.jpg',130, 86,18);
												thumbnails[4472092] = new thumbnail(4472092,'210755','','_IGP6800web_copy_thumb.jpg',130, 86,18);
												thumbnails[4472094] = new thumbnail(4472094,'210755','','_IGP6931web_copy_thumb.jpg',130, 78,18);
												thumbnails[4472095] = new thumbnail(4472095,'210755','','_IGP6949web_copy_thumb.jpg',130, 86,18);
												thumbnails[4472097] = new thumbnail(4472097,'210755','','_IGP6961web_copy_thumb.jpg',130, 86,18);
												thumbnails[4472114] = new thumbnail(4472114,'210755','','_IGP6993web_copy_thumb.jpg',130, 86,18);
												thumbnails[4472116] = new thumbnail(4472116,'210755','','_IGP7037web_copy_thumb.jpg',130, 86,18);
												thumbnails[4472119] = new thumbnail(4472119,'210755','','_IGP7093cweb_copy_thumb.jpg',130, 83,18);
												thumbnails[4472123] = new thumbnail(4472123,'210755','','_IGP7134web_copy_thumb.jpg',130, 86,18);
												thumbnails[4472125] = new thumbnail(4472125,'210755','','_IGP7201web_copy_thumb.jpg',130, 86,18);
												thumbnails[4471620] = new thumbnail(4471620,'260355','','_IGP7388web_thumb.jpg',130, 86,18);
												thumbnails[4471622] = new thumbnail(4471622,'260355','','_IGP7342web_thumb.jpg',86, 130,18);
												thumbnails[4471624] = new thumbnail(4471624,'260355','','_IGP7410web_thumb.jpg',130, 86,18);
												thumbnails[4471625] = new thumbnail(4471625,'260355','','_IGP7439web_thumb.jpg',130, 86,18);
												thumbnails[4471627] = new thumbnail(4471627,'260355','','_IGP7465web_thumb.jpg',130, 86,18);
												thumbnails[4471629] = new thumbnail(4471629,'260355','','_IGP7486web_thumb.jpg',130, 86,18);
												thumbnails[4471630] = new thumbnail(4471630,'260355','','_IGP7493web_thumb.jpg',130, 86,18);
												thumbnails[4471632] = new thumbnail(4471632,'260355','','_IGP7575web_thumb.jpg',130, 86,18);
												thumbnails[4471634] = new thumbnail(4471634,'260355','','_IGP7600web_thumb.jpg',130, 86,18);
												thumbnails[4471635] = new thumbnail(4471635,'260355','','_IGP7796web_thumb.jpg',130, 86,18);
												thumbnails[4471638] = new thumbnail(4471638,'260355','','_IGP7826web_thumb.jpg',130, 86,18);
												thumbnails[4471640] = new thumbnail(4471640,'260355','','_IGP7845web_thumb.jpg',130, 86,18);

/***************************************************************************
* Create the array of Gallery objects                                      *
***************************************************************************/
var galleries = new Object();
				galleries[210754] = new gallery(210754,'2145807,1161284','2008 images','gallery',[1161378,1161382,1163460,3443061,3443120,1161516,3443063,3443074,3443087,2145807,2316713,1161284,1235449,2145811,2316723,3443067,1235479,1235407,1161505,1235464]);
				galleries[260363] = new gallery(260363,'4471661','Brands Hatch Truck Superprix','gallery',[4471643,4471645,4471661,4471664,4471665,4471668,4471669,4471670,4471673]);
				galleries[260362] = new gallery(260362,'4471538','BTTC','gallery',[4471538,4471544,4471548,4471550,4471553,4471555,4471556,4471558,4471560,4471562]);
				galleries[260361] = new gallery(260361,'4471579','A1 Grand Prix','gallery',[4471566,4471567,4471568,4471570,4471571,4471573,4471577,4471579,4471581]);
				galleries[260360] = new gallery(260360,'4471827,4471823,4471820,4471816,4471812,4471811,4471808,4471804,4471803,4471801','Masters Historic Festival','gallery',[4471787,4471789,4471793,4471795,4471797,4471799,4471801,4471803,4471804,4471808,4471811,4471812,4471816,4471820,4471823,4471827]);
				galleries[260359] = new gallery(260359,'4471691','MG Car Club & Euroboss','gallery',[4471680,4471682,4471683,4471687,4471690,4471691]);
				galleries[260358] = new gallery(260358,'4471590','Goodwood Festival of Speed','gallery',[4471586,4471590,4471591,4471594,4471595,4471596,4471599,4471600]);
				galleries[210755] = new gallery(210755,'4472125','Brands Hatch Historic Superprix','gallery',[4472086,4472092,4472094,4472095,4472097,4472114,4472116,4472119,4472123,4472125]);
				galleries[260355] = new gallery(260355,'4471620','WTTC and Formula 2','gallery',[4471620,4471622,4471624,4471625,4471627,4471629,4471630,4471632,4471634,4471635,4471638,4471640]);
/***************************************************************************
* Create the array of image sets                                           *
***************************************************************************/
var imageSets = new Object();
imageSets[1] = '4472125,4472123,4472119,4472116,4472114,4472097,4472095,4472094,4472092,4472086,4471827,4471823,4471820,4471816,4471812,4471811,4471808,4471804,4471803,4471801,4471799,4471797,4471795,4471793,4471789,4471787,4471691,4471690,4471687,4471683,4471682,4471680,4471673,4471670,4471669,4471668,4471665,4471664,4471661,4471645,4471643,4471640,4471638,4471635,4471634,4471632,4471630,4471629,4471627,4471625';
imageSets[2] = '4472125,4471691,4471661,4471620,4471590,4471579,4471538,2145807,1161284';
imageSets[3] = '4472125,4472123,4472119,4472116,4472114,4472097,4472095,4472094,4472092,4472086,4471827,4471823,4471820,4471816,4471812,4471811,4471808,4471804,4471803,4471801,4471799,4471797,4471795,4471793,4471789,4471787,4471691,4471690,4471687,4471683,4471682,4471680,4471673,4471670,4471669,4471668,4471665,4471664,4471661,4471645,4471643,4471640,4471638,4471635,4471634,4471632,4471630,4471629,4471627,4471625';
 /***************************************************************************
* Select a random value from a comma separated list                        *
***************************************************************************/
function randomListVal(list) {
	arrayVals = list.split(',');
	if (arrayVals.length) {
		pos = Math.round(Math.random() * (arrayVals.length - 1));
		val = arrayVals[pos];
				
	}
	else {
		val = 0;
	}
	return val;
}

/***************************************************************************
* Get a server path given an ID                                            *
***************************************************************************/
function getServerPath(server_id) {
	var val = -1;
		switch (server_id) {
		case 34:
		val = 'http://www9.clikpic.com/cliffishy/images';
		break;
	}
		switch (server_id) {
		case 1:
		val = 'http://www1.clikpic.com/cliffishy/images';
		break;
	}
		switch (server_id) {
		case 2:
		val = 'http://admin.clikpic.com/cliffishy/images';
		break;
	}
		switch (server_id) {
		case 4:
		val = 'http://www.clikchurch.com/cliffishy/images';
		break;
	}
		switch (server_id) {
		case 5:
		val = 'http://www2.clikpic.com/cliffishy/images';
		break;
	}
		switch (server_id) {
		case 15:
		val = 'http://www3.clikpic.com/cliffishy/images';
		break;
	}
		switch (server_id) {
		case 21:
		val = 'http://www6.clikpic.com/cliffishy/images';
		break;
	}
		switch (server_id) {
		case 18:
		val = 'http://www4.clikpic.com/cliffishy/images';
		break;
	}
		switch (server_id) {
		case 19:
		val = 'http://www5.clikpic.com/cliffishy/images';
		break;
	}
		switch (server_id) {
		case 22:
		val = 'http://tpc5/clikpic/cliffishy/images';
		break;
	}
		switch (server_id) {
		case 23:
		val = 'http://tpc10/clikpic/cliffishy/images';
		break;
	}
		switch (server_id) {
		case 24:
		val = 'http://tpc15/clikpic/cliffishy/images';
		break;
	}
		switch (server_id) {
		case 25:
		val = 'http://tpc16/clikpic/cliffishy/images';
		break;
	}
		switch (server_id) {
		case 31:
		val = 'http://www7.clikpic.com/cliffishy/images';
		break;
	}
		switch (server_id) {
		case 32:
		val = 'http://admin2.clikpic.com/cliffishy/images';
		break;
	}
		switch (server_id) {
		case 33:
		val = 'http://www8.clikpic.com/cliffishy/images';
		break;
	}
		return val;
}

/***************************************************************************
* img = reference to image object in which to show image                   *
***************************************************************************/
function showHomeImage(img) {

	imageID = randomListVal('');
		if (!basic) {
	img.src = photos[imageID].src;
	img.width = photos[imageID].width;
	img.height = photos[imageID].height;
	}
	else {
		newImage = new Image(photos[imageID].width,photos[imageID].height);
		newImage.src = photos[imageID].src;
		document.images[img.name] = newImage;
				
	}
			}

/***************************************************************************
* Show a random image on home page from featured images                    *
***************************************************************************/
function showHomeImageInline() {
	
	html = '';
	imageID = randomListVal(imageSets[1]);
				if ('gallery' != '') {
						if (backgrounds[imageID].galleries_id != '') {
									html += '<a href="' + backgrounds[imageID].section_code + '_' + backgrounds[imageID].galleries_id + '.html">';
						}
						else {
									html += '<a href="gallery.html">';
						}
			}
						html += '<img src="' + backgrounds[imageID].src + '" width="' + backgrounds[imageID].width + '" height="' + backgrounds[imageID].height + '" class="mainhomepageimage photo" id="mainSample" name="mainSample" alt="' + backgrounds[imageID].caption  + '" border="0">';
			if ('gallery' != '') {
								html += '</a>';
			}
				$('#homepageimage').html(html);
}

/***************************************************************************
* Get the next ID in the array, given the current ID and the array. Can    *
* set boolean argument to get previous ID                                  *
***************************************************************************/
function getNextId(currId,array,previous) {
	var imagePos = getArrayPos(array, currId);
	
		
		if(previous){
		if (imagePos == 0) {
			nextImgPos = array.length -1;
		}
		else {
			nextImgPos = imagePos - 1;
		}
	}
	else{
		if (imagePos == array.length -1) {
			nextImgPos = 0;
		}
		else {
			nextImgPos = imagePos +1;
		}	}
		
	nextImg = array[nextImgPos];
	return nextImg;
}

/***************************************************************************
* 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) {

		
	var imageID = field.value;
		
	var galleryPhotoIDList = galleries[photos[imageID].galleries_id].photoIDs;
		
		nextImg = getNextId(imageID,galleryPhotoIDList);		
	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) {
		
		if (!basic) {
				
		document.getElementById('imagePhoto').innerHTML = '<img class="mainphoto photo" 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;
						$('#imageTitle').html(photos[nextImg].caption);
				
		document.title = 'clip-motorsports.com: ' + photos[nextImg].caption;
					
		if ( photos[nextImg].caption == '') {
			document.getElementById('imageTitle').style.display = 'none';
		}
		else {
			document.getElementById('imageTitle').style.display = 'block';
		}
						var temp = fnGetImageDetails(nextImg);
		if (temp == '') {
			document.getElementById('imageDetails').style.display = 'none';
			var infoWrap = document.getElementById('infoWrap');
			var photoInfo = document.getElementById('photoInfo');
			if (photos[nextImg].caption == '') {
				if (infoWrap != null) infoWrap.className = 'empty';
				if (photoInfo != null) photoInfo.className = 'empty';
			}
			else {
				if (infoWrap != null) infoWrap.className = 'noinfo';
				if (photoInfo != null) photoInfo.className = 'noinfo';
			}
		}
		else {
			document.getElementById('imageDetails').style.display = 'block';
			var infoWrap = document.getElementById('infoWrap');
			if (infoWrap != null) infoWrap.className = 'normal';
			var photoInfo = document.getElementById('photoInfo');
			if (photoInfo != null) photoInfo.className = 'normal';
		}
		document.getElementById('imageDetails').innerHTML = temp;
				resizePhotoInfo();
					toggleAddToCartConfirm();
			}
	else {
				
		window.location = 'photo_' + photos[nextImg].id + '.html';
	}
		
}

/***************************************************************************
* Toggle add to cart confirmation element                                  *
***************************************************************************/
function toggleAddToCartConfirm(){
	if($('#paymentConfirm').size()){
		$('#paymentConfirm').hide();
		$('#paymentAddButton')
		.unbind()
		.click(function(){
						form = document.getElementById('paymentForm');			option_id = 0;			if(form.item_option.value){				option_id = form.item_option.value;			}			if(addItemToBasket(form.item_number.value,photos,form.site.value,parseInt(form.quantity.value, 10),option_id)){
				if($.browser.msie){$('#paymentConfirm').text('Item added to cart').show();}
				else{$('#paymentConfirm').text('Item added to cart').fadeIn();}
			}
			else{
				$('#paymentConfirm').text('Item not added - check cookies are enabled in your browser.').fadeIn();
			}
		});
	}
}
/***************************************************************************
* Get payment info for image                                               *
***************************************************************************/
function fnGetImageDetails(id) {
	var temp = '';
	if (photos[id].description != '') {
		temp = temp +  '<p id="imageDescription">' + photos[id].description + '</p>';
	}
		if (photos[id].photo_ref != '') {
		temp = temp + '<p class="imageinfo" id="imageRef"><strong>Ref: </strong>' + photos[id].photo_ref + '</p>';
	}
		if (photos[id].takendate != '') {
				
		temp = temp + '<p class="imageinfo" id="imageDate"><strong>Date: </strong>' + photos[id].takendate + '</p>';
	}
	
	if (photos[id].location != '') {
				
		temp = temp + '<p class="imageinfo" id="imageLocation"><strong>Location: </strong>' +  photos[id].location + '</p>';
	}
	
	if (photos[id].photographer != '') {
				
		temp = temp + '<p class="imageinfo" id="imagePhotographer"><strong>Photographer: </strong>' + photos[id].photographer + '</p>';
	}
					
				if (temp != '') {
		temp = temp + '<div class="spacer"></div>';
	}
	return temp;
}

/***************************************************************************
* Get payment info for image                                               *
***************************************************************************/
function fnGetPaymentInfo(photo) {
	var temp = '';
	if (photo.item_price !== '') {
				temp = temp + '<p>Order this print:</p>';
				temp = temp + '<p class="imageinfo" id="imagePrice"><strong>' + photo.purchase_instruction + '</strong> 							' + photo.item_price + '</p>';
		var item_name  = photo.purchase_instruction;
		var amount = photo.item_price;
		var item_option  = 0;
	}
	else if (photo.payment_groups_id !== '') {
		temp = temp + '<p>Buy this print online:</p>';
				temp = temp + '<form id="paymentOptions" style="margin:0px;border:0px;" name="paymentOptions">';
											temp = temp + '<select class="paymentlink" name="payment_options_id" onchange="updateItemValues(document.forms.paymentForm,this.form.payment_options_id.options[this.form.payment_options_id.options.selectedIndex].value);">';
				
		temp = temp + getPaymentOptions(photo.payment_groups_id);
		temp = temp + '</select>';
		temp = temp + '</form>';
				var item_option  = paymentGroups[photo.payment_groups_id].options[0];
		if(paymentOptions[item_option]){
			var item_name  = paymentOptions[item_option].payment_option;
			var amount =  paymentOptions[item_option].price;
		}
			}
	else {
				
	}
	if (photo.item_price !== '' || photo.payment_groups_id !== '') {
			temp = temp + '<div class="clearing">&nbsp;</div>';
	}
	return temp;}

/***************************************************************************
* 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) {

		
	var imageID = field.value;
		
	var galleryPhotoIDList = galleries[photos[imageID].galleries_id].photoIDs;
		
		nextImg = getNextId(imageID,galleryPhotoIDList,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) {
		

				imageID = randomListVal(galleries[gallery_id].featured_images);
							
			if (imageID != 0) {
				img.src = thumbnails[imageID].src;
				img.width = thumbnails[imageID].width;
				img.height = thumbnails[imageID].height;
								if(img.width <130){
					var $img = $('img#gallery'+gallery_id);
					$img.parents('.thumbWrap').width(img.width);
					var $h3 = $img.siblings('h3').size() == 1 ? $img.siblings('h3') : $img.parent('.thumbWrap').siblings('h3');
					var padding = parseInt($h3.css('padding-left')) + parseInt($h3.css('padding-right'));
					var border = parseInt($h3.css('border-left-width')) + parseInt($h3.css('border-right-width'));
										$h3.width($img.outerWidth(true) - padding - border);
											}
							}
										}

/***************************************************************************
* If we have dynamic HTML, replace the galleries link with a list that     *
* doesn't include thecurrent gallery                                       *
***************************************************************************/
function showGalleries(gallery_id) {
		
	
	if (!basic) {
		temp = '';
		for (i = 0; i < galleries.length; i++) {
						
			
			if (galleries[i].id != gallery_id) {
								
				if (temp != '') {
					temp = temp + ' | ';
				}
				temp = temp + '<a href="gallery_' + galleries[i].id + '.html">' + galleries[i].title + '</a>';
			}
		}
		document.all.galleryLinks.innerHTML = 'Other galleries: ' + temp;
	}
}

/***************************************************************************
* Resize width and height of photo info panel                              *
***************************************************************************/
function resizePhotoInfo(options) {
	var settings = $.extend({
		centre: false
	},options||{});
		var wrapCalcBugAdjustment = 3;
	$("div#photoPanelOuter").height("auto");
	$("div#infoWrap").width(200);
	$("div#photoDetail").css("width","auto");
	//has the photoInfo panel dropped?
	var pageWidth = $("div#maincolContent").width();
	var photoWidth = $("div#photoWrap").outerWidth(true);
	var infoWidth = $("div#infoWrap").outerWidth(true);
	var photoHeight = $("div#photoWrap").outerHeight();
	var infoHeight = $("div#infoWrap").outerHeight();
	var infoEmpty = $("div#infoWrap").hasClass("empty");
	floatDrop = 0;
		
	var photoDetailWidth = photoWidth;
	if (!infoEmpty) {
		if (pageWidth < (photoWidth + infoWidth)) {floatDrop = 1;}
		if (!floatDrop) {
						var infoInnerWidth = $("div#infoWrap").innerWidth();
			$("div#infoWrap").width(infoInnerWidth + (pageWidth - photoWidth - infoWidth - wrapCalcBugAdjustment));
			infoWidth = $("div#infoWrap").outerWidth(true);
			photoDetailWidth = photoWidth + infoWidth;
						if (photoHeight > infoHeight) {
				var infoInnerHeight = $("div#photoPanelOuter").height();
								$("div#photoPanelOuter").height(infoInnerHeight + (photoHeight - infoHeight));
				
				var infoHeight = $("div#infoWrap").outerHeight();
							}
		}
		else {
						var photoActualWidth = $("div#photoWrap").outerWidth();
			$("div#infoWrap").width(photoActualWidth);
		}
	}
	if (settings.centre) {
		$("div#photoDetail").width(photoDetailWidth);
		$("div#photoDetail").css("margin-left","auto");
		$("div#photoDetail").css("margin-right","auto");
	} 
	else {
		$("div#photoDetail").css("margin-left","0");
		$("div#photoDetail").css("margin-right","0");
	} 
}


/***************************************************************************
* Gets the position in an array of a particular ID                         *
***************************************************************************/

function getArrayPos(array, id){
	for(var i=0; i<array.length; i++){
		if(array[i] == id){
			return i;
		}
	}
	return -1;
}

/***************************************************************************
* Sets the background image of an element to one chosen from an image set. *
***************************************************************************/

function changeBgImg(selector,imageSetId){
	var imageID = randomListVal(imageSets[imageSetId]);
	var imgSrc = backgrounds[imageID].src;
	var $bg = $(selector);
	if($bg.size() > 0){
		if(/\bimg$/.test(selector)){//Used for the stretch background.
			$bg.attr({'src':imgSrc});
		}
		else{
			$bg.css({'background-image':'url("'+imgSrc+'")'});
		}
	}
}
		

