/***********************************************************************

Author:     4rn0
URL:        http://www.4rn0.nl

***********************************************************************/


if (document.addEventListener) { document.addEventListener('DOMContentLoaded',init,null); }
/*@cc_on @*/ /*@if (@_win32) document.write("<script defer src=http://www.supr.nl/js/supr.init.js><"+"/script>"); /*@end @*/   
window.onload = init;

function init() {

	if (arguments.callee.done) {
		return;
	}
	
	arguments.callee.done = true;
	
	if (typeof(document.getElementById) == 'undefined') {
		document.getElementById = function(id) {
			return document.all[id];
		};
	}

	initAnchorEvents();	
	initImageNavigation();
	resizeWindow();

	window.onresize = resizeWindow;

}

function resizeWindow() {

	var height = (self.innerHeight ? self.innerHeight : (document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : (document.body ? document.body.clientHeight : 0)));
	document.getElementById('container').className = (height < 529 || self.screen.width < 1024) ? 'smallScreen' : '';
	
}

function initAnchorEvents() {
	
	var anchors = document.getElementsByTagName('A');
	for (var i = 0; i < anchors.length; i++) {
		
		if (anchors[i].getAttribute('rel') == 'external') {
			anchors[i].setAttribute('target', '_blank');
		}

	}
	
}

function initImageNavigation() {
	
	if (document.getElementById('imageNavigation')) {
		
		var imageNavigation = document.getElementById('imageNavigation');
		cleanWhiteSpace(imageNavigation);
		
		var anchors = imageNavigation.getElementsByTagName('A');
		for (var i = 0; i < anchors.length; i++) {
			anchors[i].onmouseover = setActiveImage;
			anchors[i].onmouseout = resetActiveImage;
			anchors[i].onclick = setMainImage;
		}

	}
	
}

function setActiveImage() {
	var node = (this.parentNode.nodeName == 'DT') ? this.parentNode.nextSibling.nextSibling : this.parentNode.previousSibling.previousSibling;
	if (node && node.getElementsByTagName('A')[0]) {
		node.getElementsByTagName('A')[0].className = 'active';
	}
}

function resetActiveImage() {
	var node = (this.parentNode.nodeName == 'DT') ? this.parentNode.nextSibling.nextSibling : this.parentNode.previousSibling.previousSibling;
	if (node && node.getElementsByTagName('A')[0]) {
		node.getElementsByTagName('A')[0].className = '';
	}
}

function setMainImage() {
	
	if (this.href) {
		
		removeThumbEvents();
		
		document.getElementById('mainImage').className = 'active';
		document.getElementById('mainImage').style.backgroundImage = 'url(' + this.href + ')';
	
		resetActiveImages();
		
		var thisAnchor = (this.parentNode.nodeName == 'DT') ? this : this.parentNode.previousSibling.previousSibling.getElementsByTagName('A')[0];
		thisAnchor.className = 'active';
		
		var description = (this.parentNode.nodeName == 'DT') ? this.parentNode.nextSibling : this.parentNode.previousSibling;
		description.setAttribute('id', 'active');
	
		this.blur();
		return false;
		
	}
	
}

function resetActiveImages() {

	var anchors = document.getElementById('imageNavigation').getElementsByTagName('A');
	for (var i = 0; i < anchors.length; i++) {
		anchors[i].className = '';
	}
	
	if (document.getElementById('active')) {
		document.getElementById('active').setAttribute('id', '');
	}

}

function removeThumbEvents() {
	var anchors = document.getElementById('imageNavigation').getElementsByTagName('A');
	for (var i = 0; i < anchors.length; i++) {
		if (anchors[i].parentNode.nodeName == 'DD') {
			anchors[i].onmouseover = null;
			anchors[i].onmouseout = null;
		}
	}
}

function cleanWhiteSpace(element) {
	for (var i = 0; i < element.childNodes.length; i++) {
		var node = element.childNodes[i];
		if (node.nodeType == 3 && !/\S/.test(node.nodeValue)) {
			node.parentNode.removeChild(node);
		}
	}
}

