/**
 * Fragment Highlight version 0.1
 * this JavaScript highlight code is copyright 2003 by David Dorward; http://dorward.me.uk
 * this JavaScript library is copyright 2002 by Gavin Kistner and Refinery; www.refinery.com
 */

var baseURL = document.location.host;
var fragHLed = '';
var fragExclude = ('header');

function AddClass (obj, cName) {
	KillClass(obj, cName);
	return obj.className += (obj.className.length > 0 ? ' ' : '') + cName;
}

function KillClass (obj, cName) {
	return obj.className = obj.className.replace(new RegExp("^" + cName + "\\b\\s*|\\s*\\b" + cName + "\\b", 'g'), '');
}

Array.prototype.search = function (myVariable) {
	for (x in this)
		if (x == myVariable)
			return true;
	return false;
}

function fragHLload () {
	fragHL(location.hash.substring(1));
}

function fragHL (frag) {
	if (fragHLed.length > 0 && document.getElementById(fragHLed)) {
		KillClass(document.getElementById(fragHLed), 'highlight');
	}
	if (frag.length > 0 && document.getElementById(frag) && frag != "top") {
		fragHLed = frag;
		AddClass(document.getElementById(frag), 'highlight');
	}
}

function fragHLlink () {
	if (document.getElementsByTagName) {
		var an = document.getElementsByTagName("a");
		for (var i = 0; i < an.length; i++) {
			if (an.item(i).getAttribute("href").indexOf("#") >= 0) {
				var fragment = an.item(i).getAttribute("href").substring(an.item(i).getAttribute("href").indexOf("#") + 1);
				if (fragExclude.search(fragment)) {
					var evn = "fragHL('" + fragment + "')";
					var fun = new Function('e', evn);
					an.item(i).onclick = fun;
				}
			}
		}
	}
}

function extLinks () {
	if (document.getElementsByTagName) {
		var an = document.getElementsByTagName("a");
		for (var i = 0; i < an.length; i++) {
			var obj = an.item(i);
			if (obj.href.indexOf(baseURL) == -1 && obj.href && obj.className.indexOf("ongemarkeerd")) {
				obj.rel = "external";
				obj.title = "External site: " + obj.title;
				mark = document.createElement("img");
				mark.src = "/english/img/exit.png";
				mark.alt = " (external site)";
				mark.width = "11";
				mark.height = "10";
				mark.className = "exit";
				obj.appendChild(mark);
			}
		}
	}
}

function createTopButton () {
	var t = document.getElementById("block");
	var div = document.createElement("div");
	div.id = "naar-boven";
	t.appendChild(div);
	for (var u = 0; u < 2; u++) {
		var a = document.createElement("a");
		a.className = "off";
		a.href = "#top";
		a.title = "To top";
		//a.onclick = "return scrollToTop();"
		if (u == 0)
			a.id = "top-links";
		else
			a.id = "top-rechts";
		div.appendChild(a);
		var img = document.createElement("img");
		img.alt = "To top";
		img.src = "/english/img/top.png";
		img.width = "17";
		img.height = "17";
		a.appendChild(img);
	}
}

function adjustTopButton () {
	var tl = document.getElementById("top-links");
	var tr = document.getElementById("top-rechts");
	var s = document.body.scrollTop || (document.documentElement && document.documentElement.scrollTop);
	if (s > 0) {
		tl.className = tr.className = "on";
		var pos = 0;
		if (document.getElementById("naar-boven").currentStyle)
			pos = document.getElementById("naar-boven").getElementsByTagName("a")[1].currentStyle.position;
		if (pos == "absolute") {
			var docHeight = document.getElementById("top").clientHeight;
			var winHeight = document.documentElement.clientHeight;
			var p = s + winHeight - 113 + "px";
			tl.style.top = tr.style.top = p;
		}
	}
	else
		tl.className = tr.className = "off";
}

window.onload = function () {
	fragHLload();
	fragHLlink();
	extLinks();
	if (document.getElementById && document.documentElement) {
		createTopButton();
		setInterval("adjustTopButton()", 100);
	}
};
