	// Extract image to load from URL parameter
	// --------------------------------------------------------------------------------
	var urlquery = location.href.split("?");
	if ( !urlquery[1] ) urlquery[1] = '1';
	var parameters = urlquery[1].split("=");
	var imageToLoad = parseInt(parameters[1]);
	if ( (imageToLoad == '') || isNaN(imageToLoad) ) imageToLoad = 1;

	// Browser detection
	// --------------------------------------------------------------------------------
	var agent = navigator.userAgent.toLowerCase();
	var IEBrowser    = ( (agent.indexOf("msie") != -1) && (agent.indexOf("opera") == -1) );
	var OperaBrowser = (agent.indexOf("opera") != -1);

	// Max image properties (excl. padding)
	// --------------------------------------------------------------------------------
	var maxPortraitHeight = 412; // px
	var maxLandscapeWidth = 630; // px

	// Prefetch images
	// --------------------------------------------------------------------------------
	allImages = new Array();
	for ( i=1; i < imageArray.length; i++ ) {
		allImages[i] = new Image();
		allImages[i].src = imageArray[i];
	}

	// Copy image information into slide show image array:
	// --------------------------------------------------------------------------------
	var fadeimages=new Array()
	for ( i=0; i < imageArray.length-1; i++ ) {
		fadeimages[i] = [imageArray[i+1], "", ""];
	}

	function fade(thumbnailName, theMode) {
		theThumbnail = document.getElementById(thumbnailName);
		value = (theMode == 'over') ? 100 : 50; // in %
		if ( IEBrowser ) {
			theThumbnail.filters[0].opacity = value;		// IE only
		} else {
			theThumbnail.style.opacity = value/100; 		// Mozilla
		}
	}

	// Load image into main image tag
	// Parameter: index of image array
	// --------------------------------------------------------------------------------
	function loadImage(index) {
		
		var captionHeight     = 45;  // px
		var imagePadding      = 10;  // px
		var borderThickness   = 1;   // px
		
		// Get DOM elements: image and caption:
		theImage   = document.getElementById('mainImage');
		theCaption = document.getElementById('caption_'+index);
		
		// Initialise padding-top. IE needs this, otherwise adds padding to height.
		theImage.style.paddingTop = '0px';
		
		// Assign source and dimensions:
		theImage.src    = imageArray[index];
		var imageHeight = allImages[index].height;
		var imageWidth  = allImages[index].width;

		// If images are oversize, calculate the factor by which
		// we have to reduce the image (keeping the aspect ratio):
		factor = 1;
		if ( imageHeight > maxPortraitHeight ) {
			factor = maxPortraitHeight / imageHeight;
		}
		if ( imageWidth > maxLandscapeWidth ) {
			if ( factor != 1 ) {
				// Now both width and height are too big => scale by the smallest factor:
				if ( maxLandscapeWidth / imageWidth < factor ) {
					factor = maxLandscapeWidth / imageWidth;
				}
			} else {
				// Height was ok => just scale with width factor:
				factor = maxLandscapeWidth / imageWidth;
			}
		}
		imageHeight = imageHeight * factor;
		imageWidth  = imageWidth  * factor;

		// We cannot set the property theImage.height directly (read-only) => set the style instead:
		theImage.style.height = imageHeight + 'px';
		theImage.style.width  = imageWidth  + 'px';
		
		// Equally center image vertically:
		paddingTop = (maxPortraitHeight - imageHeight) / 2;
		theImage.style.paddingTop    = paddingTop + 'px';
		theImage.style.paddingBottom = paddingTop + 'px';
		
		// Equally center image horizontally. Comment this part to have images flush left to thumbs.
		paddingLeft = (maxLandscapeWidth - imageWidth) / 2;
//		theImage.style.paddingLeft  = paddingLeft + 'px';
//		theImage.style.paddingRight = paddingLeft + 'px';
theImage.parentNode.style.width = 652 - (2*paddingLeft) + 'px';
		
		// Make the corresponding image caption visible:
		theCaption.style.display = 'block';
		
		// Change link for "buy this image" to contain image name:
		theImageLink = document.getElementById('buyImageLink');
		slashPosition = imageArray[index].indexOf('/');
		imageName = imageArray[index].substr(slashPosition+1, imageArray[index].length-slashPosition);
//		theImageLink.href = 'buyImage.html?image='+imageName;
		var sPath = theImage.src.substr(theImage.src.indexOf('galleries/'));
//alert (sPath);
		theImageLink.href = '../../buyImage.html?image='+sPath;
	}



