/**
 * jquery.expose 1.0.0 - Make HTML elements stand out
 * 
 * Copyright (c) 2009 Tero Piirainen
 * http://flowplayer.org/tools/expose.html
 *
 * Dual licensed under MIT and GPL 2+ licenses
 * http://www.opensource.org/licenses
 *
 * Launch  : June 2008
 * Version : 1.0.0 - Sun Feb 15 2009 13:55:48 GMT-0000 (GMT+00:00)
 */
(function($){function fireEvent(opts,name,self){var fn=opts[name];if($.isFunction(fn)){try{return fn.call(self);}catch(error){if(opts.alert){alert("Error calling expose."+name+": "+error);}else{throw error;}return false;}}return true;}var mask=null;var exposed,conf=null;$.expose={getVersion:function(){return[1,0,0];},getMask:function(){return mask;},getExposed:function(){return exposed;},getConf:function(){return conf;},isLoaded:function(){return mask&&mask.is(":visible");},load:function(els,opts){if(this.isLoaded()){return this;}if(els){exposed=els;conf=opts;}else{els=exposed;opts=conf;}if(!els||!els.length){return this;}if(!mask){mask=$('<div id="'+opts.maskId+'"></div>').css({position:'absolute',top:0,left:0,width:'100%',height:$(document).height(),display:'none',opacity:0,zIndex:opts.zIndex});$("body").append(mask);$(document).bind("keypress.unexpose",function(evt){if(evt.keyCode==27){$.expose.close();}});if(opts.closeOnClick){mask.bind("click.unexpose",function(){$.expose.close();});}}if(fireEvent(opts,"onBeforeLoad",this)===false){return this;}$.each(els,function(){var el=$(this);if(!/relative|absolute/i.test(el.css("position"))){el.css("position","relative");}});els.css({zIndex:opts.zIndex+1});if(opts.color){mask.css("backgroundColor",opts.color);}if(!this.isLoaded()){mask.css({opacity:0,display:'block'}).fadeTo(opts.loadSpeed,opts.opacity,function(){fireEvent(opts,"onLoad",$.expose);});}return this;},close:function(){var self=this;if(!this.isLoaded()){return self;}if(fireEvent(conf,"onBeforeClose",self)===false){return self;}mask.fadeOut(conf.closeSpeed,function(){exposed.css({zIndex:conf.zIndex-1});fireEvent(conf,"onClose",self);});}};$.prototype.expose=function(conf){if(!this.length){return this;}var opts={alert:true,maskId:'exposeMask',loadSpeed:'slow',closeSpeed:'fast',closeOnClick:true,zIndex:9998,opacity:0.8,color:'#333'};if(typeof conf=='string'){conf={color:conf};}$.extend(opts,conf);$.expose.load(this,opts);return this;};})(jQuery);
/*!
 * jquery.overlay 1.0.1. Overlay HTML with eyecandy.
 * 
 * Copyright (c) 2009 Tero Piirainen
 * http://flowplayer.org/tools/overlay.html
 *
 * Dual licensed under MIT and GPL 2+ licenses
 * http://www.opensource.org/licenses
 *
 * Launch  : March 2008
 * Version : 1.0.1 - Wed Feb 18 2009 05:18:24 GMT-0000 (GMT+00:00)
 */
(function($){var instances=[];function fireEvent(opts,name,self,arg){var fn=opts[name];if($.isFunction(fn)){try{return fn.call(self,arg);}catch(error){if(opts.alert){alert("Error calling overlay."+name+": "+error);}else{throw error;}return false;}}return true;}function Overlay(el,opts){var self=this;var trigger=null;var w=$(window);var jq=opts.target||el.attr("rel");var o=jq?$(jq):null;if(!o){o=el;}else{trigger=el;}var bg=o.attr("overlay");if(!bg){bg=o.css("backgroundImage");bg=bg.substring(bg.indexOf("(")+1,bg.indexOf(")"));o.css("backgroundImage","none");o.attr("overlay",bg);}if(!bg){throw"background-image CSS property not set for overlay element: "+jq;}bg=bg.replace(/\"/g,"");if(opts.preload){$(window).load(function(){setTimeout(function(){var img=new Image();img.src=bg;},2000);});}var oWidth=o.outerWidth({margin:true});var oHeight=o.outerHeight({margin:true});var img=$('<img src="'+bg+'"/>');img.css({border:0,position:'absolute'}).width(oWidth).hide();$('body').append(img);if(trigger){trigger.bind("click.overlay",function(e){self.load(e.pageY-w.scrollTop(),e.pageX-w.scrollLeft());return e.preventDefault();});}if(!opts.close||!o.find(opts.close).length){o.prepend('<div class="close"></div>');opts.close="div.close";}var closeButton=o.find(opts.close);$.extend(self,{load:function(top,left){if(self.isOpened()){return self;}if(opts.oneInstance){$.each(instances,function(){this.close();});}if(fireEvent(opts,"onBeforeLoad",self)===false){return self;}top=top||opts.start.top;left=left||opts.start.left;var toTop=opts.finish.top;var toLeft=opts.finish.left;if(toTop=='center'){toTop=Math.max((w.height()-oHeight)/2-30,0);}if(toLeft=='center'){toLeft=Math.max((w.width()-oWidth)/2,0);}if(!opts.start.absolute){top+=w.scrollTop();left+=w.scrollLeft();}if(!opts.finish.absolute){toTop+=w.scrollTop();toLeft+=w.scrollLeft();}img.css({top:top,left:left,width:opts.start.width,zIndex:opts.zIndex}).show();img.animate({top:toTop,left:toLeft,width:oWidth},opts.speed,function(){o.css({position:'absolute',top:toTop,left:toLeft});var z=img.css("zIndex");closeButton.add(o).css("zIndex",++z);o.fadeIn(opts.fadeInSpeed,function(){fireEvent(opts,"onLoad",self);});});return self;},getBackgroundImage:function(){return img;},getContent:function(){return o;},getTrigger:function(){return trigger;},isOpened:function(){return o.is(":visible");},getConf:function(){return opts;},close:function(){if(!self.isOpened()){return self;}if(fireEvent(opts,"onClose",self)===false){return self;}if(img.is(":visible")){img.hide();o.hide();}return self;},getVersion:function(){return[1,0,0];},expose:function(){img.expose();}});closeButton.bind("click.overlay",function(){self.close();});w.bind("keypress.overlay",function(evt){if(evt.keyCode==27){self.close();}});if(opts.closeOnClick){w.bind("click.overlay",function(evt){if(!o.is(":visible, :animated")){return;}var target=$(evt.target);if(target.attr("overlay")){return;}if(target.parents("[overlay]").length){return;}self.close();});}}jQuery.prototype.overlay=function(conf){var api=this.eq(typeof conf=='number'?conf:0).data("overlay");if(api){return api;}var w=$(window);var opts={start:{top:Math.round(w.height()/2),left:Math.round(w.width()/2),width:0,absolute:false},finish:{top:'center',left:'center',absolute:false},speed:'normal',fadeInSpeed:'fast',close:null,oneInstance:true,closeOnClick:true,preload:true,zIndex:9999,target:null,alert:true};if($.isFunction(conf)){conf={onBeforeLoad:conf};}$.extend(true,opts,conf);this.each(function(){var instance=new Overlay($(this),opts);instances.push(instance);$(this).data("overlay",instance);});return this;};})(jQuery);
/*
 * Forwart website frontend for jQuery JavaScript Library
 *
 * Copyright (C) 2003-2011
 * Peter Arts, Forwart
 * http://www.forwart.nl
 *
 * Date: 2011-10-31
 * Revision: 0003
 */

var tipTimer;
$(document).ready(function() {
	
	$('#searchq').focus(function() {
		$('#qlContact').hide();
		$('#searchoperators').fadeIn(300);
		//setTimeout(function() { $('#searchoperators').fadeOut(300); }, 3000);
	});
	
	$('#searchq').blur(function() {
		
		$('#searchoperators').fadeOut(300, function() {
			$('#qlContact').show();
		});
	});
	
	parseToggleInfo();
	
	initContentTabs();
	
	$('div#newsapp div.news_filter a.toggle').click(function(e) {
		e.preventDefault();
		var frame = $(this).parents('div.news_filter');
		if (!frame.hasClass('active')) {
			if ($.browser.msie  && parseInt($.browser.version) == 7) {
				$('div#newsapp div.news_filter.active').
				removeClass('active').find('div.filter_content').hide();
				frame.addClass('active').find('div.filter_content').show();
			} else {
				$('div#newsapp div.news_filter.active').
				addClass('tmp-active').removeClass('active'). 
				find('div.filter_content').stop(true, true).slideUp(function() {
					$(this).parents('div.news_filter').removeClass('tmp-active');
				});
				frame.addClass('active').find('div.filter_content').stop(true, true).slideDown();
			}
			var filterId = $(this).attr('data-filter-id');
			var ts = Math.round((new Date()).getTime() / 100000);
			var ncid = $('div#newsapp').attr('data-ncid');
			$.get('/post.xml?form_type=dynews-get-articles&filter=' + filterId + '&v=1&ncid=' + ncid + '&ts=' + ts, function(xmlData){
		 		var html = $('html', xmlData).text();
		 		frame.find('div.filter_content').html(html);
		 	});
		}
	});
	
	$('div#newsapp_large div.news_filter a.toggle').click(function(e) {
		e.preventDefault();
		if ($(this).hasClass('active')) {
			return;
		}
		$('div#newsapp_large div.news_filter.active').removeClass('active');
		$(this).parents('div.news_filter').addClass('active');
		var frame = $('#largeFilterContent');
		frame.fadeOut(200);
		var filterId = $(this).attr('data-filter-id');
		var ts = Math.round((new Date()).getTime() / 100000);
		var ncid = $('div#newsapp_large').attr('data-ncid');
		$.get('/post.xml?form_type=dynews-get-articles&filter=' + filterId + '&v=2&ncid=' + ncid + '&ts=' + ts, function(xmlData){
	 		var html = $('html', xmlData).text();
	 		frame.html(html).fadeIn(300);
	 	});
	});
	
	$.infoTip = $('<div id="infotip"></div>');
	$.infoTip.mouseenter(function() {
		clearTimeout(tipTimer);
	}).mouseleave(function() {
		tipTimer = setTimeout('hideInfoTip()', 300);
	});
	$('#homecols').append($.infoTip);
	$('#homecols ul.infotip li').mouseenter(function() {
		
		clearTimeout(tipTimer);
		
		$.content = $('<p>' + $(this).find('p.info').html() + '</p>');
		$.title = $('<h3>' + $(this).attr('title') + '</h3>');
		$.img = $(this).find('img');
		if ($.img.length == 1) {
			$.img = $.img.clone();
			$.content.addClass('img');
		}
		$.infoTip.html('');
		$.infoTip.append($.title);
		$.infoTip.append($.content);
		if ($.img.length == 1) {
			$.infoTip.append($.img);
		}
		
		// position
		var left = 170;
		var height = 43; //53;
		var offset = 100; // 98;
		if ($(this).parents('div.homecol').hasClass('center')) {
			left = 470;
			height = 22;
			offset = 110;
		}
		
		var currentIndex = $(this).prevAll().length;
		currentIndex = (currentIndex * height) - offset;
		
		$.infoTip.css({left: left + 'px', top: currentIndex + 'px'});
		
		$.infoTip.show();
		
	}).mouseleave(function() {
		tipTimer = setTimeout('hideInfoTip()', 300);
	});
	
	initTeamMembers();
	
	if ($('div#wrapper').hasClass('tpl_groenselekt')) {
		$('#subsiteChoice li:not(.active)').mouseenter(function() {
			$(this).addClass('hover');
		}).mouseleave(function() {
			$(this).removeClass('hover');
		});
		$('#subsiteChoice').mouseenter(function() {
			$(this).find('p').fadeIn();
			$(this).find('ul').addClass('hover');
			$(this).find('li:not(.active)').slideDown(200);
		}).mouseleave(function() {
			$(this).find('p').fadeOut();
			$(this).find('ul').removeClass('hover');
			$(this).find('li:not(.active)').slideUp(200);
		});
	}
	
	/*$('div#qlHome img').bind('afterShow', function() {
		console.log('afterShow');
	})*/
});

function initTeamMembers() {
	
	$('div.teammember').mouseenter(function() {
		$(this).addClass('active');
	}).mouseleave(function() {
		$(this).removeClass('active');
	});
	
	$('div.teammember').each(function() {
		if ($(this).find('div.detail').length == 1) {
			$(this).addClass('expand').click(function(e) {
				if (!$(this).hasClass('collapse')) {
					$(this).find('div.detail').slideDown();
					$(this).addClass('collapse');
				}
			});
			var link = $('<a class="icon" href="#"><span title="Details weergeven" class="plus">+</span><span title="Details verbergen" class="min">&ndash;</span></a>');
			link.click(function(e) {
				e.preventDefault();
				if ($(this).parents('div.teammember').hasClass('collapse')) {
					// collapse
					$(this).parents('div.teammember').removeClass('collapse').find('div.detail').slideUp();
					e.stopPropagation();
				} else {
					// expand
					// nothing to do, will be done by div handler
				}
			});
			$(this).prepend(link);
		}
	});
	
	
	/*$('div.teammember.expand a').click(function(e) {
		e.stopPropagation();
	});*/
}

function hideInfoTip() {
	$.infoTip = $('div#infotip');
	if ($.infoTip.length == 1) {
		$.infoTip.stop(true, true).fadeOut();
	}
}

function initContentTabs() {
	$.nav = $('<div class="content_tab_nav"></div>');
	$('div#content div.content_tabs').prepend($.nav);
	var zi = 80;
	$('div.content_tabs div.tab').each(function() {
		var title = $(this).find('h3.title');
		if (title.length == 1) {
			title.hide();
			title = title.find('a');
			var tc = $(this);
			$.toggleNav = title.clone();
			$.toggleNav.click(function(e) {
				e.preventDefault();
				if (!tc.hasClass('active')) {
					$('div#content div.content_tabs div.tab.active').hide().removeClass('active');
					tc.show();
					tc.addClass('active');
					$.nav.find('div.navcontainer.active').removeClass('active');
					$(this).parents('div.navcontainer').addClass('active');
					var tc_container = tc.find('div.tab_content');
					if (tc_container.length == 0) {
						tc_container = $('<div class="tab_content loading">Bezig met laden...</div>');
						tc.append(tc_container);
						var pid = $(this).attr('data-pid');
						if (typeof pid == 'undefined') {
							return;
						} else if (isNaN(pid)) {
							return;
						}
						$.get('/post.xml?form_type=childlist-getchilddetail&pid=' + pid + '&img=all', function(xmlData){
					 		var html = $('html', xmlData).text();
					 		tc_container.html(html).removeClass('loading');
					 		initLightbox();
					 		initTeamMembers();
					 	});
					} // else: dummy - content already loaded
				}
			});
			
			$.navContainer = $('<div class="navcontainer"><span class="corner l"></span><span class="corner r"></span></div>');
			$.navContainer.find('span.corner.l').after($.toggleNav);
			$.navContainer.css('z-index', zi);
			zi--;
			$.nav.append($.navContainer);
		}
	});
	
	setTimeout(function() { $.nav.find('a:first').trigger('click'); }, 600);
}

function parseToggleInfo() {
	$('div#content div.toggle_info a.toggle_more').click(function(e) {
		e.preventDefault();
		var container = $(this).parents('div.toggle_info');
		if (container.length != 1) return;
		var childs = container.find('div.detail');
		if ($(this).hasClass('expand')) {
			$(this).removeClass('expand').addClass('collapse').html('<strong>&ndash</strong> ' + $(this).attr('title')); // sluiten
			childs.stop(true, true).slideDown();
		} else {
			$(this).removeClass('collapse').addClass('expand').html('<strong>+</strong> ' + $(this).attr('title'));
			childs.stop(true, true).slideUp();
		}
	});
}

function nav(url) {
	url = URLDecode(url);
	window.location.href = url;
}

function nav_new(url) {
	window.open(url);
}

function URLDecode(encoded)
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while
   return plaintext;
}

function externalLinks() { 
	if (!document.getElementsByTagName) return; 
 	var anchors = document.getElementsByTagName("a"); 
	for (var i=0; i<anchors.length; i++) { 
   		var anchor = anchors[i]; 
   		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "blank") {
	   		anchor.target = "_blank";
		} 
	}
}

function replaceText(text){
  while(text.lastIndexOf("&") > 0){
      text = text.replace('&', '[i-Stats]');
  }
  return text;
}

var web_referrer = replaceText(document.referrer);
      
//istat = new Image(1,1);
//istat.src = "/template/terpstra/js/fwstats/counter.php?sw="+screen.width+"&sc="+screen.colorDepth+"&referer="+web_referrer+"&page="+location.href;

/*
	Lightbox JS: Fullsize Image Overlays 
	by Lokesh Dhakar - http://www.huddletogether.com
	For more information on this script, visit:
	http://huddletogether.com/projects/lightbox/
	Licensed under the Creative Commons Attribution 2.5 License - http://creativecommons.org/licenses/by/2.5/
	(basically, do anything you want, just leave my name and link)
*/
// If you would like to use a custom loading image or close button reference them in the next two lines.
var loadingImage = '/template/mertens-groep/img/loading.gif';		
var closeButton = '/template/mertens-groep/img/close.gif';		
function getPageScroll(){
	var yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}
	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}
function getPageSize(){
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}
function pause(numberMillis) {
	var now = new Date();
	var exitTime = now.getTime() + numberMillis;
	while (true) {
		now = new Date();
		if (now.getTime() > exitTime)
			return;
	}
}
function getKey(e){
	if (e == null) { // ie
		keycode = event.keyCode;
	} else { // mozilla
		keycode = e.which;
	}
	key = String.fromCharCode(keycode).toLowerCase();
	if(key == 'x'){ hideLightbox(); }
}
function listenKey () {	document.onkeypress = getKey; }
function showLightbox(objLink)
{
	// prep objects
	var objOverlay = document.getElementById('overlay');
	var objLightbox = document.getElementById('lightbox');
	var objCaption = document.getElementById('lightboxCaption');
	var objImage = document.getElementById('lightboxImage');
	var objLoadingImage = document.getElementById('loadingImage');
	var objLightboxDetails = document.getElementById('lightboxDetails');
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	// center loadingImage if it exists
	if (objLoadingImage) {
		objLoadingImage.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - objLoadingImage.height) / 2) + 'px');
		objLoadingImage.style.left = (((arrayPageSize[0] - 20 - objLoadingImage.width) / 2) + 'px');
		objLoadingImage.style.display = 'block';
	}
	// set height of Overlay to take up whole page and show
	objOverlay.style.height = (arrayPageSize[1] + 'px');
	objOverlay.style.display = 'block';
	// preload image
	imgPreload = new Image();
	imgPreload.onload=function(){
		objImage.src = objLink.href;
		// center lightbox and make sure that the top and left values are not negative
		// and the image placed outside the viewport
		var lightboxTop = arrayPageScroll[1] + ((arrayPageSize[3] - 35 - imgPreload.height) / 2);
		var lightboxLeft = ((arrayPageSize[0] - 20 - imgPreload.width) / 2);
		objLightbox.style.top = (lightboxTop < 0) ? "0px" : lightboxTop + "px";
		objLightbox.style.left = (lightboxLeft < 0) ? "0px" : lightboxLeft + "px";
		objLightboxDetails.style.width = imgPreload.width + 'px';
		if(objLink.getAttribute('title')){
			objCaption.style.display = 'block';
			//objCaption.style.width = imgPreload.width + 'px';
			objCaption.innerHTML = objLink.getAttribute('title');
		} else {
			objCaption.style.display = 'none';
		}
		// A small pause between the image loading and displaying is required with IE,
		// this prevents the previous image displaying for a short burst causing flicker.
		if (navigator.appVersion.indexOf("MSIE")!=-1){
			pause(250);
		} 
		if (objLoadingImage) {	objLoadingImage.style.display = 'none'; }

		// Hide select boxes as they will 'peek' through the image in IE
		selects = document.getElementsByTagName("select");
        for (i = 0; i != selects.length; i++) {
                selects[i].style.visibility = "hidden";
        }
		objLightbox.style.display = 'block';
		// After image is loaded, update the overlay height as the new image might have
		// increased the overall page height.
		arrayPageSize = getPageSize();
		objOverlay.style.height = (arrayPageSize[1] + 'px');
		// Check for 'x' keypress
		listenKey();
		return false;
	}
	imgPreload.src = objLink.href;
}
function hideLightbox()
{
	// get objects
	objOverlay = document.getElementById('overlay');
	objLightbox = document.getElementById('lightbox');
	// hide lightbox and overlay
	objOverlay.style.display = 'none';
	objLightbox.style.display = 'none';
	// make select boxes visible
	selects = document.getElementsByTagName("select");
    for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}
	// disable keypress listener
	document.onkeypress = '';
}
function initLightbox()
{
	if (!document.getElementsByTagName){ return; }
	var anchors = document.getElementsByTagName("a");
	// loop through all anchor tags
	for (var i=0; i<anchors.length; i++){
		var anchor = anchors[i];

		if (anchor.getAttribute("href") && (anchor.getAttribute("rel") == "imgpopover")){
			anchor.onclick = function () {showLightbox(this); return false;}
		}
	}
	var objBody = document.getElementsByTagName("body").item(0);
	// create overlay div and hardcode some functional styles (aesthetic styles are in CSS file)
	var objOverlay = document.createElement("div");
	objOverlay.setAttribute('id','overlay');
	objOverlay.onclick = function () {hideLightbox(); return false;}
	objOverlay.style.display = 'none';
	objOverlay.style.position = 'absolute';
	objOverlay.style.top = '0';
	objOverlay.style.left = '0';
	objOverlay.style.zIndex = '90';
 	objOverlay.style.width = '100%';
	objBody.insertBefore(objOverlay, objBody.firstChild);
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	var imgPreloader = new Image();
	imgPreloader.onload=function(){
		var objLoadingImageLink = document.createElement("a");
		objLoadingImageLink.setAttribute('href','#');
		objLoadingImageLink.onclick = function () {hideLightbox(); return false;}
		objOverlay.appendChild(objLoadingImageLink);
		var objLoadingImage = document.createElement("img");
		objLoadingImage.src = loadingImage;
		objLoadingImage.setAttribute('id','loadingImage');
		objLoadingImage.style.position = 'absolute';
		objLoadingImage.style.zIndex = '150';
		objLoadingImageLink.appendChild(objLoadingImage);
		imgPreloader.onload=function(){};	//	clear onLoad, as IE will flip out w/animated gifs
		return false;
	}
	imgPreloader.src = loadingImage;
	var objLightbox = document.createElement("div");
	objLightbox.setAttribute('id','lightbox');
	objLightbox.style.display = 'none';
	objLightbox.style.position = 'absolute';
	objLightbox.style.zIndex = '100';	
	objBody.insertBefore(objLightbox, objOverlay.nextSibling);
	var objLink = document.createElement("a");
	objLink.setAttribute('href','#');
	objLink.setAttribute('title','');
	objLink.onclick = function () {hideLightbox(); return false;}
	objLightbox.appendChild(objLink);
	var objImage = document.createElement("img");
	objImage.setAttribute('id','lightboxImage');
	objLink.appendChild(objImage);
	var objLightboxDetails = document.createElement("div");
	objLightboxDetails.setAttribute('id','lightboxDetails');
	objLightbox.appendChild(objLightboxDetails);
	var objCaption = document.createElement("div");
	objCaption.setAttribute('id','lightboxCaption');
	objCaption.style.display = 'none';
	objLightboxDetails.appendChild(objCaption);
	var objKeyboardMsg = document.createElement("div");
	objKeyboardMsg.setAttribute('id','keyboardMsg');
	objKeyboardMsg.innerHTML = '<a href="#" onclick="hideLightbox(); return false;">[ X ]</a>';
	objLightboxDetails.appendChild(objKeyboardMsg);
}
// Function found at Simon Willison's weblog - http://simon.incutio.com/
function addLoadEvent(func)
{	
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
    	window.onload = func;
	} else {
		window.onload = function(){
		oldonload();
		func();
		}
	}

}

addLoadEvent(initLightbox);	// run initLightbox onLoad
addLoadEvent(externalLinks);
