window.thumbnails = {};
															thumbnails[5977258] = clik.newPhoto({"id":5977258,"src":"keswick1_thumb.jpg","galleries_id":"","server_id":1,"link":"#","width":130,"caption":"Derwentwater","height":87});
															thumbnails[4345527] = clik.newPhoto({"id":4345527,"src":"reflections1_thumb.jpg","galleries_id":254435,"server_id":1,"link":"photo_4345527.html","width":130,"caption":"Reflections in Buttermere","height":59});
															thumbnails[4345528] = clik.newPhoto({"id":4345528,"src":"crummock_water1_thumb.jpg","galleries_id":254435,"server_id":1,"link":"photo_4345528.html","width":130,"caption":"Crummock Water, Cumbria","height":87});
															thumbnails[4405775] = clik.newPhoto({"id":4405775,"src":"STR1_thumb.jpg","galleries_id":254435,"server_id":1,"link":"photo_4405775.html","width":130,"caption":"South Tynedale Railway, Alston, Cumbria","height":87});
															thumbnails[4412523] = clik.newPhoto({"id":4412523,"src":"walltown1_thumb.jpg","galleries_id":254435,"server_id":1,"link":"photo_4412523.html","width":130,"caption":"Sunrise near Walltown, Northumberland","height":65});
															thumbnails[4412542] = clik.newPhoto({"id":4412542,"src":"eden1_thumb.jpg","galleries_id":254435,"server_id":1,"link":"photo_4412542.html","width":130,"caption":"Summer in the Eden Valley","height":87});
															thumbnails[4419618] = clik.newPhoto({"id":4419618,"src":"berry1_thumb.jpg","galleries_id":329420,"server_id":1,"link":"photo_4419618.html","width":130,"caption":"hoarfrost on berries","height":87});
															thumbnails[4504607] = clik.newPhoto({"id":4504607,"src":"dawn1_thumb.jpg","galleries_id":254435,"server_id":1,"link":"photo_4504607.html","width":130,"caption":"Dawn on Hadrians Wall. ","height":87});
															thumbnails[4608814] = clik.newPhoto({"id":4608814,"src":"heather1_thumb.jpg","galleries_id":254435,"server_id":1,"link":"photo_4608814.html","width":130,"caption":"Weardale Valley","height":87});
															thumbnails[4732267] = clik.newPhoto({"id":4732267,"src":"steel_rigg_mist1_thumb.jpg","galleries_id":254435,"server_id":1,"link":"photo_4732267.html","width":130,"caption":"Dawn mist at Steel Rigg, Hadrians Wall","height":87});
															thumbnails[5254010] = clik.newPhoto({"id":5254010,"src":"frost1_thumb.jpg","galleries_id":254435,"server_id":1,"link":"photo_5254010.html","width":130,"caption":"First Frost","height":195});
															thumbnails[5254019] = clik.newPhoto({"id":5254019,"src":"poplar_thumb.jpg","galleries_id":254435,"server_id":1,"link":"photo_5254019.html","width":130,"caption":"Misty Woodland","height":195});
															thumbnails[5601870] = clik.newPhoto({"id":5601870,"src":"glendue1_thumb.jpg","galleries_id":254435,"server_id":1,"link":"photo_5601870.html","width":130,"caption":"Glendue, Northumberland","height":190});
															thumbnails[5819983] = clik.newPhoto({"id":5819983,"src":"wanjabw1_thumb.jpg","galleries_id":371283,"server_id":1,"link":"photo_5819983.html","width":130,"caption":"'Wanja' And Lindisfarne Castle","height":193});
															thumbnails[5977265] = clik.newPhoto({"id":5977265,"src":"boats1_thumb.jpg","galleries_id":254435,"server_id":1,"link":"photo_5977265.html","width":130,"caption":"red boats on a misty Windermere","height":172});
															thumbnails[5977267] = clik.newPhoto({"id":5977267,"src":"bowness1_thumb.jpg","galleries_id":254435,"server_id":1,"link":"photo_5977267.html","width":130,"caption":"Bowness on Windermere in the mist","height":174});
															thumbnails[6028006] = clik.newPhoto({"id":6028006,"src":"ashgill1_thumb.jpg","galleries_id":254435,"server_id":1,"link":"photo_6028006.html","width":130,"caption":"Ashgill Falls nr Garrigill, Cumbria","height":195});
															thumbnails[6028014] = clik.newPhoto({"id":6028014,"src":"ashgill2_thumb.jpg","galleries_id":254435,"server_id":1,"link":"photo_6028014.html","width":130,"caption":"Ashgill Falls nr Garrigill, Cumbria   ","height":195});
															thumbnails[6090319] = clik.newPhoto({"id":6090319,"src":"sunset1_thumb.jpg","galleries_id":254435,"server_id":1,"link":"photo_6090319.html","width":130,"caption":"Flaming June","height":87});
															thumbnails[6837056] = clik.newPhoto({"id":6837056,"src":"faweb_thumb.jpg","galleries_id":329420,"server_id":1,"link":"photo_6837056.html","width":130,"caption":"Fly Agaric","height":195});
															thumbnails[6837061] = clik.newPhoto({"id":6837061,"src":"NP1web_thumb.jpg","galleries_id":371283,"server_id":1,"link":"photo_6837061.html","width":130,"caption":"Stormy Seas at Tynemouth Pier","height":195});
															thumbnails[6837063] = clik.newPhoto({"id":6837063,"src":"sunweb_thumb.jpg","galleries_id":254435,"server_id":1,"link":"photo_6837063.html","width":130,"caption":"Northumberland Sunset","height":87});
															thumbnails[6900081] = clik.newPhoto({"id":6900081,"src":"stmarybwweb_thumb.jpg","galleries_id":371283,"server_id":1,"link":"photo_6900081.html","width":130,"caption":"Lighthouse at St Marys Island, Whitley Bay","height":87});
															thumbnails[6907549] = clik.newPhoto({"id":6907549,"src":"sycgapweb_thumb.jpg","galleries_id":254435,"server_id":1,"link":"photo_6907549.html","width":130,"caption":"Sycamore Gap on Hadrians Wall","height":87});
															thumbnails[7763959] = clik.newPhoto({"id":7763959,"src":"beachhut2_thumb.jpg","galleries_id":371283,"server_id":1,"link":"photo_7763959.html","width":130,"caption":"Beach huts at Blyth, Northumberland","height":87});
															thumbnails[7763996] = clik.newPhoto({"id":7763996,"src":"mawbraycolour_thumb.jpg","galleries_id":371283,"server_id":1,"link":"photo_7763996.html","width":130,"caption":"Blue Dawn","height":72});
															thumbnails[7764172] = clik.newPhoto({"id":7764172,"src":"seagulls_thumb.jpg","galleries_id":371283,"server_id":1,"link":"photo_7764172.html","width":130,"caption":"Silloth Seagulls","height":87});
															thumbnails[7764177] = clik.newPhoto({"id":7764177,"src":"gretna_thumb.jpg","galleries_id":371283,"server_id":1,"link":"photo_7764177.html","width":130,"caption":"Boat on the Solway","height":87});
															thumbnails[7876410] = clik.newPhoto({"id":7876410,"src":"mawbraybw_thumb.jpg","galleries_id":371283,"server_id":1,"link":"photo_7876410.html","width":130,"caption":"Mawbray, Solway Coast, Cumbria","height":182});
															thumbnails[7876419] = clik.newPhoto({"id":7876419,"src":"hadg0003w1_thumb.jpg","galleries_id":371283,"server_id":1,"link":"photo_7876419.html","width":130,"caption":"Sandyhills 1, Dumfries & Galloway","height":87});
															thumbnails[7876435] = clik.newPhoto({"id":7876435,"src":"hadg0005w1_thumb.jpg","galleries_id":371283,"server_id":1,"link":"photo_7876435.html","width":130,"caption":"Sandyhills 2, Dumfries & Galloway","height":195});
															thumbnails[7876441] = clik.newPhoto({"id":7876441,"src":"hadg0006w1_thumb.jpg","galleries_id":371283,"server_id":1,"link":"photo_7876441.html","width":130,"caption":"trickles","height":82});
															thumbnails[8121718] = clik.newPhoto({"id":8121718,"src":"POPPIES_thumb.jpg","galleries_id":254435,"server_id":1,"link":"photo_8121718.html","width":130,"caption":"Northumbrian Poppies","height":87});
															thumbnails[8121731] = clik.newPhoto({"id":8121731,"src":"IMG_3298_thumb.jpg","galleries_id":254435,"server_id":1,"link":"photo_8121731.html","width":130,"caption":"Reflections In Kielder","height":155});
															thumbnails[8121739] = clik.newPhoto({"id":8121739,"src":"IMG_3291_thumb.jpg","galleries_id":254435,"server_id":1,"link":"photo_8121739.html","width":130,"caption":"Kielder forest","height":87});
															thumbnails[8573425] = clik.newPhoto({"id":8573425,"src":"IMG_4095_thumb.jpg","galleries_id":371283,"server_id":1,"link":"photo_8573425.html","width":130,"caption":"Drumburgh dawn","height":195});
															thumbnails[8573434] = clik.newPhoto({"id":8573434,"src":"IMG_4108_thumb.jpg","galleries_id":371283,"server_id":1,"link":"photo_8573434.html","width":130,"caption":"Marsh Mono","height":195});
															thumbnails[8573438] = clik.newPhoto({"id":8573438,"src":"IMG_4279_thumb.jpg","galleries_id":254435,"server_id":1,"link":"photo_8573438.html","width":130,"caption":"Low Force, Teesdale","height":88});
															thumbnails[8573440] = clik.newPhoto({"id":8573440,"src":"IMG_4309_thumb.jpg","galleries_id":254435,"server_id":1,"link":"photo_8573440.html","width":130,"caption":"Teesdale cottages","height":87});
															thumbnails[8573441] = clik.newPhoto({"id":8573441,"src":"IMG_4396_thumb.jpg","galleries_id":371283,"server_id":1,"link":"photo_8573441.html","width":130,"caption":"Bamburgh beach","height":195});
															thumbnails[8573442] = clik.newPhoto({"id":8573442,"src":"IMG_4410_thumb.jpg","galleries_id":371283,"server_id":1,"link":"photo_8573442.html","width":130,"caption":"Bamburgh Castle mono","height":87});
															thumbnails[8573444] = clik.newPhoto({"id":8573444,"src":"IMG_4424_thumb.jpg","galleries_id":371283,"server_id":1,"link":"photo_8573444.html","width":130,"caption":"Dune","height":130});
															thumbnails[8573447] = clik.newPhoto({"id":8573447,"src":"Copy_of_hadur0026_thumb.jpg","galleries_id":254435,"server_id":1,"link":"photo_8573447.html","width":130,"caption":"High Force, Teesdale","height":195});
															thumbnails[8573458] = clik.newPhoto({"id":8573458,"src":"IMG_4433_thumb.jpg","galleries_id":371283,"server_id":1,"link":"photo_8573458.html","width":130,"caption":"7pm Spittal Promenade","height":195});
															thumbnails[8578287] = clik.newPhoto({"id":8578287,"src":"hatyne0022s_thumb.jpg","galleries_id":371283,"server_id":1,"link":"photo_8578287.html","width":130,"caption":"Blyth beach Huts","height":87});
															thumbnails[8578435] = clik.newPhoto({"id":8578435,"src":"oldies_001_thumb.jpg","galleries_id":254435,"server_id":1,"link":"photo_8578435.html","width":130,"caption":"Snow Gate","height":195});
															thumbnails[8578442] = clik.newPhoto({"id":8578442,"src":"oldies_021_thumb.jpg","galleries_id":254435,"server_id":1,"link":"photo_8578442.html","width":130,"caption":"Ullswater","height":86});
															thumbnails[8578444] = clik.newPhoto({"id":8578444,"src":"oldies_023_thumb.jpg","galleries_id":254435,"server_id":1,"link":"photo_8578444.html","width":130,"caption":"Where's My Breakfast?","height":87});
															thumbnails[8578447] = clik.newPhoto({"id":8578447,"src":"maryport_thumb.jpg","galleries_id":371283,"server_id":1,"link":"photo_8578447.html","width":130,"caption":"Maryport","height":87});
															thumbnails[8830015] = clik.newPhoto({"id":8830015,"src":"IMG_4778_thumb.jpg","galleries_id":371283,"server_id":1,"link":"photo_8830015.html","width":130,"caption":"Waiting..","height":154});
															thumbnails[8830024] = clik.newPhoto({"id":8830024,"src":"IMG_4786_thumb.jpg","galleries_id":371283,"server_id":1,"link":"photo_8830024.html","width":130,"caption":"Blyth Beach","height":87});
															thumbnails[9097721] = clik.newPhoto({"id":9097721,"src":"IMG_5028_thumb.jpg","galleries_id":254435,"server_id":1,"link":"photo_9097721.html","width":130,"caption":"Morning Walk","height":81});
															thumbnails[9097723] = clik.newPhoto({"id":9097723,"src":"IMG_5146_thumb.jpg","galleries_id":329420,"server_id":1,"link":"photo_9097723.html","width":130,"caption":"Daffodil mono","height":159});
															thumbnails[9097725] = clik.newPhoto({"id":9097725,"src":"IMG_5157_thumb.jpg","galleries_id":329420,"server_id":1,"link":"photo_9097725.html","width":130,"caption":"Daffodil colour","height":87});
															thumbnails[9097728] = clik.newPhoto({"id":9097728,"src":"IMG_5171_thumb.jpg","galleries_id":329420,"server_id":1,"link":"photo_9097728.html","width":130,"caption":"Snowdrop","height":195});

/***************************************************************************
* Create the array of Gallery objects                                      *
***************************************************************************/
var galleries = new Object();
				  						galleries[453256] = clik.newGallery({"parentGallery":"","usePopups":false,"title":"****NEW****","link":"section307424_453256.html","maxRecords":0.0,"photoIDs":[],"skipIndex":0,"section_code":"section307424","featured_images":"","id":453256,"singleSection":false});				  						galleries[371283] = clik.newGallery({"parentGallery":"","usePopups":false,"title":"Coastal Images","link":"section307424_371283.html","maxRecords":0.0,"photoIDs":[5819983.0,6837061.0,6900081.0,7763959.0,7763996.0,7764172.0,7764177.0,7876410.0,7876419.0,7876435.0,7876441.0,8573425.0,8573434.0,8573441.0,8573442.0,8573444.0,8573458.0,8578287.0,8578447.0,8830015.0,8830024.0],"skipIndex":0,"section_code":"section307424","featured_images":8573425.0,"id":371283,"singleSection":false});				  						galleries[254435] = clik.newGallery({"parentGallery":"","usePopups":false,"title":"Landscapes","link":"section307424_254435.html","maxRecords":0.0,"photoIDs":[4345527.0,4345528.0,4405775.0,4412523.0,4412542.0,4504607.0,4608814.0,4732267.0,5254010.0,5254019.0,5601870.0,5977265.0,5977267.0,6028006.0,6028014.0,6090319.0,6837063.0,6907549.0,8121718.0,8121731.0,8121739.0,8573438.0,8573440.0,8573447.0,8578435.0,8578442.0,8578444.0,9097721.0],"skipIndex":0,"section_code":"section307424","featured_images":"9097721,8578444,8578442,8578435,8573447,8573440,8573438,8121739,8121731,8121718","id":254435,"singleSection":false});				  						galleries[329420] = clik.newGallery({"parentGallery":"","usePopups":false,"title":"Images of Nature","link":"section307424_329420.html","maxRecords":0.0,"photoIDs":[4419618.0,6837056.0,9097723.0,9097725.0,9097728.0],"skipIndex":0,"section_code":"section307424","featured_images":"9097728,9097725,9097723,6837056,4419618","id":329420,"singleSection":false});/***************************************************************************
* Create the array of image sets                                           *
***************************************************************************/
var imageSets = {};
imageSets[1] = '8830015';
imageSets[2] = '8573425';
imageSets[3] = '6907549,6837063,6028014,6028006,5977267,5977265,5601870,5254019,5254010,4732267,4608814,4504607,4412542,4412523,4405775,4345528,4345527';
 /***************************************************************************
* Get a server path given an ID                                            *
***************************************************************************/
function getServerPath(server_id) {
	var val = -1;
		switch (server_id) {
		case 51:
		val = 'http://www12.clikpic.com/heatherathey/images';
		break;
	}
		switch (server_id) {
		case 0:
		val = 'http://www.clikpic.com/heatherathey/images';
		break;
	}
		switch (server_id) {
		case 1:
		val = 'http://www1.clikpic.com/heatherathey/images';
		break;
	}
		switch (server_id) {
		case 2:
		val = 'http://admin.clikpic.com/heatherathey/images';
		break;
	}
		switch (server_id) {
		case 24:
		val = 'http://tpc15/clikpic/heatherathey/images';
		break;
	}
		switch (server_id) {
		case 4:
		val = 'http://clikchurch.clikpic.com/heatherathey/images';
		break;
	}
		switch (server_id) {
		case 5:
		val = 'http://www2.clikpic.com/heatherathey/images';
		break;
	}
		switch (server_id) {
		case 22:
		val = 'http://tpc5/clikpic/heatherathey/images';
		break;
	}
		switch (server_id) {
		case 23:
		val = 'http://tpc10/clikpic/heatherathey/images';
		break;
	}
		switch (server_id) {
		case 25:
		val = 'http://tpc16/clikpic/heatherathey/images';
		break;
	}
		switch (server_id) {
		case 26:
		val = 'http://tpc20/clikpic/heatherathey/images';
		break;
	}
		switch (server_id) {
		case 40:
		val = 'http://www11.clikpic.com/heatherathey/images';
		break;
	}
		switch (server_id) {
		case 42:
		val = 'db2.clikpic.com/heatherathey/images';
		break;
	}
		switch (server_id) {
		case 15:
		val = 'http://www3.clikpic.com/heatherathey/images';
		break;
	}
		switch (server_id) {
		case 18:
		val = 'http://www4.clikpic.com/heatherathey/images';
		break;
	}
		switch (server_id) {
		case 19:
		val = 'http://www5.clikpic.com/heatherathey/images';
		break;
	}
		switch (server_id) {
		case 31:
		val = 'http://www7.clikpic.com/heatherathey/images';
		break;
	}
		switch (server_id) {
		case 32:
		val = 'http://www8.clikpic.com/heatherathey/images';
		break;
	}
		switch (server_id) {
		case 34:
		val = 'http://www9.clikpic.com/heatherathey/images';
		break;
	}
		switch (server_id) {
		case 35:
		val = 'http://admin3.clikpic.com/heatherathey/images';
		break;
	}
		switch (server_id) {
		case 37:
		val = 'http://admin4.clikpic.com/heatherathey/images';
		break;
	}
		switch (server_id) {
		case 38:
		val = 'http://admin5.clikpic.com/heatherathey/images';
		break;
	}
		switch (server_id) {
		case 39:
		val = 'http://www10.clikpic.com/heatherathey/images';
		break;
	}
		switch (server_id) {
		case 53:
		val = 'http://images.clikpic.com/heatherathey/images';
		break;
	}
		switch (server_id) {
		case 52:
		val = 'http://tpc22/clikpic/heatherathey/images';
		break;
	}
		switch (server_id) {
		case 21:
		val = 'http://www6.clikpic.com/heatherathey/images';
		break;
	}
		switch (server_id) {
		case 50:
		val = '[cliktext value=article.servers_id type=servers_id]/heatherathey/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;
		img.parentNode.title = img.alt = photos[imageID].caption;
	} else {
		newImage = new Image(photos[imageID].width,photos[imageID].height);
		newImage.src = photos[imageID].src;
		document.images[img.name] = newImage;
		
	}
}

function getHomeImageLink(imageID) {
  	var href='', photo = (backgrounds || photos || {})[imageID];
	if(photo){
		if (photo && photo.galleries_id != '') {
  			href = photo.fnGalleryLink();
  		}
  		  		else {
  				href += 'section307424.html';
  	  		}
	}
    return href;
}

/***************************************************************************
* Show a random image on home page from featured images                    *
***************************************************************************/
function showHomeImageInline(el, image_sets_id, href) {
	
	var css = {}, imageID,
	    imageSetsId = 1;
	if(image_sets_id){
		imageSetsId = image_sets_id;
	}
	imageID = randomListVal(imageSets[imageSetsId]);
	if (href == null && 'section307424' != '') {
					href = getHomeImageLink(imageID);
	}
	
	updateImage({nextPhoto: backgrounds[imageID], img:el.find('img')[0],
                $photo:el, $title:$('#homeimageTitleContainer'), $detail:$('#homeimageDetailsContainer'),                speed:0, href:href, css:css, onAfter: function(){                  this.closest('.contentsection').doManualAlign({				    inner: 'img',				    crop: 'a'				  });                }              });
}

/***************************************************************************
* Set 'img' to be a new image given its photo() object                     *
***************************************************************************/
function updateImage (options) {
	var defaults = {nextPhoto:'',field:'',img:'',$photo:'',$title:'',$detail:'',$detailContainer:'',
                    updateDocumentTitle:false,speed:0,href:false,css:false,updateHash:false,onAfter:null,onBefore:null},
		op = $.extend({},defaults,options),
		html = '', temp = '',
		photoId = op.nextPhoto.id,
		photoCaption = ''+op.nextPhoto.caption,
		photoSrc = op.nextPhoto.src;
	
	if (op.updateHash && clik.getIDInUrl(location.href,'photo') != op.nextPhoto.id) {
		clik.changeHash('photos_id=' + op.nextPhoto.id, true);
	}
		
	    if (op.$title.length > 0) {
  		op.$title.fadeGalleryDetails(photoCaption, op.speed);
    }
        if (op.updateDocumentTitle) {
						  document.title = 'Images by Heather Athey: ' + photoCaption;
			    }
        if (op.$detail.length > 0) {
      	temp = op.nextPhoto.fnGetImageDetails();
	    op.$detail.fadeGalleryDetails(temp, op.speed, function(){
			if (typeof(backgrounds) != 'undefined' && op.nextPhoto == backgrounds[op.nextPhoto.id]) {
				toggleAddToCartConfirm(backgrounds, op.$detail);
			} else if (typeof(photos) != 'undefined' && op.nextPhoto == photos[op.nextPhoto.id]) {
				toggleAddToCartConfirm(photos, op.$detail);
			}
			$('body').trigger('clikUpdate.popup');
	    });
    }
        $(op.$detailContainer).find('.replaceable[class*=replaceable_photo-]').each(function(){
    	var field = clik.getPrefixedClass(this.className, 'replaceable_photo-');
    	if (field in op.nextPhoto) {
    		$(this).fadeGalleryDetails(op.nextPhoto[field], op.speed);
    	}
    }).end().find('.replaceable.photoPayment').fadeGalleryDetails(op.nextPhoto.fnGetPaymentInfo(), op.speed, function(){
		if (typeof(backgrounds) != 'undefined' && op.nextPhoto == backgrounds[op.nextPhoto.id]) {
			toggleAddToCartConfirm(backgrounds, op.$detailContainer);
		} else if (typeof(photos) != 'undefined' && op.nextPhoto == photos[op.nextPhoto.id]) {
			toggleAddToCartConfirm(photos, op.$detailContainer);
		}
		$('body').trigger('clikUpdate.popup');
	});
		if (op.$photo.length > 0) {
		html = $('<img/>',{
			'class': 'mainphoto photo',
			src: photoSrc,
			id: 'mainPic',
			name: 'mainPic',
			width: op.nextPhoto.width,
			height: op.nextPhoto.height,
			alt: photoCaption,
			css: op.css || {}
		});
		if (op.href) {
			if (op.href.match(/<a/)) {
				html = $(op.href).append(html);
			} else {
				html = $('<a/>', {
					href: op.href,
					title: photoCaption
				}).append(html);
			}
		} else {
			html = $('<a/>', {
				title: photoCaption
			}).append(html);
		}
		if (op.speed == 0) {			op.$photo.html(html);			if (op.onBefore) {			  	op.onBefore.apply(op.$photo);			}			if (op.onAfter) {			  	op.onAfter.apply(op.$photo);			}		} else {			op.$photo.stop(true,true).fadeReplaceWith(html,op.speed,'',function(){  				if (op.onAfter) {				  	op.onAfter.apply(this);				}				clik.doColumnResize(false, $(this).add(op.$detail).add(op.$title));			}, op.onBefore);
		}	}
    if (op.field) {
		op.field.value = photoId;
	} else {
		op.$photo.data('image_id', photoId);
    }
        if (!op.speed) {
      	clik.doColumnResize(false, op.$photo.add(op.$detail).add(op.$title));
    }
        
    return html;
	}

/***************************************************************************
* Toggle add to cart confirmation element and set up the click event for   *
* the 'Add to cart' button.                                                *
***************************************************************************/
function toggleAddToCartConfirm(array, root){
	if (typeof(array) !== 'object' || array === null) {
	  	array = photos;
	}
	if (!$(root).length) {		root = $('body');	}	if($('#paymentConfirm', root).length > 0){
		$('#paymentConfirm', root).hide();
		$('#paymentAddButton', root)
		.unbind()
		.click(function(){
						form = $('#paymentForm', root)[0];
			option_id = 0;
			if(form.item_option.value){
				option_id = form.item_option.value;
			}
			if(addItemToBasket(form.item_number.value,array,form.site.value,parseInt(form.quantity.value, 10),option_id)){
				if($.browser.msie){$('#paymentConfirm', root).text('Item added to cart').show();}
				else{
					$('#paymentConfirm', root).text('Item added to cart').fadeIn();
					dspOrderDetails(form.site.value);
				}
			}
			else{
				$('#paymentConfirm', root).text('Item not added - check cookies are enabled in your browser.').fadeIn();
			}
		});
	}
}

/***************************************************************************
* Get payment info for image - add as 'method' to photo object             *
***************************************************************************/
clik.photo.fnGetImageDetails = function(){
	var temp = '';
	if (this.description != '') {
		temp +=  '<div id="imageDescription">' + this.description + '</div>';
	}
		if (this.photo_ref != '') {
		temp += '<div class="imageinfo" id="imageRef"><strong>Ref: </strong>' + this.photo_ref + '</div>';
	}
		if (this.takendate != '') {
		
		temp += '<div class="imageinfo" id="imageDate"><strong>Date: </strong>' + this.takendate + '</div>';
	}
	
	if (this.location != '') {
		
		temp += '<div class="imageinfo" id="imageLocation"><strong>Location: </strong>' +  this.location + '</div>';
	}
	
	if (this.photographer != '') {
		
		temp += '<div class="imageinfo" id="imagePhotographer"><strong>Photographer: </strong>' + this.photographer + '</div>';
	}
				
	temp += this.fnGetPaymentInfo();
				if (temp != '') {
		temp += '<div class="spacer"></div>';
	}
	return temp;
};

/***************************************************************************
* Get payment info for image - add as 'method' to photo object             *
***************************************************************************/
clik.photo.fnGetPaymentInfo = function(){
	var temp = '';
	if (this.item_price !== '') {
																		temp += '<p>Buy now using PayPal:</p>';
				temp += '<div class="imageinfo" id="imagePrice"><strong>' + this.purchase_instruction + '</strong> &pound;' + (this.item_price).toFixed(2) + '</div>';
		var item_name  = this.purchase_instruction;
		var amount = (this.item_price).toFixed(2);
		var item_option  = 0;
	}
		else if (this.payment_groups_id !== '') {
		temp += '<p>Buy this print online:</p>';
				temp += '<form id="paymentOptions" style="margin:0px;border:0px;" name="paymentOptions">';
											temp += '<select class="paymentlink" name="payment_options_id" onchange="updateItemValues($(this.form).next(\'#paymentForm\')[0],this.form.payment_options_id.options[this.form.payment_options_id.options.selectedIndex].value);">';
		
		temp += getPaymentOptions(this.payment_groups_id);
		temp += '</select>';
		temp += '</form>';
				var item_option  = paymentGroups[this.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 (this.item_price !== '' || this.payment_groups_id !== '') {
																		temp += '<form id="paymentForm" style="margin:0px;border:0px;" name="paymentForm" target="_blank" action="https://www.paypal.com/cgi-bin/webscr" method="post">';
			temp += '<input type="hidden" name="item_name" value="'+item_name+'">';
			ref = '';
			if(this.photo_ref != ''){
				ref = this.photo_ref+' - '+this.caption;
			}
			else{
				ref = this.id+' - '+this.caption;
			}
			price = amount;								temp += '<input type="hidden" name="cmd" value="_cart">';
					temp += '<input type="hidden" name="business" value="hatheyphotos@gmail.com">';
					temp += '<input type="hidden" name="currency_code" value="GBP">';
					temp += '<input type="hidden" name="add" value="1">';
													temp += '<input type="hidden" name="amount" value="'+amount+'">';
					temp += '<input type="hidden" name="item_number" value="'+ref+'">';
													temp += '<input type=\"Submit\" value=\"Add to cart\" id=\"paymentAddButton\" class=\"button\" onmouseover=\"this.className=\'buttonHi\';\" onmouseout=\"this.className=\'button\';\">';
										temp += '</form>';
										temp += '<form id="paymentCartForm" style="margin:0px;" name="paymentCartForm" target="_blank" action="https://www.paypal.com/cgi-bin/webscr" method="post">';
				temp += '<input type="hidden" name="cmd" value="_cart">';
				temp += '<input type="hidden" name="business" value="hatheyphotos@gmail.com">';
				temp += '<input type="hidden" name="display" value="1">';
				temp += '<input type=\"Submit\" value=\"View cart\" id=\"paymentViewButton\" class=\"button\" onmouseover=\"this.className=\'buttonHi\';\" onmouseout=\"this.className=\'button\';\">';
				temp += '</form>';
						temp += '<div class="clearing">&nbsp;</div>';
	}
	return temp;};

/***************************************************************************
* 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, updateLink) {
	
	if(img){
		if (location.hash.match('galleries_id=' + gallery_id) && (imageID = location.hash.match('.*photos_id=(.+)$'))) {
		  	imageID = imageID[1];
		} else {
		  	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;
			img.alt = galleries[gallery_id].title;
			if (updateLink) {
				$(img).parent().attr({					title: galleries[gallery_id].title				}).filter(function(){return this.href;}).attr({					href: thumbnails[imageID].fnGalleryLink(gallery_id)				});
			}
		}
	}
}

/***************************************************************************
* 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 += '<a href="' + galleries[i].section_code + '_' + galleries[i].id + '.html">' + galleries[i].title + '</a>';
							}
		}
		document.all.galleryLinks.innerHTML = 'Other galleries: ' + temp;
	}
}

			

