if (typeof quantum !== "object") {quantum = {};}
if (typeof quantum.lb !== "object") {quantum.lb = {};}
if (typeof quantum.explorer !== "object") {quantum.explorer = {version : 8};}

quantum.lb.cookie = (typeof (quantum.lb.cookie) === "string") ? quantum.lb.cookie : "";
quantum.lb.keys = (typeof (quantum.lb.keys) === "object") ? quantum.lb.keys : [];
quantum.lb.titles = (typeof (quantum.lb.titles) === "object") ? quantum.lb.titles : [];
quantum.lb.src = (typeof (quantum.lb.src) === "object") ? quantum.lb.src : [];
quantum.lb.canvas = {open : 150, closed : 2};
quantum.lb.floating = {width : 0};
quantum.lb.open = false;
quantum.lb.ieBox = {};

quantum.baseURL = 'http://www.mikekiplingstockphotos.co.uk/';
quantum.blackBox = {};
quantum.maxWidth = 0;
quantum.maxHeight = 0;
quantum.totalLoaded = 0;
quantum.get = {};
quantum.set = {};
quantum.large = {};
quantum.wait = {};
quantum.help = {x : 0, y : 0, opacity : 0, delay : 1500, id : 0, up : false, width : 250, height: 30, radius : 5, top : 15, left : 15};
quantum.slider = {border : {width : 0},	sprite : {expander : 0, width : 0}, buffer : {left: 0, right: 0}};
quantum.convert = {};

quantum.large.click = function (context,e) {	
	var dbref = $(context).attr('id').substring(3);
	var src = $(context).attr('src');
	var filecode = src.substring(src.lastIndexOf("/")+1, src.indexOf(".jpg"));
	var path = src.substring(0,src.lastIndexOf("/"));
	var hyper = path + "/large/" + filecode + ".jpg";	
	var html = "<div class='center' style='width:25px; height: 25px; padding-top:12px;'><img src='" + quantum.baseURL + "/loading.gif' /></div>";
	var title = ($(context).attr("title"));

	quantum.blackBox(html, 
		{
			width: 50, 
			height: 50, 
			animSpeed: 200,
			fadeSpeed: 200, 
			style: {animType : "tv3"}, 
			onFinish: function () 
				{ quantum.large.load(hyper, filecode, dbref, title); }
		});
	return false;
};

quantum.lb.init = function ()
{
	if (quantum.explorer.version > 7)
	{
		$("body").append("<div id='mainLightbox'><div id='mainLightboxTitle'>Lightbox</div><div id='mainLightboxScroller'></div></div>");
	}
	quantum.lb.windowResized();
};

quantum.lb.lightBulb = function (icon)
{
	var code = (icon.target.id).substring(3);
	if ((icon.target.id).search(/ic1/) === 0)
	{
		$("#ic1"+code).removeClass("icon1").addClass("icon2").unbind("click",quantum.lb.lightBulb).bind("click",quantum.lb.unlightBulb);
	}
	else
	{
		$("#ic1"+code).removeClass("icon1").addClass("icon2").unbind("click",quantum.lb.lightBulb).bind("click",quantum.lb.unlightBulb);
		$(".icon8").unbind("click",quantum.lb.lightBulb).removeClass("icon8").addClass("icon7").bind("click",quantum.lb.unlightBulb);	
	}
	
	quantum.lb.keys.push(code);
	quantum.lb.titles.push($("#pix"+code).attr("title"));
	quantum.lb.src.push($("#pix"+code).attr("src"));	
	quantum.cookie('lightbox', quantum.lb.keys.join(","),{path: "/", domain: 'www.mikekiplingstockphotos.co.uk'});
	quantum.lb.draw();
	$("#fde"+code).css("opacity",0).fadeTo(500,1,quantum.lb.draw);
};

quantum.lb.unlightBulb = function (icon)
{
	var temp1 = [], temp2=[], temp3=[], i = 0;
	var code = (icon.target.id).substring(3);
	
	if ((icon.target.id).search(/ic1/) === 0)
	{
		$("#ic1"+code).removeClass("icon2").addClass("icon1").unbind("click",quantum.lb.unlightBulb).bind("click",quantum.lb.lightBulb);
	}
	else
	{
		$("#ic1"+code).removeClass("icon2").addClass("icon1").unbind("click",quantum.lb.unlightBulb).bind("click",quantum.lb.lightBulb);
		$(".icon7").unbind("click",quantum.lb.unlightBulb).removeClass("icon7").addClass("icon8").bind("click",quantum.lb.lightBulb);	
	}

	
	for (i=0; i < quantum.lb.keys.length; i++)
	{
		if (code !== quantum.lb.keys[i])
		{
			temp1.push(quantum.lb.keys[i]);
			temp2.push(quantum.lb.src[i]);
			temp3.push(quantum.lb.titles[i]);
		}			
	}
	quantum.lb.keys = temp1; quantum.lb.src = temp2; quantum.lb.titles = temp3;
	
	quantum.cookie('lightbox', quantum.lb.keys.join(","),{path: "/", domain: 'www.mikekiplingstockphotos.co.uk'});
	$("#fde"+code).css("opacity",1).fadeTo(500,0,quantum.lb.draw);
};

quantum.lb.windowResized = function ()
{
	var vp = quantum.get.viewportDimensions();	
	var lightboxAreaHeight = (quantum.lb.open === true) ? quantum.lb.canvas.open : quantum.lb.canvas.closed;
	if (quantum.explorer.version > 7) 
	{
		$('#mainLightbox').css("top", vp.viewport.height - lightboxAreaHeight);
		$("#mainPageArea").css("height", vp.viewport.height - lightboxAreaHeight -20);
	}
};

quantum.lb.forceClose = function ()
{
	quantum.lb.open = true;
	quantum.lb.toggle();
};

quantum.lb.toggle = function ()
{
	var vp = quantum.get.viewportDimensions(), lightboxAreaHeight = 0;

	quantum.lb.open = !(quantum.lb.open);
	lightboxAreaHeight = (quantum.lb.open === true) ? quantum.lb.canvas.open : quantum.lb.canvas.closed;
	
	if (quantum.explorer.version > 7)
	{
		if (quantum.lb.open) {quantum.lb.draw();}
		$('#mainLightbox').animate({top : vp.viewport.height - lightboxAreaHeight}, 500);
	}
	else
	{
		if (quantum.lb.open) 
		{
			quantum.lb.ieBox.create();
		}
		else
		{
			quantum.lb.ieBox.destroy();
		}	
	}
};

quantum.lb.draw = function()
{
	var html = "", n = 0, totalWidth = 0, newHeight = 110, t = "", code = "", padding = 0, img = {};
	html += "<div id='movingCanvas' style='width:INSERT_WIDTH_HEREpx;'>";
	for (n = 0; n < quantum.lb.keys.length; n++)
	{
		img = new Image();
		img.src = quantum.lb.src[n];
		t = quantum.lb.src[n];
		title = quantum.lb.titles[n];
		id = quantum.lb.keys[n];
		code = quantum.get.refFromFilename();		
		if (img.height > newHeight)
		{
			img.newWidth = parseInt(img.width * (newHeight / img.height),10);
			img.newHeight = newHeight;
			padding = 0;
		}
		else
		{
			img.newWidth = img.width;
			img.newHeight = img.height;
			padding = newHeight - img.height;			
		}		
		totalWidth += (img.newWidth+80); // this is the css left margin!
		html += "<div id='fde" + id + "' class='tomThumbImage' style='width:"+ (img.newWidth) +"px'>";
			html += "<img id='ltc" + id + "' src='" + t +"' title = '" + title + "' alt='"+code+"'";
			html += "style = 'width : " + img.newWidth + "px; height:" + img.newHeight + "px; margin-top:"+padding+"px; border: 1px solid white;'/>";
		html += "<div id='ttc" + id + "' class='tomThumbClose' style='top:"+ (-img.newHeight - 10) +"px'></div>";
		html += "</div>";
		img.src = null;
		img = null;
	}

	html += "</div>";
	html = html.replace(/INSERT_WIDTH_HERE/,parseInt(totalWidth+80,10));
	
	$('#mainLightboxScroller').html(html);
	$('#mainLightboxScroller').find("img").each(function () {$(this).click(function () {quantum.large.click(this);});});	
	$('#mainLightboxScroller').find(".tomThumbClose").each(function (i,elm) {$(elm).bind("click",quantum.lb.closeThumbImage);});
};

quantum.lb.ieBox.create = function()
{
	var vp = quantum.get.viewportDimensions();
	var wide = parseInt((vp.viewport.width) - (vp.viewport.width * 0.2),10);
	var high = parseInt((vp.viewport.height) - (vp.viewport.height * 0.2),10);
	var html = "";

	o = quantum.centrify({height : high, width: wide});
	$("body").append("<div id='ie7Panel' style='width:"+o.width+"px; height:"+o.height+"px; background-color: black; position:absolute; top:"+o.top+"px; left:"+o.left+"px;'></div>");	

	html += "<div id='iePanelClose'></div><div id='ie7LightTitle'>Lightbox</div>";
	html += "<div id='ie7movingCanvas' style='overflow: auto; height:"+(o.height - 60)+"px'>";
	html += quantum.lb.ieBox.innerHTML();
	html += "</div>";
	
	$("#ie7Panel").css("opacity",0.0).html(html);
	$("#iePanelClose").bind("click", quantum.lb.ieBox.destroy);
	$('#ie7Panel').find("img").each(function () {$(this).click(function () {quantum.large.click(this);});});
	$('#ie7Panel').find(".trash1").each(
		function () {$(this).hover(function () {$(this).addClass("trash2");}, function () { $(this).removeClass("trash2");});}).bind("click",quantum.lb.ieBox.closeThumbImage);

	$("#ie7Panel").fadeTo(500,1.0);
};

quantum.lb.ieBox.innerHTML = function ()
{
	var html = "", n = 0,  maxHeight = 0, maxWidth = 0, t = "", code = "", padding = 0, img = {};
	for (n = 0; n < quantum.lb.keys.length; n++)
	{
		img = new Image();
		img.src = quantum.lb.src[n];
		maxHeight = (img.height > maxHeight) ? img.height : maxHeight;
		maxWidth = (img.width > maxWidth) ? img.width : maxWidth;
		img.src = null;
		img = null;
	}
	
	for (n = 0; n < quantum.lb.keys.length; n++)
	{
		img = new Image();
		img.src = quantum.lb.src[n];
		t = quantum.lb.src[n];
		title = quantum.lb.titles[n];
		id = quantum.lb.keys[n];
		code = quantum.get.refFromFilename(t);

		html += "<div id='fde" + id + "' class='tomThumbImage' style=' margin-top:"+(20+maxHeight-img.height)+"px'>";
			html += "<img id='ltc" + id + "' src='" + t +"' title = '" + title + "' alt='"+code+"'";
			html += "style = 'width : " + img.width + "px; height:" + img.height + "px; border: 1px solid white;'/>";
		html += "<div style = 'width : " + img.width + "px; height:32px; margin-top:10px;'><div id='tcn" + id + "' class='trash1'></div></div>";
		html += "</div>";
		img.src = null;
		img = null;
	}
	return html;
};

quantum.lb.ieBox.destroy = function()
{
	quantum.lb.open = false;
	$("#iePanelClose").unbind("click", quantum.lb.ieBox.destroy);
	$("#ie7Panel").fadeTo(500,0.0,function() {$("#ie7Panel").remove();});
};

quantum.lb.closeThumbImage = function (icon)
{
	$(icon).unbind("click", quantum.lb.closeThumbImage);	
	quantum.lb.unlightBulb(icon);
};

quantum.lb.ieBox.closeThumbImage = function (icon)
{
	$(icon).unbind("click", quantum.lb.ieBox.closeThumbImage);
	quantum.lb.unlightBulb(icon);
};

quantum.convert.toRadians = function (d)
{
	return (Math.PI/180 * d);
};

quantum.help.init = function ()
{
	var canvas = document.getElementById('cvHelp');
	if (canvas.getContext)
	{
		quantum.help.ctx = canvas.getContext('2d');
	}
	else 
	{	
		var el = document.getElementById('cvHelp');
		G_vmlCanvasManager.initElement(el);
		quantum.help.ctx = el.getContext('2d');
	}
};

quantum.help.draw = function (html, overflow)
{
	$("#textWidthArea").html(html);
	var width = $("#textWidthArea").width();
	var height = $("#textWidthArea").height();
	var pointerPosition = "";
	var rads = quantum.convert.toRadians;
	var ctx = quantum.help.ctx;
		
	$("#qtmHelp").css("width",width + 40).css("height",height + 40);
	$("#qtmHelpText").css("width",width).css("height",height);

	if	(ctx)
	{
		var radius = quantum.help.radius;
		var top = quantum.help.top;
		var left = quantum.help.left;

		height += radius*2;
		width += radius*5;

		ctx.clearRect(0,0,500,500);
		ctx.save();
		ctx.strokeStyle = ("black");
		ctx.fillStyle = ("gray");
		ctx.lineWidth = (2);

		if (overflow.x && overflow.y)
		{
			ctx.translate(width+10,height+30);
			ctx.transform(-1,0,0,1,0,0);
			ctx.transform(1,0,0,-1,0,0);
		}

		if (overflow.x && !(overflow.y))
		{
			ctx.translate(width+10,0);
			ctx.transform(-1,0,0,1,0,0);				
		}

		if (!(overflow.x) && overflow.y)
		{
			ctx.translate(0,height+30);
			ctx.transform(1,0,0,-1,0,0);
		}
		
		ctx.beginPath();		
		ctx.moveTo(0, 0);
		ctx.lineTo(left + radius, top);
		ctx.arc(width - radius, top + radius, radius, rads(270), rads(0), false);	//top right
		ctx.arc(width - radius, top + height - radius, radius, rads(0), rads(90), false);	//bottom right
		ctx.arc(left + radius, top + height - radius, radius, rads(90), rads(180), false);	//bottom left?
		ctx.lineTo(left, top + radius);	//top left
		ctx.lineTo(0, 0);
		ctx.fill();
		ctx.stroke();
		ctx = null;
	}
	else
	{
		$("#qtmHelpText").css("backgroundColor", "gray");		
	}
};

quantum.help.hide = function()
{
	clearTimeout(quantum.help.id);
	$("#qtmHelp").fadeOut(200);
	$("#qtmHelpText").fadeOut(200);
	$("#qtmHelp").css("width",0).css("height",0);
	$("#qtmHelpText").css("width",0).css("height",0);
	quantum.help.ctx.restore();
};

quantum.help.display = function(html, options)
{
	var target = options.event.currentTarget;
	var cssOffset = {X:0, Y:0};

	cssOffset.X = parseInt($(target).css("margin-left"),10);
	cssOffset.Y = parseInt($(target).css("margin-top"),10);
	cssOffset.X = (isNaN(cssOffset.X)) ? 0 : cssOffset.X;
	cssOffset.Y = (isNaN(cssOffset.Y)) ? 0 : cssOffset.Y;	// required by IE!!!

	var delay = (typeof (options.delay) !== "undefined") ? options.delay : quantum.help.delay;
	var txt = {top : quantum.help.top, left : quantum.help.left};
	var vp = quantum.get.viewportDimensions();
	var render = {y: $(target).position().top + $(target).height() + cssOffset.Y, x : $(target).position().left + $(target).width() + cssOffset.X};
	var overflow = {x : false, y : false};
	var lightboxAreaHeight = (quantum.lb.open === true) ? quantum.lb.canvas.open : quantum.lb.canvas.closed;
	html = (typeof (html) !== "undefined") ? html : "I need help!";
	
	$("#textWidthArea").html(html);


	// Gets the size of the rendered block of text (not the canvas)
	render.width = $("#textWidthArea").width() + 40;
	render.height = $("#textWidthArea").height() + 40;


	if (render.width + $(target).position().left + $(target).width() > vp.viewport.width)
	{
		overflow.x = true;
		render.x = render.x - render.width - $(target).width();
	}
	
	if (render.height + $(target).position().top + $(target).height() > vp.viewport.height - lightboxAreaHeight)
	{
		overflow.y = true;
		render.y = render.y - render.height - $(target).height();
	}	
	// renders the canvas on a Div.
	quantum.help.draw(html, overflow);
		
	$("#qtmHelp").css("top",render.y).css("left",render.x);
	$("#qtmHelpText").html(html).css("top",render.y + txt.top).css("left",render.x + txt.left);
	quantum.help.id = setTimeout(function () {$("#qtmHelp").fadeTo(500,1); $("#qtmHelpText").fadeTo(200,1);} ,delay);
	
};

quantum.help.showTitle = function(options)
{
	var target = options.event.currentTarget;
	
	if (options.previous) 
	{
		quantum.help.display($(target).prev().html(),options);
	}
	else
	{
		quantum.help.display($(target).html(),options);
	}
};

quantum.get.refFromFilename = function (t)
{
	if (typeof (t) === "undefined") {return "";}
	return (t.substr(t.lastIndexOf("/")+1, t.indexOf(".jpg"))).replace(/\.jpg/,"");
};

quantum.get.image = function (c)
{
	return $("#lbx"+c).attr("src");
};

quantum.get.filecode = function(t)
{
	if (typeof (t) === "undefined") {return false;} 	
	if (typeof (t = quantum.get.image(t)) === "undefined") {return false;}
	return(t.substr(t.lastIndexOf("/")+1, t.indexOf(".jpg")));
};

quantum.loader = function (loaded) 
{
	if (typeof(loaded) !== "undefined" && typeof(loaded) === "function")
	{
		loaded();
	}
};

quantum.get.viewportDimensions = function ()
{
	var body = {};
	var viewport = {};
	
	body.width = $("body").width();

	if (typeof window.innerWidth !== 'undefined')
	{
		viewport.width = window.innerWidth;
		viewport.height = window.innerHeight;
	}
	
	else if (typeof(document.documentElement) !== 'undefined' && typeof( document.documentElement.clientWidth) !== 'undefined' && document.documentElement.clientWidth !== 0)
	{
		viewport.width = document.documentElement.clientWidth;
		viewport.height = document.documentElement.clientHeight;
	}

	body.height = viewport.height;
			
	if ($("#mainPageArea").height() > body.height) 
	{
		body.height = $("#mainPageArea").height();
	}
	
	if ($(window).height() > body.height) 
	{
		body.height = $(window).height();
	}
		
	return ({
		viewport	: viewport,
		body		: body,
		X			: $(window).scrollLeft(),
		Y			: $(window).scrollTop()
	});
};

quantum.centrify = function (o)
{
	var vp = quantum.get.viewportDimensions();
	o.left = (vp.viewport.width/2) - (o.width/2) + vp.X;
	o.top = (vp.viewport.height/2) - (o.height/2) + vp.Y; 
	return (o);
};

quantum.blackBox = function (html, obj)
{	
	var container = {height : 100, width: 100, left: 0, top: 0};
	var anim = {type : "tv1", speed : 500, fade : 500};
	var backdrop = "black";
	var style = {background : "black"};
	var vp = quantum.get.viewportDimensions();

	
	if (typeof(obj) === "object")
	{
		if (typeof(obj.style) === "object")
		{
			anim.type = (typeof(obj.style.animType) === "string") ? obj.style.animType : "tv1";			
			backdrop = (typeof(obj.style.background) === "string") ? obj.style.background : "black" ;
		}
		container.height = (typeof(obj.height) === "number") ? obj.height : container.height;
		container.width = (typeof(obj.width) === "number") ? obj.width : container.width;
		anim.speed = (typeof(obj.animSpeed) === "number") ? obj.animSpeed : anim.speed;
		anim.fade = (typeof(obj.fadeSpeed) === "number") ? obj.fadeSpeed : anim.fade;
	}
	
	container = quantum.centrify(container);
	
	if (! document.getElementById("backBlind"))
	{
		$("body").append("<div id='backBlind' class='backBlind' style='width:"+vp.body.width+"px; height:"+vp.body.height+"px;'></div>");	
		$("#backBlind").fadeTo(500,0.8).click(function () {$('#frontBlind').fadeTo(500,0.0).remove(); $(this).fadeTo(500,0.0, function () {$(this).remove();});});
	
		$("body").append("<div id='frontBlind' class='frontBlind' style='background-color:" + backdrop + ";top:"+(vp.viewport.height/2+ vp.Y)+"px;left:"+(vp.viewport.width/2+vp.X)+"px;'></div>");
		$('#frontBlind').html("<div id='glass' class='transDiv'>" + html + "</div>");
	}
	else
	{
		$('#glass').css("opacity",0.0).html(html);
	}

	animSettings = 
	{
		container	: container,
		anim		: anim,
		onFinish	: obj.onFinish
	};
	
	quantum.blackBoxAnimate(animSettings);
};

quantum.blackBoxAnimate = function(obj)
{
	if (obj.anim.type === "tv1")
	{
		$("#frontBlind").animate({
		height : obj.container.height, top: obj.container.top}, 
		obj.anim.speed, 
		function () {$(this).animate({width: obj.container.width, left: obj.container.left},obj.anim.speed, // callback 1 - second expansion
		function () {$("#glass").fadeTo(obj.anim.fade,1.0, obj.onFinish);});						// callback 2 - bring up display and callback to finalise.
		});
	}
	else if (obj.anim.type === "tv2")
	{
		$("#frontBlind").animate(
		{width : obj.container.width, left: obj.container.left}, 
		obj.anim.speed, 
		function () {$(this).animate({height : obj.container.height, top: obj.container.top}, obj.anim.speed,
		function () {$("#glass").fadeTo(obj.anim.fade,1.0,obj.onFinish);});});	
	}
	else
	{
		$("#frontBlind").animate(
		{height : obj.container.height, top: obj.container.top, width : obj.container.width, left: obj.container.left}, 
		obj.anim.speed,
		function () {$("#glass").fadeTo(obj.anim.fade,1.0,obj.onFinish);});
	}
	return false;
};


quantum.large.load = function (hyper, filecode, dbref, title)
{
	var pre = new Image();
	var spacing = 55;
	
	var k = quantum.lb.keys.toString() + ",";
	var icon = (k.indexOf(dbref+",") === -1 ) ? "icon8" : "icon7";
	
	var htm = "<div class='tomThumbClose' style='float:left; left:0px;'></div><div id='bbx"+dbref+"' class='"+icon+"' style='float:right;'></div>";
	title = htm + filecode + "<br />" + title;
	
	pre.onload = function() {
 
	var vp = quantum.get.viewportDimensions();
 	var titleHeight = 5 + $("#titleWidthArea").css("width",this.width).html(title).height();
 	
 	var ratio = this.width / this.height;
 	if (ratio < 0.5 || ratio > 2)
 	{
 		this.width = parseInt(this.width * 1.5,10);
 		this.height = parseInt(this.height * 1.5,10);
 	}
 	
 	
 	if (this.height +  titleHeight > vp.viewport.height)
 	{
 		var newHeight = vp.viewport.height - titleHeight - 100;
 		this.width = parseInt((newHeight/this.height) * this.width,10);
 		this.height = newHeight;
 	}


 	if (this.width + 50 > vp.viewport.width)
 	{
 		var newWidth = vp.viewport.width - 50;
 		this.height = parseInt((newWidth/this.width) * this.height,10);
 		this.width = newWidth;
 	}

		html = "<div class='mkBoxFrame' ";
		html += "style='width:" + (this.width+60) + "px; height:" + (this.height+60) + "px;'>";
			html += "<div class='mkBoxImage' style='width:" + this.width + "px; margin:auto;'>";
				html += "<div style='width:" + this.width + "px; height:" + titleHeight + "px; padding-top:5px'>" + title + "</div>";					
				html += "<div style='width:" + this.width + "px; height:" + this.height + "px;'>";
					html += "<img src='" + hyper + "' style='height:"+this.height+"px; width:"+this.width+"px'/>";	
				html += "</div>";
				html += "<div id='ajaxKeys' style='width:" + this.width + "px;'>";
				html += "Please wait - retrieving keywords: <img src='"+quantum.baseURL+"/loading.gif'/></div>";			
			html += "</div>";
		html += "</div>";
		
		if (this.height > this.width)
		{
			spacing = 75; 				
		}

		quantum.blackBox(html, 
		{
			width: this.width + 50, 
			height: this.height + spacing +titleHeight, 
			
			
			animSpeed: 500,
			fadeSpeed: 500, 
			style: {animType : "tv1"}, 
			onFinish: function () 
				{
					// this should be locally buffered for this page load, at least. 
					$("#ajaxKeys").load(quantum.baseURL + "/stockphotos/ajaxkeys/" + dbref);
					
					$(".icon7").click( function (e) {quantum.lb.unlightBulb(e);} );
					$(".icon8").click( function (e) {quantum.lb.lightBulb(e);} );
					
					$(".tomThumbClose").click(
						function () {
							$('#frontBlind').fadeTo(500,0.0).remove(); 
							$('#backBlind').fadeTo(500,0.0, function () { $('#backBlind').remove();}
					);});					
				}
			}
		);

		pre.onload = null;
		pre = null; 
		return false;	
	};

 pre.src = hyper;
	return false;
};

quantum.squash = function () 
{
	var maxHeight = 0, maxWidth = 0;


	if (document.getElementById("generalResults") && quantum.explorer.version > 7)
	{
		$("body").css("overflow","hidden");
	}
	$("#thumbCanvas").find(".tTxt").each(function() {
		$("#textWidthArea").html($(this).html());
		if ($("#textWidthArea").height() > 34)
		{
			$(this).next().html("[more...]");
		}
	});

	$(".tTxt").height("2.4em");
	$("#thumbCanvas").find("img").each(function () 
	{
		maxHeight = (this.height > maxHeight) ? this.height : maxHeight;
		maxWidth = (this.width > maxWidth) ? this.width : maxWidth;
	});
	$(".thumbframe").css("height",maxHeight + 100);

};

quantum.wait.please = function ()
{
	var vp = quantum.get.viewportDimensions();
	var container = quantum.centrify({height : 50, width: 50, left: 0, top: 0});
	var html = "";

 	if (! document.getElementById("backBlind"))
	{
		html = "<div id='backBlind' class='backBlind' style='width:"+vp.body.width+"px; height:"+vp.body.height+"px;'>";
		html += "<div style='position: absolute; z-index: 500; width:100px; height:100px; top:"+container.top+"px; left:"+container.left+"px; color: white; font-size:40px;'>";
		html += "<img src='"+quantum.baseURL+"/loading.gif'/>";
		html += "</div>";		
		html += "</div>";		
		$("body").append(html);	
		$("#backBlind").fadeTo(500,0.8);
	}
};

quantum.wait.done = function ()
{
 	if (document.getElementById("spinner"))
 	{
 		$("body").css("overflow","auto");
 		$("#spinner").remove();
 	}
};

$(function () {quantum.wait.done();});		// yes, this really does need to run here!

window.onload = function()
{
	var start = new Date();	var end = {};
	var q = [];

	quantum.lb.cookie = (typeof (quantum.cookie("lightbox")) === "string") ? quantum.cookie("lightbox") : null;
	quantum.lb.keys = (quantum.lb.cookie === null || quantum.lb.cookie.length === 0 ) ? [] : quantum.lb.cookie.split(",");
	quantum.help.init();
	if (quantum.lightboxEnabled) {quantum.lb.init();}	
	quantum.squash();

	if(quantum.explorer.version < 7){$(document).pngFix();}
	
	
	if (document.getElementById("featuredImageText"))
	{
		$("#featuredImageText").html("featured image: " + uk.co.mikekiplingstockphotos.featured.replace(".jpg",""));
		$("#featuredImageText").animate({"opacity" : 1}, 1500);
		$("#featuredImageStrip").animate({"opacity" : 0.5}, 500);
	}

	$(window).resize(function() { quantum.lb.windowResized();});
		
	$("img[id^='pix']").click(function (e) {quantum.large.click(this,e); return false;});
	$(".icon1").bind("click",quantum.lb.lightBulb);
	$(".icon1").mouseover(function (e) {quantum.help.display("Add image to lightbox.",{event : e, caller: this});});

	$(".icon2").bind("click",quantum.lb.unlightBulb);
	$(".icon2").mouseover(function (e) {quantum.help.display("Remove this image",{event : e, caller: this});});

	$(".icon3").click(function (e) {quantum.wait.please();});
	$(".icon3").mouseover(function (e) {quantum.help.display("Buy a print to frame",{event : e, caller: this});});
	
	$(".icon4").mouseover(function (e) {quantum.help.display("Get a quotation for licenced use",{event : e, caller: this});});
	$(".icon4").click(function (e) {quantum.wait.please();});

	$(".icon5").mouseover(function (e) {quantum.help.display("Open the lightbox",{event : e, caller: this});});
	$(".icon6").mouseover(function (e) {quantum.help.display("Find similar images",{event : e, caller: this});});

	$(".icon5").click(quantum.lb.toggle);
	$(".icon6").click(function (e) {quantum.wait.please();});
	$(".icon1, .icon2, .icon3,.icon4, .icon5, .icon6, .elipses").mouseleave(function (e) {quantum.help.hide();});
	
	$(".elipses").mouseover(function (e) {quantum.help.showTitle({event : e, caller: this, previous: true});});

	$("#mainLightboxTitle").click(quantum.lb.toggle);	
	
	end = new Date();
	
	$("#timers").html($("#timers").html() + ". DOM adjusted in: " + (end.getTime() - start.getTime()) /1000 + " secs.");

};


/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */

/**
 * Create a cookie with the given name and value and other optional parameters.
 *
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Set the value of a cookie.
 * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
 * @desc Create a cookie with all available options.
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Create a session cookie.
 * @example $.cookie('the_cookie', null);
 * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
 * used when the cookie was set.
 *
 * @param String name The name of the cookie.
 * @param String value The value of the cookie.
 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
 * If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
 * If set to null or omitted, the cookie will be a session cookie and will not be retained
 * when the the browser exits.
 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
 * require a secure protocol (like HTTPS).
 * @type undefined
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */

/**
 * Get the value of a cookie with the given name.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String name The name of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */

quantum.cookie = function(name, value, options) {
 if (typeof value !== 'undefined') { // name and value given, set cookie
 options = options || {};
 if (value === null) {
 value = '';
 options.expires = -1;
 }
 var expires = '';
 if (options.expires && (typeof options.expires === 'number' || options.expires.toUTCString)) {
 var date;
 if (typeof options.expires === 'number') {
 date = new Date();
 date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
 } else {
 date = options.expires;
 }
 expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
 }
 var path = options.path ? '; path=' + (options.path) : '';
 var domain = options.domain ? '; domain=' + (options.domain) : '';
 var secure = options.secure ? '; secure' : '';
 document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
 } else { // only name given, get cookie
 var cookieValue = null;
 if (document.cookie && document.cookie !== '') {
 var cookies = document.cookie.split(';');
 for (var i = 0; i < cookies.length; i++) {
 var cookie = jQuery.trim(cookies[i]);
 // Does this cookie string begin with the name we want?
 if (cookie.substring(0, name.length + 1) === (name + '=')) {
 cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
 break;
 }
 }
 }
 return cookieValue;
 }
};


/**
 * --------------------------------------------------------------------
 * jQuery-Plugin "pngFix"
 * Version: 1.1, 11.09.2007
 * by Andreas Eberhard, andreas.eberhard@gmail.com
 *                      http://jquery.andreaseberhard.de/
 *
 * Copyright (c) 2007 Andreas Eberhard
 * Licensed under GPL (http://www.opensource.org/licenses/gpl-license.php)
 */
eval(function(p,a,c,k,e,r){e=function(c){return(c<62?'':e(parseInt(c/62)))+((c=c%62)>35?String.fromCharCode(c+29):c.toString(36))};if('0'.replace(0,e)==0){while(c--)r[e(c)]=k[c];k=[function(e){return r[e]||e}];e=function(){return'([237-9n-zA-Z]|1\\w)'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('(s(m){3.fn.pngFix=s(c){c=3.extend({P:\'blank.gif\'},c);8 e=(o.Q=="t R S"&&T(o.u)==4&&o.u.A("U 5.5")!=-1);8 f=(o.Q=="t R S"&&T(o.u)==4&&o.u.A("U 6.0")!=-1);p(3.browser.msie&&(e||f)){3(2).B("img[n$=.C]").D(s(){3(2).7(\'q\',3(2).q());3(2).7(\'r\',3(2).r());8 a=\'\';8 b=\'\';8 g=(3(2).7(\'E\'))?\'E="\'+3(2).7(\'E\')+\'" \':\'\';8 h=(3(2).7(\'F\'))?\'F="\'+3(2).7(\'F\')+\'" \':\'\';8 i=(3(2).7(\'G\'))?\'G="\'+3(2).7(\'G\')+\'" \':\'\';8 j=(3(2).7(\'H\'))?\'H="\'+3(2).7(\'H\')+\'" \':\'\';8 k=(3(2).7(\'V\'))?\'float:\'+3(2).7(\'V\')+\';\':\'\';8 d=(3(2).parent().7(\'href\'))?\'cursor:hand;\':\'\';p(2.9.v){a+=\'v:\'+2.9.v+\';\';2.9.v=\'\'}p(2.9.w){a+=\'w:\'+2.9.w+\';\';2.9.w=\'\'}p(2.9.x){a+=\'x:\'+2.9.x+\';\';2.9.x=\'\'}8 l=(2.9.cssText);b+=\'<y \'+g+h+i+j;b+=\'9="W:X;white-space:pre-line;Y:Z-10;I:transparent;\'+k+d;b+=\'q:\'+3(2).q()+\'z;r:\'+3(2).r()+\'z;\';b+=\'J:K:L.t.M(n=\\\'\'+3(2).7(\'n\')+\'\\\', N=\\\'O\\\');\';b+=l+\'"></y>\';p(a!=\'\'){b=\'<y 9="W:X;Y:Z-10;\'+a+d+\'q:\'+3(2).q()+\'z;r:\'+3(2).r()+\'z;">\'+b+\'</y>\'}3(2).hide();3(2).after(b)});3(2).B("*").D(s(){8 a=3(2).11(\'I-12\');p(a.A(".C")!=-1){8 b=a.13(\'url("\')[1].13(\'")\')[0];3(2).11(\'I-12\',\'none\');3(2).14(0).15.J="K:L.t.M(n=\'"+b+"\',N=\'O\')"}});3(2).B("input[n$=.C]").D(s(){8 a=3(2).7(\'n\');3(2).14(0).15.J=\'K:L.t.M(n=\\\'\'+a+\'\\\', N=\\\'O\\\');\';3(2).7(\'n\',c.P)})}return 3}})(3);',[],68,'||this|jQuery||||attr|var|style||||||||||||||src|navigator|if|width|height|function|Microsoft|appVersion|border|padding|margin|span|px|indexOf|find|png|each|id|class|title|alt|background|filter|progid|DXImageTransform|AlphaImageLoader|sizingMethod|scale|blankgif|appName|Internet|Explorer|parseInt|MSIE|align|position|relative|display|inline|block|css|image|split|get|runtimeStyle'.split('|'),0,{}))
