window.thumbnails = {};
thumbnails[8306250] = clik.newPhoto({"link":"#","caption":"Self Portrait","height":173,"id":8306250,"server_id":21,"src":"Self_portrait_thumb.jpg","galleries_id":"","width":130});
thumbnails[8306457] = clik.newPhoto({"link":"photo_8306457.html","caption":"'King' class locomotive in Sonning Cutting.","height":104,"id":8306457,"server_id":21,"src":"King_in_Sonning_Cutting_thumb.jpg","galleries_id":441811,"width":130});
thumbnails[8306473] = clik.newPhoto({"link":"photo_8306473.html","caption":"Brecon Beacons II","height":102,"id":8306473,"server_id":21,"src":"Brecon_Beacons___thumb.jpg","galleries_id":441810,"width":130});
thumbnails[8306479] = clik.newPhoto({"link":"photo_8306479.html","caption":"Phurnacite plant, Cynon Valley","height":98,"id":8306479,"server_id":21,"src":"phurnacite_plant_cynon_valley_thumb.jpg","galleries_id":441811,"width":130});
thumbnails[8306790] = clik.newPhoto({"link":"photo_8306790.html","caption":"Coal Country","height":98,"id":8306790,"server_id":21,"src":"4165_jan_08_relcol_P_thumb.jpg","galleries_id":441811,"width":130});
thumbnails[8316897] = clik.newPhoto({"link":"photo_8316897.html","caption":"Caversham Promenade","height":105,"id":8316897,"server_id":21,"src":"Caversham_Promenade_thumb.jpg","galleries_id":441810,"width":130});
thumbnails[8317007] = clik.newPhoto({"link":"photo_8317007.html","caption":"Tennant Canal","height":99,"id":8317007,"server_id":21,"src":"Tennant_Canal_Swansea_thumb.jpg","galleries_id":441810,"width":130});
thumbnails[8317023] = clik.newPhoto({"link":"photo_8317023.html","caption":"Dolgoch Viaduct","height":97,"id":8317023,"server_id":21,"src":"dolgochviaduct_thumb.jpg","galleries_id":441811,"width":130});
thumbnails[8317034] = clik.newPhoto({"link":"photo_8317034.html","caption":"Mumbles","height":97,"id":8317034,"server_id":21,"src":"Mumbles__thumb.jpg","galleries_id":441810,"width":130});
thumbnails[8317048] = clik.newPhoto({"link":"photo_8317048.html","caption":"Bwllfa Dare Colliery","height":103,"id":8317048,"server_id":21,"src":"Bwllfa_dare_Colliery__thumb.jpg","galleries_id":441811,"width":130});
thumbnails[8317085] = clik.newPhoto({"link":"photo_8317085.html","caption":"The Merthyr Tunnel","height":97,"id":8317085,"server_id":21,"src":"The_Merthyr_Tunnel_thumb.jpg","galleries_id":441811,"width":130});
thumbnails[8326757] = clik.newPhoto({"link":"photo_8326757.html","caption":"Henley on Thames","height":88,"id":8326757,"server_id":21,"src":"Henley___thumb.jpg","galleries_id":441810,"width":130});
thumbnails[8326902] = clik.newPhoto({"link":"photo_8326902.html","caption":"Tractor & Barn","height":85,"id":8326902,"server_id":21,"src":"picton2P_thumb.jpg","galleries_id":441810,"width":130});
thumbnails[8326912] = clik.newPhoto({"link":"photo_8326912.html","caption":"Pen y Fan","height":86,"id":8326912,"server_id":21,"src":"Pen-y-_Fan_thumb.jpg","galleries_id":441810,"width":130});
thumbnails[8327897] = clik.newPhoto({"link":"photo_8327897.html","caption":"Dorchester on Thames","height":98,"id":8327897,"server_id":21,"src":"RP_4_may_07_P_copy_thumb.jpg","galleries_id":441810,"width":130});
thumbnails[8328992] = clik.newPhoto({"link":"photo_8328992.html","caption":"Thames at Reading.","height":104,"id":8328992,"server_id":21,"src":"RP2may07P_thumb.jpg","galleries_id":441810,"width":130});
thumbnails[8329000] = clik.newPhoto({"link":"photo_8329000.html","caption":"Cow Lane","height":98,"id":8329000,"server_id":21,"src":"RP3may07P_thumb.jpg","galleries_id":441810,"width":130});
thumbnails[8329038] = clik.newPhoto({"link":"photo_8329038.html","caption":"Lord Nelson","height":104,"id":8329038,"server_id":21,"src":"RPImay07P_thumb.jpg","galleries_id":441811,"width":130});
thumbnails[8329072] = clik.newPhoto({"link":"photo_8329072.html","caption":"Purley King","height":193,"id":8329072,"server_id":21,"src":"Purley_King_thumb.jpg","galleries_id":441811,"width":130});
thumbnails[8329095] = clik.newPhoto({"link":"photo_8329095.html","caption":"Sonning Lock","height":87,"id":8329095,"server_id":21,"src":"sonninglock_small_thumb.jpg","galleries_id":441810,"width":130});
thumbnails[8329111] = clik.newPhoto({"link":"photo_8329111.html","caption":"Black 5's","height":87,"id":8329111,"server_id":21,"src":"Black_5s__thumb.jpg","galleries_id":441811,"width":130});
thumbnails[8329164] = clik.newPhoto({"link":"photo_8329164.html","caption":"'Western' at Bridgend","height":103,"id":8329164,"server_id":21,"src":"weternbridgend_thumb.jpg","galleries_id":441811,"width":130});
thumbnails[8329168] = clik.newPhoto({"link":"photo_8329168.html","caption":"Neath & Brecon Railway","height":98,"id":8329168,"server_id":21,"src":"Neath__Brecon_Railway_thumb.JPG","galleries_id":441811,"width":130});
thumbnails[8329172] = clik.newPhoto({"link":"photo_8329172.html","caption":"'Tornado' at Grosmont","height":102,"id":8329172,"server_id":21,"src":"tornadoatgrosmont_thumb.jpg","galleries_id":441811,"width":130});
thumbnails[8329174] = clik.newPhoto({"link":"photo_8329174.html","caption":"Mapledurham Estate","height":87,"id":8329174,"server_id":21,"src":"Mapledurham_Estate_thumb.JPG","galleries_id":441810,"width":130});
thumbnails[8329175] = clik.newPhoto({"link":"photo_8329175.html","caption":"Brecon Beacons ","height":95,"id":8329175,"server_id":21,"src":"paint-012paint_Brecon_Beacons_J_thumb.JPG","galleries_id":441810,"width":130});
thumbnails[8329191] = clik.newPhoto({"link":"photo_8329191.html","caption":"The Crooked Billet.","height":97,"id":8329191,"server_id":21,"src":"paint-021paint_Crooked_Billet_J_thumb.JPG","galleries_id":441810,"width":130});
thumbnails[8720791] = clik.newPhoto({"link":"photo_8720791.html","caption":"Hardwick House","height":97,"id":8720791,"server_id":21,"src":"HardwickHouselowres_thumb.jpg","galleries_id":441810,"width":130});
thumbnails[8720806] = clik.newPhoto({"link":"photo_8720806.html","caption":"Hayfield","height":97,"id":8720806,"server_id":21,"src":"Hayfieldlowres_thumb.jpg","galleries_id":441810,"width":130});
thumbnails[8720814] = clik.newPhoto({"link":"photo_8720814.html","caption":"Henrhyd Falls","height":98,"id":8720814,"server_id":21,"src":"HenrhydFallslowres_thumb.jpg","galleries_id":441810,"width":130});
thumbnails[9058700] = clik.newPhoto({"link":"photo_9058700.html","caption":"South Wales Coal Train","height":103,"id":9058700,"server_id":21,"src":"South_Wales_coal_train_thumb.jpg","galleries_id":441811,"width":130});
thumbnails[9058745] = clik.newPhoto({"link":"photo_9058745.html","caption":"Britannia Class approaching Cholsey","height":103,"id":9058745,"server_id":21,"src":"7002_Lo_res_thumb.jpg","galleries_id":441811,"width":130});
thumbnails[9058765] = clik.newPhoto({"link":"photo_9058765.html","caption":"Field at Dunsden","height":96,"id":9058765,"server_id":21,"src":"Corn_field_Lo_res_thumb.jpg","galleries_id":441810,"width":130});

/***************************************************************************
* Create the array of Gallery objects                                      *
***************************************************************************/
var galleries = new Object();
galleries[441810] = clik.newGallery({"photoIDs":[8306473,8316897,8317007,8317034,8326757,8326902,8326912,8327897,8328992,8329000,8329095,8329174,8329175,8329191,8720791,8720806,8720814,9058765],"link":"gallery_441810.html","skipIndex":0,"section_code":"gallery","id":441810,"parentGallery":"","featured_images":"9058765,8720814,8720806,8720791,8329191,8329175,8329174,8329095,8329000,8328992","maxRecords":0,"usePopups":false,"singleSection":false,"title":"Landscapes"});galleries[441811] = clik.newGallery({"photoIDs":[8306457,8306479,8306790,8317023,8317048,8317085,8329038,8329072,8329111,8329164,8329168,8329172,9058700,9058745],"link":"gallery_441811.html","skipIndex":0,"section_code":"gallery","id":441811,"parentGallery":"","featured_images":"9058745,9058700,8329172,8329168,8329164,8329111,8329072,8329038,8317085,8317048","maxRecords":0,"usePopups":false,"singleSection":false,"title":"Railways"});/***************************************************************************
* Create the array of image sets                                           *
***************************************************************************/
var imageSets = {};
imageSets[3] = '9058765,9058745,9058700,8720814,8720806,8720791,8329191,8329175,8329174,8329172,8329168,8329164,8329111,8329095,8329072,8329038,8329000,8328992,8327897,8326912,8326902,8326757,8317085,8317048,8317034,8317023,8317007,8316897,8306790,8306479,8306473,8306457,8306250';
imageSets[1] = '8306250';
 /***************************************************************************
* Get a server path given an ID                                            *
***************************************************************************/
function getServerPath(server_id) {
	var val = -1;
		switch (server_id) {
		case 19:
		val = 'http://www5.clikpic.com/pictonart/images';
		break;
	}
		switch (server_id) {
		case 35:
		val = 'http://admin3.clikpic.com/pictonart/images';
		break;
	}
		switch (server_id) {
		case 18:
		val = 'http://www4.clikpic.com/pictonart/images';
		break;
	}
		switch (server_id) {
		case 15:
		val = 'http://www3.clikpic.com/pictonart/images';
		break;
	}
		switch (server_id) {
		case 34:
		val = 'http://www9.clikpic.com/pictonart/images';
		break;
	}
		switch (server_id) {
		case 39:
		val = 'http://www10.clikpic.com/pictonart/images';
		break;
	}
		switch (server_id) {
		case 37:
		val = 'http://admin4.clikpic.com/pictonart/images';
		break;
	}
		switch (server_id) {
		case 38:
		val = 'http://admin5.clikpic.com/pictonart/images';
		break;
	}
		switch (server_id) {
		case 21:
		val = 'http://www6.clikpic.com/pictonart/images';
		break;
	}
		switch (server_id) {
		case 42:
		val = 'db2.clikpic.com/pictonart/images';
		break;
	}
		switch (server_id) {
		case 40:
		val = 'http://www11.clikpic.com/pictonart/images';
		break;
	}
		switch (server_id) {
		case 22:
		val = 'http://tpc5/clikpic/pictonart/images';
		break;
	}
		switch (server_id) {
		case 23:
		val = 'http://tpc10/clikpic/pictonart/images';
		break;
	}
		switch (server_id) {
		case 24:
		val = 'http://tpc15/clikpic/pictonart/images';
		break;
	}
		switch (server_id) {
		case 25:
		val = 'http://tpc16/clikpic/pictonart/images';
		break;
	}
		switch (server_id) {
		case 26:
		val = 'http://tpc20/clikpic/pictonart/images';
		break;
	}
		switch (server_id) {
		case 2:
		val = 'http://admin.clikpic.com/pictonart/images';
		break;
	}
		switch (server_id) {
		case 1:
		val = 'http://www1.clikpic.com/pictonart/images';
		break;
	}
		switch (server_id) {
		case 0:
		val = 'http://www.clikpic.com/pictonart/images';
		break;
	}
		switch (server_id) {
		case 5:
		val = 'http://www2.clikpic.com/pictonart/images';
		break;
	}
		switch (server_id) {
		case 32:
		val = 'http://www8.clikpic.com/pictonart/images';
		break;
	}
		switch (server_id) {
		case 4:
		val = 'http://clikchurch.clikpic.com/pictonart/images';
		break;
	}
		switch (server_id) {
		case 31:
		val = 'http://www7.clikpic.com/pictonart/images';
		break;
	}
		switch (server_id) {
		case 51:
		val = 'http://www12.clikpic.com/pictonart/images';
		break;
	}
		switch (server_id) {
		case 52:
		val = 'http://tpc22/clikpic/pictonart/images';
		break;
	}
		switch (server_id) {
		case 53:
		val = 'http://images.clikpic.com/pictonart/images';
		break;
	}
		switch (server_id) {
		case 50:
		val = '[cliktext value=article.servers_id type=servers_id]/pictonart/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 = 'Richard Picton: ' + 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>';
	}
			
				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>Order this print:</p>';
				temp += '<div class="imageinfo" id="imagePrice"><strong>' + this.purchase_instruction + '</strong> ' + (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.item_price !== '') {
			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;
	}
}

		

