<!--
// Javascript to parse and modify as necessary the parameters passed from an index
// page to the viewer DHTML page.
//


//Edit to cope with firefox encoding too much stuff:
/**
*
*  URL encode / decode
*  http://www.webtoolkit.info/
*
**/

var UrlEncoder = {

	// public method for url decoding
	decode : function (string) {
		return this._utf8_decode(unescape(string));
	},

	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;

		while ( i < utftext.length ) {

			c = utftext.charCodeAt(i);

			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}

		}

		return string;
	}

}



// window.location.href returns the url passed, save as 'url'
// The parameter list is preceded by '?', the parameters are separated by '~'
if (document.images)
{
	var url=window.location.href;

	// Look for ?, if missing, no parameters passed
	var is_params=url.indexOf('?');
	if (is_params != -1)
	{
		passed_params=url.substring(is_params+1,url.length);
		var params="";

        //Another Edit:
		// Decode Parameters
		params=UrlEncoder.decode(passed_params);
   	}
	else
	{
		params="~~~~~~~";
	}

	// params contains the supplied parameters as the creator intended rather than as HTML interpreted up!
	// Now split on ~ characters into an array
	// The fields are:
	// 0 - image id (no .jpg suffix)
	// 1 - image width
	// 2 - image height
	// 3 - alt text from gallery
	// 4 - any additional text
	// 5 - date
	// 6 - image/scanning information
	// 7 - other photographer

	var image = new Array(8)
		image[0]="";
		image[1]="";
		image[2]="";
		image[3]="";
		image[4]="";
		image[5]="";
		image[6]="";
		image[7]="";
		image[8]="Copyright Martin Cowgill";

	var subscript=0;
	for (count = 0; count < params.length; count++)
	{
		this_char=params.charAt(count);
		if (this_char == "~")
		{
			subscript++;
		}
		else
		{
			image[subscript]=image[subscript]+this_char;
		}
	}

	// Set appropriate values for any null or coded parameters
	if (image[6]=="") { image[6]="Transparency scanned with Minolta Dimage Dual III scanner"; }
	if (image[6]=="DO") { image[6]="Digital image from Olympus C1400L camera"; }
	if (image[6]=="EF") { image[6]="Transparency scanned with Epson 1200P flatbed scanner"; }
	if (image[6]=="DN") { image[6]="Digital image from Nikon D70 camera"; }

	if (image[7]!="")
	{
		image[8]="Page copyright Martin Cowgill";
	}
}
// - End of JavaScript - -->

