window.thumbnails = {};
															thumbnails[3559356] = clik.newPhoto({"id":3559356,"src":"Trio_-_Pas_de_Calais_thumb.jpg","galleries_id":204841,"server_id":15,"link":"photo_3559356.html","width":130,"caption":"Trio, Pas de Calais","height":87});
															thumbnails[3583588] = clik.newPhoto({"id":3583588,"src":"Schiehallion__Dunalastair_Water_copy_thumb.jpg","galleries_id":204853,"server_id":15,"link":"photo_3583588.html","width":130,"caption":"Schiehallion & Dunalastair Water","height":130});
															thumbnails[3583625] = clik.newPhoto({"id":3583625,"src":"On_Rannoch_Moor_copy_thumb.jpg","galleries_id":204853,"server_id":15,"link":"photo_3583625.html","width":130,"caption":"Island Tree, Lochan na H'achlaise","height":87});
															thumbnails[3583632] = clik.newPhoto({"id":3583632,"src":"Black_Rock_Cottage_and_Buachaille_Etive_Mor_copy_thumb.jpg","galleries_id":204853,"server_id":15,"link":"photo_3583632.html","width":130,"caption":"Black Rock Cottage & Buachaille Etive Mor","height":87});
															thumbnails[3677051] = clik.newPhoto({"id":3677051,"src":"Moorland_Ruin_thumb.jpg","galleries_id":204291,"server_id":15,"link":"photo_3677051.html","width":130,"caption":"Moorland Ruin","height":87});
															thumbnails[5251502] = clik.newPhoto({"id":5251502,"src":"Drying_the_Nets_Aldeburgh_thumb.jpg","galleries_id":204679,"server_id":15,"link":"photo_5251502.html","width":85,"caption":"Drying the Nets, Aldeburgh","height":130});
															thumbnails[5251505] = clik.newPhoto({"id":5251505,"src":"Fence_Grasses_and_Beach_Huts_Southwold_thumb.jpg","galleries_id":204679,"server_id":15,"link":"photo_5251505.html","width":130,"caption":"Fence, Grass & Beach Huts, Southwold","height":87});
															thumbnails[5251508] = clik.newPhoto({"id":5251508,"src":"Fishermen_Dunwich_4_thumb.jpg","galleries_id":204679,"server_id":15,"link":"photo_5251508.html","width":130,"caption":"Fishermen at Dunwich","height":86});
															thumbnails[5497601] = clik.newPhoto({"id":5497601,"src":"Swanage_Beach_Jetty_thumb.jpg","galleries_id":204679,"server_id":15,"link":"photo_5497601.html","width":130,"caption":"Swanage Promenade","height":87});
															thumbnails[5497607] = clik.newPhoto({"id":5497607,"src":"Swanage_Beach_Jetty_mono_thumb.jpg","galleries_id":204679,"server_id":15,"link":"photo_5497607.html","width":130,"caption":"Swanage Promenade","height":87});
															thumbnails[5497623] = clik.newPhoto({"id":5497623,"src":"The_Groyne_Swanage_thumb.jpg","galleries_id":204679,"server_id":15,"link":"photo_5497623.html","width":130,"caption":"The Groyne, Swanage","height":65});
															thumbnails[6440327] = clik.newPhoto({"id":6440327,"src":"Winchester_Cathedral_Lady_Chapel_copy_thumb.jpg","galleries_id":355458,"server_id":15,"link":"photo_6440327.html","width":130,"caption":"The Lady Chapel, Winchester Cathedral","height":87});
															thumbnails[7807188] = clik.newPhoto({"id":7807188,"src":"A_Wensleydale_Flock_thumb.jpg","galleries_id":204291,"server_id":15,"link":"photo_7807188.html","width":130,"caption":"Sheep Grazing in Wensleydale","height":87});
															thumbnails[7811296] = clik.newPhoto({"id":7811296,"src":"Across_Wensleydale_thumb.jpg","galleries_id":204291,"server_id":15,"link":"photo_7811296.html","width":130,"caption":"Across Wensleydale","height":57});
															thumbnails[7811324] = clik.newPhoto({"id":7811324,"src":"Cotterdale_3_thumb.jpg","galleries_id":204291,"server_id":15,"link":"photo_7811324.html","width":130,"caption":"Cotterdale","height":69});
															thumbnails[7811329] = clik.newPhoto({"id":7811329,"src":"Cotterdale_Beck_ver_2_thumb.jpg","galleries_id":204291,"server_id":15,"link":"photo_7811329.html","width":130,"caption":"Cotterdale Beck","height":87});
															thumbnails[7811335] = clik.newPhoto({"id":7811335,"src":"Dawn_Wensleydale_thumb.jpg","galleries_id":204291,"server_id":15,"link":"photo_7811335.html","width":130,"caption":"Dawn, Wensleydale","height":73});
															thumbnails[7811344] = clik.newPhoto({"id":7811344,"src":"Distant_Barn_thumb.jpg","galleries_id":204291,"server_id":15,"link":"photo_7811344.html","width":130,"caption":"A Distant Barn","height":68});
															thumbnails[7811355] = clik.newPhoto({"id":7811355,"src":"End_day_1_thumb.jpg","galleries_id":204291,"server_id":15,"link":"photo_7811355.html","width":82,"caption":"End of the Day, Swaledale","height":130});
															thumbnails[7811478] = clik.newPhoto({"id":7811478,"src":"Early_Morning_Wensleydale1_thumb.jpg","galleries_id":204291,"server_id":15,"link":"photo_7811478.html","width":130,"caption":"First Light, Wensleydale","height":87});
															thumbnails[7811485] = clik.newPhoto({"id":7811485,"src":"First_Light_thumb.jpg","galleries_id":204291,"server_id":15,"link":"photo_7811485.html","width":130,"caption":"First Light near Garsdale","height":53});
															thumbnails[7811496] = clik.newPhoto({"id":7811496,"src":"Flooded_Field_in_Swaledale_thumb.jpg","galleries_id":204291,"server_id":15,"link":"photo_7811496.html","width":130,"caption":"A Flooded Field in Swaledale","height":85});
															thumbnails[7811506] = clik.newPhoto({"id":7811506,"src":"Lychgate_Roof_Chapel-le-Dale_thumb.jpg","galleries_id":204291,"server_id":15,"link":"photo_7811506.html","width":130,"caption":"Lych Gate Roof, Chapel le Dale","height":87});
															thumbnails[7811514] = clik.newPhoto({"id":7811514,"src":"Mists_in_Wensleydale_thumb.jpg","galleries_id":204291,"server_id":15,"link":"photo_7811514.html","width":130,"caption":"Morning Mist in Wensleydale","height":61});
															thumbnails[7811528] = clik.newPhoto({"id":7811528,"src":"Near_Tan_Hill_3_copy_thumb.jpg","galleries_id":204291,"server_id":15,"link":"photo_7811528.html","width":130,"caption":"Field Barn and Cart Track near Tan Hill","height":87});
															thumbnails[7811535] = clik.newPhoto({"id":7811535,"src":"Near_Hardraw_thumb.jpg","galleries_id":204291,"server_id":15,"link":"photo_7811535.html","width":130,"caption":"Near Hardraw","height":70});
															thumbnails[7811643] = clik.newPhoto({"id":7811643,"src":"Near_Horton_3_thumb.jpg","galleries_id":204291,"server_id":15,"link":"photo_7811643.html","width":130,"caption":"Towards Pen y Ghent","height":76});
															thumbnails[7811757] = clik.newPhoto({"id":7811757,"src":"Near_Tan_Hill_thumb.jpg","galleries_id":204291,"server_id":15,"link":"photo_7811757.html","width":130,"caption":"Near Tan Hill","height":87});
															thumbnails[7811806] = clik.newPhoto({"id":7811806,"src":"Near_Thwaite_2_thumb.jpg","galleries_id":204291,"server_id":15,"link":"photo_7811806.html","width":87,"caption":"Near Thwaite in Swaledale","height":130});
															thumbnails[7811847] = clik.newPhoto({"id":7811847,"src":"Pen-y-Ghent_thumb.jpg","galleries_id":204291,"server_id":15,"link":"photo_7811847.html","width":130,"caption":"Pen y Ghent","height":87});
															thumbnails[7811850] = clik.newPhoto({"id":7811850,"src":"Plantation_near_Hawea_thumb.jpg","galleries_id":204291,"server_id":15,"link":"photo_7811850.html","width":130,"caption":"Forestry Plantation near Garsdale","height":87});
															thumbnails[7811854] = clik.newPhoto({"id":7811854,"src":"Reflection_in_a_Flood_thumb.jpg","galleries_id":204291,"server_id":15,"link":"photo_7811854.html","width":83,"caption":"Barn Reflection in a Flood, Swaledale","height":130});
															thumbnails[7811863] = clik.newPhoto({"id":7811863,"src":"Sunrise_over_Wensleydale_thumb.jpg","galleries_id":204291,"server_id":15,"link":"photo_7811863.html","width":130,"caption":"Daybreak, Upper Wensleydale","height":69});
															thumbnails[7811866] = clik.newPhoto({"id":7811866,"src":"Swaledale_from_Buttertubs_2_sMOOTH_sEPIA_RE_kI_thumb.jpg","galleries_id":204291,"server_id":15,"link":"photo_7811866.html","width":130,"caption":"Swaledale from Buttertubs","height":53});
															thumbnails[7811871] = clik.newPhoto({"id":7811871,"src":"Swaledale_from_Buttertubs_2_thumb.jpg","galleries_id":204291,"server_id":15,"link":"photo_7811871.html","width":130,"caption":"Swaledale from Buttertubs","height":53});
															thumbnails[7811875] = clik.newPhoto({"id":7811875,"src":"Towards_Keld_2_thumb.jpg","galleries_id":204291,"server_id":15,"link":"photo_7811875.html","width":130,"caption":"Near Thwaite in Swaledale","height":89});
															thumbnails[7811880] = clik.newPhoto({"id":7811880,"src":"Treeline_thumb.jpg","galleries_id":204291,"server_id":15,"link":"photo_7811880.html","width":130,"caption":"Tree Line","height":87});
															thumbnails[7897978] = clik.newPhoto({"id":7897978,"src":"The_Sapling1_thumb.jpg","galleries_id":204841,"server_id":15,"link":"photo_7897978.html","width":87,"caption":"The Sapling","height":130});
															thumbnails[7897980] = clik.newPhoto({"id":7897980,"src":"Stone_Pillar_Bury_St_Eds_Cath_thumb.jpg","galleries_id":355458,"server_id":15,"link":"photo_7897980.html","width":87,"caption":"Stone Column Detail, Bury St Edmunds Cathedral","height":130});
															thumbnails[8920055] = clik.newPhoto({"id":8920055,"src":"SwanageBay2_thumb.jpg","galleries_id":204679,"server_id":15,"link":"photo_8920055.html","width":130,"caption":"Swanage Bay","height":130});
															thumbnails[8920353] = clik.newPhoto({"id":8920353,"src":"WestPier_thumb.jpg","galleries_id":204679,"server_id":15,"link":"photo_8920353.html","width":130,"caption":"Brighton's West Pier","height":79});
															thumbnails[8924245] = clik.newPhoto({"id":8924245,"src":"WorthingPier_thumb.jpg","galleries_id":204679,"server_id":15,"link":"photo_8924245.html","width":130,"caption":"Worthing Pier and Beach at Sunset","height":66});
															thumbnails[8929374] = clik.newPhoto({"id":8929374,"src":"SevenSisters2_thumb.jpg","galleries_id":204679,"server_id":15,"link":"photo_8929374.html","width":130,"caption":"The Seven Sisters","height":87});
															thumbnails[3462852] = clik.newPhoto({"id":3462852,"src":"clevedon pier1_thumb.jpg","galleries_id":204679,"server_id":15,"link":"photo_3462852.html","width":130,"caption":"Clevedon Pier","height":130});
															thumbnails[3355970] = clik.newPhoto({"id":3355970,"src":"Black Mount panorama copy_thumb.jpg","galleries_id":204853,"server_id":15,"link":"photo_3355970.html","width":130,"caption":"The Black Mount from Rannoch Moor","height":50});
															thumbnails[3355977] = clik.newPhoto({"id":3355977,"src":"Black Rock Cottage copy_thumb.jpg","galleries_id":204853,"server_id":15,"link":"photo_3355977.html","width":130,"caption":"Black Rock Cottage & Buachaille Etive Mor","height":87});
															thumbnails[3358875] = clik.newPhoto({"id":3358875,"src":"cranhamroots_RT16 copy_thumb.jpg","galleries_id":204841,"server_id":15,"link":"photo_3358875.html","width":130,"caption":"Beech Tree at Cranham","height":87});
															thumbnails[3358902] = clik.newPhoto({"id":3358902,"src":"malvern hills 2 bw copy_thumb.jpg","galleries_id":205033,"server_id":15,"link":"photo_3358902.html","width":130,"caption":"On the Malvern Hills","height":87});
															thumbnails[3351066] = clik.newPhoto({"id":3351066,"src":"Pen-y-Ghent 10_thumb.jpg","galleries_id":204291,"server_id":15,"link":"photo_3351066.html","width":130,"caption":"Pen y Ghent","height":87});
															thumbnails[3355982] = clik.newPhoto({"id":3355982,"src":"Buachille Etive Mor bw copy_thumb.jpg","galleries_id":204853,"server_id":15,"link":"photo_3355982.html","width":130,"caption":"The River Coupall & Buachaille Etive Mor","height":87});
															thumbnails[3348348] = clik.newPhoto({"id":3348348,"src":"Limestone & viaduct_thumb.jpg","galleries_id":204291,"server_id":15,"link":"photo_3348348.html","width":130,"caption":"Ribblehead Viaduct","height":87});
															thumbnails[3351083] = clik.newPhoto({"id":3351083,"src":"wensleydale_thumb.jpg","galleries_id":204291,"server_id":15,"link":"photo_3351083.html","width":130,"caption":"Wensleydale","height":70});
															thumbnails[3351075] = clik.newPhoto({"id":3351075,"src":"Swaledaledale from Buttertubs copy_thumb.jpg","galleries_id":204291,"server_id":15,"link":"photo_3351075.html","width":130,"caption":"Swaledale from Buttertubs Pass","height":87});
															thumbnails[3351107] = clik.newPhoto({"id":3351107,"src":"swaledale_thumb.jpg","galleries_id":204291,"server_id":15,"link":"photo_3351107.html","width":130,"caption":"Field Barn near Thwaite","height":87});
															thumbnails[3351073] = clik.newPhoto({"id":3351073,"src":"Swaledale Snowstorm_thumb.jpg","galleries_id":204291,"server_id":15,"link":"photo_3351073.html","width":130,"caption":"Swaledale Snowstorm","height":87});
															thumbnails[3351069] = clik.newPhoto({"id":3351069,"src":"swaledale 4_2_thumb.jpg","galleries_id":204291,"server_id":15,"link":"photo_3351069.html","width":130,"caption":"Swaledale","height":81});
															thumbnails[3351071] = clik.newPhoto({"id":3351071,"src":"Swaledale Barns and walls_thumb.jpg","galleries_id":204291,"server_id":15,"link":"photo_3351071.html","width":130,"caption":"Drystone Walls & Barns","height":87});
															thumbnails[3348578] = clik.newPhoto({"id":3348578,"src":"21 - Muker Barn Doors3_thumb.jpg","galleries_id":204291,"server_id":15,"link":"photo_3348578.html","width":87,"caption":"Barn Doors in Muker","height":130});
															thumbnails[3348355] = clik.newPhoto({"id":3348355,"src":"Dent Head 2_thumb.jpg","galleries_id":204291,"server_id":15,"link":"photo_3348355.html","width":130,"caption":"Dent Head Viaduct","height":87});
															thumbnails[3348361] = clik.newPhoto({"id":3348361,"src":"Dent 1_thumb.jpg","galleries_id":204291,"server_id":15,"link":"photo_3348361.html","width":130,"caption":"The Sun Inn, Dent","height":87});

/***************************************************************************
* Create the array of Gallery objects                                      *
***************************************************************************/
var galleries = new Object();
				  						galleries[205033] = clik.newGallery({"parentGallery":"","usePopups":false,"title":"Landscapes","link":"gallery_205033.html","maxRecords":0.0,"photoIDs":[3358902.0],"skipIndex":0,"section_code":"gallery","featured_images":3358902.0,"id":205033,"singleSection":false});				  						galleries[204291] = clik.newGallery({"parentGallery":"","usePopups":false,"title":"Images of Yorkshire","link":"gallery_204291.html","maxRecords":0.0,"photoIDs":[3677051.0,7807188.0,7811296.0,7811324.0,7811329.0,7811335.0,7811344.0,7811355.0,7811478.0,7811485.0,7811496.0,7811506.0,7811514.0,7811528.0,7811535.0,7811643.0,7811757.0,7811806.0,7811847.0,7811850.0,7811854.0,7811863.0,7811866.0,7811871.0,7811875.0,7811880.0,3351066.0,3348348.0,3351083.0,3351075.0,3351107.0,3351073.0,3351069.0,3351071.0,3348578.0,3348355.0,3348361.0],"skipIndex":0,"section_code":"gallery","featured_images":"7811880,7811875,7811871,7811866,7811863,7811854,7811850,7811847,7811757,7811643,7811535,7811528,7811514,7811506,7811496,7811485,7811478,7811355,7811344,7811335,7811329,7811324,7811296,7807188,3677051,3351083","id":204291,"singleSection":false});				  						galleries[204853] = clik.newGallery({"parentGallery":"","usePopups":false,"title":"Scotland","link":"gallery_204853.html","maxRecords":0.0,"photoIDs":[3583588.0,3583625.0,3583632.0,3355970.0,3355977.0,3355982.0],"skipIndex":0,"section_code":"gallery","featured_images":"3355982,3355977","id":204853,"singleSection":false});				  						galleries[204841] = clik.newGallery({"parentGallery":"","usePopups":false,"title":"Trees","link":"gallery_204841.html","maxRecords":0.0,"photoIDs":[3559356.0,7897978.0,3358875.0],"skipIndex":0,"section_code":"gallery","featured_images":7897978.0,"id":204841,"singleSection":false});				  						galleries[204679] = clik.newGallery({"parentGallery":"","usePopups":false,"title":"By the Sea","link":"gallery_204679.html","maxRecords":0.0,"photoIDs":[5251502.0,5251505.0,5251508.0,5497601.0,5497607.0,5497623.0,8920055.0,8920353.0,8924245.0,8929374.0,3462852.0],"skipIndex":0,"section_code":"gallery","featured_images":"8929374,8924245","id":204679,"singleSection":false});				  						galleries[355458] = clik.newGallery({"parentGallery":"","usePopups":false,"title":"Churches & Graveyards","link":"gallery_355458.html","maxRecords":0.0,"photoIDs":[6440327.0,7897980.0],"skipIndex":0,"section_code":"gallery","featured_images":7897980.0,"id":355458,"singleSection":false});/***************************************************************************
* Create the array of image sets                                           *
***************************************************************************/
var imageSets = {};
imageSets[1] = '8929374,8924245,7897980,7897978,7811880,7811875,7811871,7811866,7811863,7811854,7811850,7811847,7811757,7811643,7811535,7811528,7811514,7811506,7811496,7811485,7811478,7811355,7811344,7811335,7811329,7811324,7807188,3677051,3583632,3583625,3462852,3355970,3358875,3355982,3351083,3351107,3351073,3351069,3348578';
imageSets[2] = '8929374,8924245,7897980,7897978,7811880,7811875,7811871,7811866,7811863,7811854,7811850,7811847,7811757,7811643,7811535,7811528,7811514,7811506,7811496,7811485,7811478,7811355,7811344,7811335,7811329,7811324,7811296,7807188,3677051,3355977,3355982,3351083';
imageSets[3] = '7811296';
 /***************************************************************************
* Get a server path given an ID                                            *
***************************************************************************/
function getServerPath(server_id) {
	var val = -1;
		switch (server_id) {
		case 51:
		val = 'http://www12.clikpic.com/rogerdtapp/images';
		break;
	}
		switch (server_id) {
		case 0:
		val = 'http://www.clikpic.com/rogerdtapp/images';
		break;
	}
		switch (server_id) {
		case 1:
		val = 'http://www1.clikpic.com/rogerdtapp/images';
		break;
	}
		switch (server_id) {
		case 2:
		val = 'http://admin.clikpic.com/rogerdtapp/images';
		break;
	}
		switch (server_id) {
		case 24:
		val = 'http://tpc15/clikpic/rogerdtapp/images';
		break;
	}
		switch (server_id) {
		case 4:
		val = 'http://clikchurch.clikpic.com/rogerdtapp/images';
		break;
	}
		switch (server_id) {
		case 5:
		val = 'http://www2.clikpic.com/rogerdtapp/images';
		break;
	}
		switch (server_id) {
		case 22:
		val = 'http://tpc5/clikpic/rogerdtapp/images';
		break;
	}
		switch (server_id) {
		case 23:
		val = 'http://tpc10/clikpic/rogerdtapp/images';
		break;
	}
		switch (server_id) {
		case 25:
		val = 'http://tpc16/clikpic/rogerdtapp/images';
		break;
	}
		switch (server_id) {
		case 26:
		val = 'http://tpc20/clikpic/rogerdtapp/images';
		break;
	}
		switch (server_id) {
		case 40:
		val = 'http://www11.clikpic.com/rogerdtapp/images';
		break;
	}
		switch (server_id) {
		case 42:
		val = 'db2.clikpic.com/rogerdtapp/images';
		break;
	}
		switch (server_id) {
		case 15:
		val = 'http://www3.clikpic.com/rogerdtapp/images';
		break;
	}
		switch (server_id) {
		case 18:
		val = 'http://www4.clikpic.com/rogerdtapp/images';
		break;
	}
		switch (server_id) {
		case 19:
		val = 'http://www5.clikpic.com/rogerdtapp/images';
		break;
	}
		switch (server_id) {
		case 31:
		val = 'http://www7.clikpic.com/rogerdtapp/images';
		break;
	}
		switch (server_id) {
		case 32:
		val = 'http://www8.clikpic.com/rogerdtapp/images';
		break;
	}
		switch (server_id) {
		case 34:
		val = 'http://www9.clikpic.com/rogerdtapp/images';
		break;
	}
		switch (server_id) {
		case 35:
		val = 'http://admin3.clikpic.com/rogerdtapp/images';
		break;
	}
		switch (server_id) {
		case 37:
		val = 'http://admin4.clikpic.com/rogerdtapp/images';
		break;
	}
		switch (server_id) {
		case 38:
		val = 'http://admin5.clikpic.com/rogerdtapp/images';
		break;
	}
		switch (server_id) {
		case 39:
		val = 'http://www10.clikpic.com/rogerdtapp/images';
		break;
	}
		switch (server_id) {
		case 53:
		val = 'http://images.clikpic.com/rogerdtapp/images';
		break;
	}
		switch (server_id) {
		case 52:
		val = 'http://tpc22/clikpic/rogerdtapp/images';
		break;
	}
		switch (server_id) {
		case 21:
		val = 'http://www6.clikpic.com/rogerdtapp/images';
		break;
	}
		switch (server_id) {
		case 50:
		val = '[cliktext value=article.servers_id type=servers_id]/rogerdtapp/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 += 'gallery.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 && 'gallery' != '') {
					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 = 'Roger Tapp Photography: ' + 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="updateCartValue($(this.form).next(\'#paymentForm\')[0],this.form.payment_options_id.options[this.form.payment_options_id.options.selectedIndex].value); if(divShowing(\'paymentConfirm\')){fadeOut(\'paymentConfirm\', 3)};">';
		
		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">';
			temp += '	<input type="hidden" name="item_option" value="' + item_option + '">';
			temp += '	<input type="hidden" name="site" value="ROGERDTAPP">';
			temp += '	<input type="hidden" name="item_number" value="'+ this.id +'">';
			temp += '	<input type="hidden" name="quantity" value="1">';
						temp += '	<input value="Add to cart" id="paymentAddButton" class="button" onmouseover="this.className=\'buttonHi\'\;" onmouseout="this.className=\'button\'\;" type="Button">';
							temp += '	<input value="View cart" id="paymentViewButton" class="button" onmouseover="this.className=\'buttonHi\';" onmouseout="this.className=\'button\';" type="Button" onclick="javascript:window.location=\'cart.html\'">';
			temp += '</form>';
						temp += '<div class="clearing">&nbsp;</div>';
			temp += '<div id="confirmContainer">';
			temp += '<div id="paymentConfirm">Item added to cart</div>';
			temp += '</div>';
			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;
	}
}

			

