//By http://simon.incutio.com/archive/2004/05/26/addLoadEvent
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

function setExternalLinks(bNewWindow, sClassName) {
	if (bNewWindow || sClassName) {
		
		var links = document.getElementsByTagName('a');
		
		for (i = 0; i < links.length; i++) {
			//Only display if it is an external link and it isn't an image link			
			if (links[i].hostname.indexOf(location.hostname) == -1 && links[i].firstChild.nodeName != 'IMG' && links[i].protocol != 'mailto:') {
				
				//Set new window
				if (bNewWindow) {
					links[i].onclick = function() { window.open(this.href); return false; }
				}

				//Set class name
				if (sClassName) {
					if (links[i].className) {
						links[i].className = links[i].className + ' ' + sClassName;
					} else {
						links[i].className = sClassName;
					}
				}
			}
		}
	}
}



function createImagePopups(sClassName, iVspace, iHspace) {
	if (!sClassName) { sClassName = 'imagelink'; }
	if (!iVspace) { iVspace = 0; }
	if (!iHspace) { iHspace = 0; }

	for (i = 0; i < document.links.length; i++) {
		//Only create function for image links, and only for links with the specified class name (if given, otherwise run for all image links)
		if ((!sClassName || document.links[i].className == sClassName)) {
			//Pre-load the image (to make the dimensions available)
			var eImg = new Image();
			eImg.src = document.links[i].href;

			//on click create the window.open() function on the link tag			
			document.links[i].onclick = function() {
				var eImg = new Image();
				eImg.src = this.href;

				window.open(this.href, this.firstChild.id, 'width=' + (eImg.width + iHspace) + ',height=' + (eImg.height + iVspace));
				return false;
			}
			
			//add onfocus="blur"
			//document.links[i].onfocus = function() { blur(); }
		}
	}
}