window.thumbnails = {};
thumbnails[8195389] = clik.newPhoto({"link":"#","caption":"","height":200,"id":8195389,"server_id":19,"src":"Kevin_by_Keith_Gillard12_thumb.JPG","galleries_id":"","width":130});
thumbnails[8161781] = clik.newPhoto({"link":"photo_8161781.html","caption":"Split Apple Rock, Abel Tasman National Park","height":140,"id":8161781,"server_id":37,"src":"IMG_4746-2_thumb.jpg","galleries_id":436114,"width":130});
thumbnails[8195445] = clik.newPhoto({"link":"photo_8195445.html","caption":"Sunset, West Coast New Zealand","height":67,"id":8195445,"server_id":19,"src":"Sunrise_thumb.jpg","galleries_id":436114,"width":130});
thumbnails[8195456] = clik.newPhoto({"link":"photo_8195456.html","caption":"West Coast sunset","height":71,"id":8195456,"server_id":19,"src":"West_Coast_Sunset-1_thumb.jpg","galleries_id":436114,"width":130});
thumbnails[8195464] = clik.newPhoto({"link":"photo_8195464.html","caption":"Flaming Tussock, Dansies Pass, New Zealand","height":50,"id":8195464,"server_id":19,"src":"Tussock_thumb.jpg","galleries_id":436114,"width":130});
thumbnails[8195466] = clik.newPhoto({"link":"photo_8195466.html","caption":"Fire In the Sky, Punakaiki, New Zealand","height":93,"id":8195466,"server_id":19,"src":"Fireinthesky_thumb.jpg","galleries_id":436114,"width":130});
thumbnails[8195471] = clik.newPhoto({"link":"photo_8195471.html","caption":"Moeraki Boulders, New Zealand","height":82,"id":8195471,"server_id":19,"src":"MoerakiBoulders_thumb.jpg","galleries_id":436114,"width":130});
thumbnails[8195474] = clik.newPhoto({"link":"photo_8195474.html","caption":"Ship anchored outside Lyttelton Harbour","height":152,"id":8195474,"server_id":19,"src":"Tanker_outside_Lyttelton_Harbour_thumb.jpg","galleries_id":436114,"width":130});
thumbnails[8195475] = clik.newPhoto({"link":"photo_8195475.html","caption":"Boat Stack, Purau, Lyttelton Harbour Basin, New Zealand","height":166,"id":8195475,"server_id":19,"src":"Boat_Stack_Purau_Lyttelton_Harbour_Basin_thumb.jpg","galleries_id":436114,"width":130});
thumbnails[8195477] = clik.newPhoto({"link":"photo_8195477.html","caption":"Rock formations, Castle Hill, New Zealand","height":166,"id":8195477,"server_id":19,"src":"Castle_Hill_thumb.jpg","galleries_id":436114,"width":130});
thumbnails[8195480] = clik.newPhoto({"link":"photo_8195480.html","caption":"The Old Wharf, Selwyn Huts, Canterbury, New Zealand","height":103,"id":8195480,"server_id":19,"src":"The_Old_Wharf_thumb.jpg","galleries_id":436114,"width":130});
thumbnails[8195483] = clik.newPhoto({"link":"photo_8195483.html","caption":"Mitre Peak, Fiordland, New Zealand","height":59,"id":8195483,"server_id":19,"src":"Mitre_Peak_Fiordland_New_Zealand_thumb.jpg","galleries_id":436114,"width":130});
thumbnails[8195485] = clik.newPhoto({"link":"photo_8195485.html","caption":"Franz Josef Glacier, West Coast, New Zealand","height":81,"id":8195485,"server_id":19,"src":"Franz_Josef_Glacier_New_Zealand_thumb.jpg","galleries_id":436114,"width":130});
thumbnails[8195487] = clik.newPhoto({"link":"photo_8195487.html","caption":"Moonrise over the Remarkables, Queenstown, New Zealand","height":84,"id":8195487,"server_id":19,"src":"Moonrise_over_the_Remarkables_Queenstwon_New_Zealand_thumb.jpg","galleries_id":436114,"width":130});
thumbnails[8195488] = clik.newPhoto({"link":"photo_8195488.html","caption":"Dawn, Lake Matheson, New Zealand","height":96,"id":8195488,"server_id":19,"src":"Dawn_Lake_Matheson_New_Zealand_thumb.jpg","galleries_id":436114,"width":130});
thumbnails[8195489] = clik.newPhoto({"link":"photo_8195489.html","caption":"Ice Cave, Franz Josef, Glacier, New Zealand","height":83,"id":8195489,"server_id":19,"src":"Ice_cave_thumb.jpg","galleries_id":436114,"width":130});
thumbnails[8195540] = clik.newPhoto({"link":"photo_8195540.html","caption":"Mount Cook, New Zealand","height":81,"id":8195540,"server_id":19,"src":"Mount_Cook_peak_thumb.jpg","galleries_id":436114,"width":130});
thumbnails[8203190] = clik.newPhoto({"link":"photo_8203190.html","caption":"Dawn in the Cheviot Hills, Canterbury, New Zealand","height":65,"id":8203190,"server_id":38,"src":"Cheviotdawn_thumb.jpg","galleries_id":436114,"width":130});
thumbnails[8203222] = clik.newPhoto({"link":"photo_8203222.html","caption":"Sunrise at Moeraki Boulders, New Zealand","height":88,"id":8203222,"server_id":38,"src":"Moeraki_thumb.jpg","galleries_id":436114,"width":130});
thumbnails[8203225] = clik.newPhoto({"link":"photo_8203225.html","caption":"Moeraki Boulders, New Zealand","height":87,"id":8203225,"server_id":38,"src":"Moerakisunset_thumb.jpg","galleries_id":436114,"width":130});
thumbnails[8203229] = clik.newPhoto({"link":"photo_8203229.html","caption":"Old West Coast Beech Tree","height":81,"id":8203229,"server_id":38,"src":"OldBeech_thumb.jpg","galleries_id":436114,"width":130});
thumbnails[8203231] = clik.newPhoto({"link":"photo_8203231.html","caption":"Purakanui Falls, Catlins, New Zealand","height":102,"id":8203231,"server_id":38,"src":"Purakanuifalls_thumb.jpg","galleries_id":436114,"width":130});
thumbnails[8203235] = clik.newPhoto({"link":"photo_8203235.html","caption":"Dansies Pass, New Zealand","height":64,"id":8203235,"server_id":38,"src":"dansiespass_thumb.jpg","galleries_id":436114,"width":130});
thumbnails[8203243] = clik.newPhoto({"link":"photo_8203243.html","caption":"Tahunanui Sunset, Nelson, New Zealand","height":66,"id":8203243,"server_id":38,"src":"Nelsonsunset_thumb.jpg","galleries_id":436114,"width":130});
thumbnails[8203247] = clik.newPhoto({"link":"photo_8203247.html","caption":"Fifeshire Rock and Haulashore Island Fisheye Panorama","height":39,"id":8203247,"server_id":38,"src":"Fifeshirerockpanorama_thumb.jpg","galleries_id":436114,"width":130});
thumbnails[8203249] = clik.newPhoto({"link":"photo_8203249.html","caption":"Split Apple Rock, Abel Tasman National Park, New Zealand, Panorama","height":40,"id":8203249,"server_id":38,"src":"AbelTasmanPanorama_thumb.jpg","galleries_id":436114,"width":130});
thumbnails[8237577] = clik.newPhoto({"link":"photo_8237577.html","caption":"African Elephant, Melbourne Zoo","height":133,"id":8237577,"server_id":38,"src":"elephant_thumb.jpg","galleries_id":436115,"width":130});
thumbnails[8237578] = clik.newPhoto({"link":"photo_8237578.html","caption":"Gecko","height":59,"id":8237578,"server_id":38,"src":"Gecko_thumb.jpg","galleries_id":436115,"width":130});
thumbnails[8237579] = clik.newPhoto({"link":"photo_8237579.html","caption":"Old Car in Fog","height":91,"id":8237579,"server_id":38,"src":"IMG_4808-Edit_thumb.jpg","galleries_id":436115,"width":130});
thumbnails[8237580] = clik.newPhoto({"link":"photo_8237580.html","caption":"Shiny as new","height":88,"id":8237580,"server_id":38,"src":"OldCar1_thumb.jpg","galleries_id":436115,"width":130});
thumbnails[8237581] = clik.newPhoto({"link":"photo_8237581.html","caption":"Old Friends","height":83,"id":8237581,"server_id":38,"src":"OldFriends_thumb.jpg","galleries_id":436115,"width":130});

/***************************************************************************
* Create the array of Gallery objects                                      *
***************************************************************************/
var galleries = new Object();
galleries[436114] = clik.newGallery({"photoIDs":[8161781,8195445,8195456,8195464,8195466,8195471,8195474,8195475,8195477,8195480,8195483,8195485,8195487,8195488,8195489,8195540,8203190,8203222,8203225,8203229,8203231,8203235,8203243,8203247,8203249],"link":"gallery_436114.html","skipIndex":0,"section_code":"gallery","id":436114,"parentGallery":"","featured_images":"8203249,8203247,8203243,8203235,8203231,8203229,8203225,8203222,8203190,8195540","maxRecords":0,"usePopups":false,"singleSection":false,"title":"New Zealand Images"});galleries[436115] = clik.newGallery({"photoIDs":[8237577,8237578,8237579,8237580,8237581],"link":"gallery_436115.html","skipIndex":0,"section_code":"gallery","id":436115,"parentGallery":"","featured_images":"8237581,8237580,8237579,8237578,8237577","maxRecords":0,"usePopups":false,"singleSection":false,"title":"Other Images"});/***************************************************************************
* Create the array of image sets                                           *
***************************************************************************/
var imageSets = {};
imageSets[3] = '8237581,8237580,8237579,8237578,8237577,8203249,8203247,8203243,8203235,8203231,8203229,8203225,8203222,8203190,8195540,8195489,8195488,8195487,8195485,8195483,8195480,8195477,8195475,8195474,8195471,8195466,8195464,8195456,8195445,8195389,8161781';
imageSets[1] = '8161781';
 /***************************************************************************
* Get a server path given an ID                                            *
***************************************************************************/
function getServerPath(server_id) {
	var val = -1;
		switch (server_id) {
		case 19:
		val = 'http://www5.clikpic.com/KARussell/images';
		break;
	}
		switch (server_id) {
		case 35:
		val = 'http://admin3.clikpic.com/KARussell/images';
		break;
	}
		switch (server_id) {
		case 22:
		val = 'http://tpc5/clikpic/KARussell/images';
		break;
	}
		switch (server_id) {
		case 18:
		val = 'http://www4.clikpic.com/KARussell/images';
		break;
	}
		switch (server_id) {
		case 23:
		val = 'http://tpc10/clikpic/KARussell/images';
		break;
	}
		switch (server_id) {
		case 15:
		val = 'http://www3.clikpic.com/KARussell/images';
		break;
	}
		switch (server_id) {
		case 24:
		val = 'http://tpc15/clikpic/KARussell/images';
		break;
	}
		switch (server_id) {
		case 34:
		val = 'http://www9.clikpic.com/KARussell/images';
		break;
	}
		switch (server_id) {
		case 25:
		val = 'http://tpc16/clikpic/KARussell/images';
		break;
	}
		switch (server_id) {
		case 39:
		val = 'http://www10.clikpic.com/KARussell/images';
		break;
	}
		switch (server_id) {
		case 26:
		val = 'http://tpc20/clikpic/KARussell/images';
		break;
	}
		switch (server_id) {
		case 37:
		val = 'http://admin4.clikpic.com/KARussell/images';
		break;
	}
		switch (server_id) {
		case 38:
		val = 'http://admin5.clikpic.com/KARussell/images';
		break;
	}
		switch (server_id) {
		case 21:
		val = 'http://www6.clikpic.com/KARussell/images';
		break;
	}
		switch (server_id) {
		case 2:
		val = 'http://admin.clikpic.com/KARussell/images';
		break;
	}
		switch (server_id) {
		case 1:
		val = 'http://www1.clikpic.com/KARussell/images';
		break;
	}
		switch (server_id) {
		case 42:
		val = 'db2.clikpic.com/KARussell/images';
		break;
	}
		switch (server_id) {
		case 32:
		val = 'http://www8.clikpic.com/KARussell/images';
		break;
	}
		switch (server_id) {
		case 5:
		val = 'http://www2.clikpic.com/KARussell/images';
		break;
	}
		switch (server_id) {
		case 40:
		val = 'http://www11.clikpic.com/KARussell/images';
		break;
	}
		switch (server_id) {
		case 31:
		val = 'http://www7.clikpic.com/KARussell/images';
		break;
	}
		switch (server_id) {
		case 4:
		val = 'http://clikchurch.clikpic.com/KARussell/images';
		break;
	}
		switch (server_id) {
		case 50:
		val = '[cliktext value=article.servers_id type=servers_id]/KARussell/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:'',$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 = 'Kevin Russell 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>';
	}
			
				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.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 += '<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 += '<a href="' + galleries[i].section_code + '_' + galleries[i].id + '.html">' + galleries[i].title + '</a>';
							}
		}
		document.all.galleryLinks.innerHTML = 'Other galleries: ' + temp;
	}
}

		

