window.thumbnails = new Object();
												thumbnails[7160113] = new thumbnail(7160113,'342517','Sylvan Dale, Wolds','_D3X9378_thumb.jpg',130, 130,32,'photo_7160113.html');
												thumbnails[7159833] = new thumbnail(7159833,'342517','Buttermere ','_D3X9250_thumb.jpg',130, 78,32,'photo_7159833.html');
												thumbnails[6113379] = new thumbnail(6113379,'342518','Knife Edge','20090409-005_thumb.jpg',104, 130,32,'photo_6113379.html');
												thumbnails[6113387] = new thumbnail(6113387,'342518','Red rocks','20090409-006_thumb.jpg',104, 130,32,'photo_6113387.html');
												thumbnails[6113417] = new thumbnail(6113417,'342518','The Cold Pool','20090409-007_thumb.jpg',104, 130,32,'photo_6113417.html');
												thumbnails[6121617] = new thumbnail(6121617,'342516','Beach Debris','20090409-018_thumb.jpg',104, 130,32,'photo_6121617.html');
												thumbnails[6121629] = new thumbnail(6121629,'342519','Birch Trees','birch_trees_in_snow_thumb.jpg',103, 130,32,'photo_6121629.html');
												thumbnails[6121744] = new thumbnail(6121744,'342519','Raindale Golden Birch','200911005001_thumb.jpg',104, 130,32,'photo_6121744.html');
												thumbnails[6121749] = new thumbnail(6121749,'342516','Wreck of the Sarb-J','Wreck_of_the_Sarb-J_thumb.jpg',102, 130,32,'photo_6121749.html');
												thumbnails[6121846] = new thumbnail(6121846,'342519','Glen Etive Trees','20090409-055_thumb.jpg',104, 130,32,'photo_6121846.html');
												thumbnails[6121852] = new thumbnail(6121852,'342517','The Ba River in Winter','20100306003_thumb.jpg',104, 130,32,'photo_6121852.html');
												thumbnails[6121854] = new thumbnail(6121854,'342517','Black Mount Winter Dawn','20100306004_thumb.jpg',104, 130,32,'photo_6121854.html');
												thumbnails[6121878] = new thumbnail(6121878,'342516','Elgol','20090409-048_thumb.jpg',104, 130,32,'photo_6121878.html');
												thumbnails[6121880] = new thumbnail(6121880,'342518','Etive Water Plunge Pool','20100206009_thumb.jpg',102, 130,32,'photo_6121880.html');
												thumbnails[6121980] = new thumbnail(6121980,'342517','Overlooking Fenn Bog','20100114015_thumb.jpg',104, 130,32,'photo_6121980.html');
												thumbnails[6122161] = new thumbnail(6122161,'342516','East Cliff, Whitby','whitby_sunset_thumb.jpg',103, 130,32,'photo_6122161.html');
												thumbnails[6122165] = new thumbnail(6122165,'342516','Fiery Sunrise over Ravenscar','20091007002_thumb.jpg',103, 130,32,'photo_6122165.html');
												thumbnails[6122171] = new thumbnail(6122171,'342516','Saltwick Bay','20090711-002_thumb.jpg',104, 130,32,'photo_6122171.html');
												thumbnails[6122175] = new thumbnail(6122175,'342516','Robin Hoods Bay Sunrise','RHB_Sunrise_Oct_08_blend_thumb.jpg',130, 102,32,'photo_6122175.html');
												thumbnails[6122180] = new thumbnail(6122180,'342517','Buchaille Etive Mor','20100209007-2_thumb.jpg',104, 130,32,'photo_6122180.html');
												thumbnails[6122190] = new thumbnail(6122190,'342517','Moss in Temperate Rainforest','20100209005_thumb.jpg',104, 130,32,'photo_6122190.html');
												thumbnails[6122200] = new thumbnail(6122200,'342516','Robin Hoods Bay Winter Dawn','20100113002_thumb.jpg',130, 130,32,'photo_6122200.html');
												thumbnails[6122201] = new thumbnail(6122201,'342516','Bay Bottom at Dawn','20090409-075_thumb.jpg',130, 104,32,'photo_6122201.html');
												thumbnails[6122539] = new thumbnail(6122539,'342518','Glen Brittle in the rain','20090409-077_thumb.jpg',130, 104,32,'photo_6122539.html');
												thumbnails[6122562] = new thumbnail(6122562,'342519','Winter Wonderland','Etive_tree_monochrome_2_thumb.jpg',120, 130,32,'photo_6122562.html');
												thumbnails[6122566] = new thumbnail(6122566,'342519','Scots Pine in the Snow','Pine_detail_thumb.jpg',103, 130,32,'photo_6122566.html');
												thumbnails[6122592] = new thumbnail(6122592,'342517','That Tree, Rannoch Moor','20100306005_thumb.jpg',130, 64,32,'photo_6122592.html');
												thumbnails[6391761] = new thumbnail(6391761,'342517','Gunnerside','20090409-072_thumb.jpg',130, 104,32,'photo_6391761.html');
												thumbnails[7160088] = new thumbnail(7160088,'387006','Rocks at Porth Nanven','20101202006_thumb.jpg',130, 130,32,'photo_7160088.html');
												thumbnails[7160094] = new thumbnail(7160094,'387006','Porth Nanven Eggs','20101202005_thumb.jpg',104, 130,32,'photo_7160094.html');
												thumbnails[7160105] = new thumbnail(7160105,'387006','Botallach Mines, Cornwall','20101202004_thumb.jpg',103, 130,32,'photo_7160105.html');
												thumbnails[7160142] = new thumbnail(7160142,'387006','\'Steve\'','20101202009_thumb.jpg',104, 130,32,'photo_7160142.html');
												thumbnails[7160055] = new thumbnail(7160055,'387006','Treen Beach','20101202011_thumb.jpg',104, 130,32,'photo_7160055.html');
												thumbnails[7159860] = new thumbnail(7159860,'387006','Borrowdale Valley from Castle Crag','_D3X9281_thumb.jpg',97, 130,32,'photo_7159860.html');
												thumbnails[7159873] = new thumbnail(7159873,'387006','Whitby in the Rain','20100819004_thumb.jpg',130, 103,32,'photo_7159873.html');
												thumbnails[7159926] = new thumbnail(7159926,'387006','St Stephens Church, Robin Hoods Bay','20100819009_thumb.jpg',114, 130,32,'photo_7159926.html');
												thumbnails[7159968] = new thumbnail(7159968,'387006','Evening light over Whitby','20100819005_thumb.jpg',104, 130,32,'photo_7159968.html');

/***************************************************************************
* Create the array of Gallery objects                                      *
***************************************************************************/
var galleries = new Object();
				  					galleries[387006] = new gallery(387006,'7160142,7160105,7160094,7160088,7160055,7159968,7159926,7159873,7159860','Latest Pictures','section409407',[7160088,7160094,7160105,7160142,7160055,7159860,7159873,7159926,7159968],0, 0, '', 'section409407.html',0,1);
				  					galleries[342516] = new gallery(342516,'6122201,6122200,6122175,6122171,6122165,6122161,6121878,6121749,6121617','Coast','gallery',[6121617,6121749,6121878,6122161,6122165,6122171,6122175,6122200,6122201],0, 0, '', 'gallery_342516.html',0,0);
				  					galleries[342517] = new gallery(342517,'7160113,7159833,6391761,6122592,6122190,6122180,6121980,6121854,6121852','Mountains & Moors','gallery',[7160113,7159833,6121852,6121854,6121980,6122180,6122190,6122592,6391761],0, 0, '', 'gallery_342517.html',0,0);
				  					galleries[342518] = new gallery(342518,'6122539,6121880,6113417,6113387,6113379','Streams & Rivers','gallery',[6113379,6113387,6113417,6121880,6122539],0, 0, '', 'gallery_342518.html',0,0);
				  					galleries[342519] = new gallery(342519,'6122566,6122562,6121846,6121744,6121629','Trees','gallery',[6121629,6121744,6121846,6122562,6122566],0, 0, '', 'gallery_342519.html',0,0);
/***************************************************************************
* Create the array of image sets                                           *
***************************************************************************/
var imageSets = new Object();
imageSets[1] = '6121854';
imageSets[3] = '6121854';
 /***************************************************************************
* Get a server path given an ID                                            *
***************************************************************************/
function getServerPath(server_id) {
	var val = -1;
		switch (server_id) {
		case 21:
		val = 'http://www6.clikpic.com/davidjt/images';
		break;
	}
		switch (server_id) {
		case 1:
		val = 'http://www1.clikpic.com/davidjt/images';
		break;
	}
		switch (server_id) {
		case 2:
		val = 'http://admin.clikpic.com/davidjt/images';
		break;
	}
		switch (server_id) {
		case 24:
		val = 'http://tpc15/clikpic/davidjt/images';
		break;
	}
		switch (server_id) {
		case 4:
		val = 'http://clikchurch.clikpic.com/davidjt/images';
		break;
	}
		switch (server_id) {
		case 5:
		val = 'http://www2.clikpic.com/davidjt/images';
		break;
	}
		switch (server_id) {
		case 22:
		val = 'http://tpc5/clikpic/davidjt/images';
		break;
	}
		switch (server_id) {
		case 23:
		val = 'http://tpc10/clikpic/davidjt/images';
		break;
	}
		switch (server_id) {
		case 25:
		val = 'http://tpc16/clikpic/davidjt/images';
		break;
	}
		switch (server_id) {
		case 40:
		val = 'http://www11.clikpic.com/davidjt/images';
		break;
	}
		switch (server_id) {
		case 42:
		val = 'db2.clikpic.com/davidjt/images';
		break;
	}
		switch (server_id) {
		case 15:
		val = 'http://www3.clikpic.com/davidjt/images';
		break;
	}
		switch (server_id) {
		case 18:
		val = 'http://www4.clikpic.com/davidjt/images';
		break;
	}
		switch (server_id) {
		case 19:
		val = 'http://www5.clikpic.com/davidjt/images';
		break;
	}
		switch (server_id) {
		case 31:
		val = 'http://www7.clikpic.com/davidjt/images';
		break;
	}
		switch (server_id) {
		case 32:
		val = 'http://admin2.clikpic.com/davidjt/images';
		break;
	}
		switch (server_id) {
		case 33:
		val = 'http://www8.clikpic.com/davidjt/images';
		break;
	}
		switch (server_id) {
		case 34:
		val = 'http://www9.clikpic.com/davidjt/images';
		break;
	}
		switch (server_id) {
		case 35:
		val = 'http://admin3.clikpic.com/davidjt/images';
		break;
	}
		switch (server_id) {
		case 37:
		val = 'http://admin4.clikpic.com/davidjt/images';
		break;
	}
		switch (server_id) {
		case 38:
		val = 'http://admin5.clikpic.com/davidjt/images';
		break;
	}
		switch (server_id) {
		case 39:
		val = 'http://www10.clikpic.com/davidjt/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 && backgrounds[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:'',
                    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 (!basic) {
    if (op.updateHash && clik.getIDInUrl(location.href,'photo') != op.nextPhoto.id) {
		clik.changeHash('photos_id=' + op.nextPhoto.id, true);
    }
				
    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));		  $('body').trigger('clikUpdate');		}, op.onBefore);
      }    }
    	if (op.field) {
		op.field.value = photoId;
	} else {
		op.$photo.data('image_id', photoId);
    }
	    if (op.$title.length > 0) {
  		op.$title.fadeGalleryDetails(photoCaption, op.speed);
    }
        if (op.updateDocumentTitle) {
						  document.title = 'Photographs by David Tolcher: ' + photoCaption;
			    }
        if (op.$detail.length > 0) {
      temp = op.nextPhoto.fnGetImageDetails();
	    op.$detail.fadeGalleryDetails(temp, op.speed, function(){
	    var options = {photoinfominwidth:200};	    		options.photoinfoadjacent = true;			      	      resizePhotoInfo(options);
        if (typeof(backgrounds) != 'undefined' && op.nextPhoto == backgrounds[op.nextPhoto.id]) {
  	      toggleAddToCartConfirm(backgrounds);
  	    } else if (typeof(photos) != 'undefined' && op.nextPhoto == photos[op.nextPhoto.id]) {
  	      toggleAddToCartConfirm(photos);
  	    }
	    });
    }
        if (!op.speed) {      clik.doColumnResize(false, op.$photo.add(op.$detail).add(op.$title));      $('body').trigger('clikUpdate');    }        
    return html;			}
	else {
				
		window.location = 'photo_' + nextPhoto.id + '.html';
	}
		
}

/***************************************************************************
* Toggle add to cart confirmation element and set up the click event for   *
* the 'Add to cart' button.                                                *
***************************************************************************/
function toggleAddToCartConfirm(array){
  if (typeof(array) !== 'object') {
    array = photos;
  }
	if($('#paymentConfirm').length > 0){
		$('#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,array,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();
					dspOrderDetails(form.site.value);
				}
			}
			else{
				$('#paymentConfirm').text('Item not added - check cookies are enabled in your browser.').fadeIn();
			}
		});
	}
}
/***************************************************************************
* Get payment info for image - add as 'method' to photo object             *
***************************************************************************/
photo.prototype.fnGetImageDetails = function(){
	var temp = '';
	if (this.description != '') {
		temp = temp +  '<p id="imageDescription">' + this.description + '</p>';
	}
		if (this.photo_ref != '') {
		temp = temp + '<p class="imageinfo" id="imageRef"><strong>Ref: </strong>' + this.photo_ref + '</p>';
	}
		if (this.takendate != '') {
				
		temp = temp + '<p class="imageinfo" id="imageDate"><strong>Date: </strong>' + this.takendate + '</p>';
	}
	
	if (this.location != '') {
				
		temp = temp + '<p class="imageinfo" id="imageLocation"><strong>Location: </strong>' +  this.location + '</p>';
	}
	
	if (this.photographer != '') {
				
		temp = temp + '<p class="imageinfo" id="imagePhotographer"><strong>Photographer: </strong>' + this.photographer + '</p>';
	}
					
				if (temp != '') {
		temp = temp + '<div class="spacer"></div>';
	}
	return temp;
};

/***************************************************************************
* Get payment info for image - add as 'method' to photo object             *
***************************************************************************/
photo.prototype.fnGetPaymentInfo = function(){
	var temp = '';
	if (this.item_price !== '') {
				temp = temp + '<p>Order this print:</p>';
				temp = temp + '<p class="imageinfo" id="imagePrice"><strong>' + this.purchase_instruction + '</strong> &pound;' + (this.item_price).toFixed(2) + '</p>';
		var item_name  = this.purchase_instruction;
		var amount = (this.item_price).toFixed(2);
		var item_option  = 0;
	}
	else if (this.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(this.payment_groups_id);
		temp = temp + '</select>';
		temp = 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 = temp + '<form id="paymentForm" style="margin:0px;border:0px;" name="paymentForm" target="_blank" action="https://www.paypal.com/cgi-bin/webscr" method="post">';
	temp = 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 = temp + '<input type="hidden" name="cmd" value="_cart">';
	temp = temp + '<input type="hidden" name="business" value="davidjt@btinternet.com">';
	temp = temp + '<input type="hidden" name="currency_code" value="GBP">';
	temp = temp + '<input type="hidden" name="add" value="1">';
					temp = temp + '<input type="hidden" name="amount" value="'+amount+'">';
	temp = temp + '<input type="hidden" name="item_number" value="'+ref+'">';
					temp = temp + '<input type=\"Submit\" value=\"Add to cart\" id=\"paymentAddButton\" class=\"button\" onmouseover=\"this.className=\'buttonHi\';\" onmouseout=\"this.className=\'button\';\">';
									temp = temp + '</form>';
								temp = temp + '<form id="paymentCartForm" style="margin:0px;" name="paymentCartForm" target="_blank" action="https://www.paypal.com/cgi-bin/webscr" method="post">';
	temp = temp + '<input type="hidden" name="cmd" value="_cart">';
	temp = temp + '<input type="hidden" name="business" value="davidjt@btinternet.com">';
	temp = temp + '<input type="hidden" name="display" value="1">';
	temp = temp + '<input type=\"Submit\" value=\"View cart\" id=\"paymentViewButton\" class=\"button\" onmouseover=\"this.className=\'buttonHi\';\" onmouseout=\"this.className=\'button\';\">';
	temp = temp + '</form>';
							temp = 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({            href: thumbnails[imageID].fnGalleryLink(gallery_id),            title: galleries[gallery_id].title          });
        }
							}
										}
}

/***************************************************************************
* 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="' + galleries[i].section_code + '_' + galleries[i].id + '.html">' + galleries[i].title + '</a>';
			}
		}
		document.all.galleryLinks.innerHTML = 'Other galleries: ' + temp;
	}
}

		

