// JavaScript by iCREW // dependencies: prototype.lite.js

function init() {
	initNavigation()
	initPortalBlocks();
}

function initNavigation() {
	var target = document.getElementsByClassName("nav");
	for(var i = 0; i < target.length; i++) {
		var ddelement = target[i].lastChild;
		ddelement.style.position="absolute";
		ddelement.style.zIndex="102";
		ddelement.firstChild.style.display="none";
		registerNavEvent(target[i], i+1);
	}
}

function registerNavEvent(target, nr) {
	if (document.addEventListener) { // DOM Level 2 Event Registration
			target.addEventListener("mouseover",mouseOver,false);
			target.addEventListener("mouseout",mouseOut,false);
		} 
		else { // Microsoft Event Registration
			target.attachEvent('onmouseover',mouseOver);
			target.attachEvent('onmouseout',mouseOut);
		}
	function mouseOver() {expandNav(target, nr);}
	function mouseOut() {collapseNav(target, nr);}
}

function expandNav(target, nr) {
	var ddelement = target.lastChild;
	var ulelement = ddelement.firstChild;
	ddelement.firstChild.style.display="block";
	var anchor = target.firstChild.lastChild;
	if ((ulelement.hasChildNodes) && (nr == "1" || "2" || "3")) { anchor.style.background="#001703 url('/media/navicon1b.gif') no-repeat scroll center right" }
	if ((ulelement.hasChildNodes) && (nr == "4")) { anchor.style.background="#F0BD0D url('/media/navicon2b.gif') no-repeat scroll center right" }	
}

function collapseNav(target, nr) {
	var ddelement = target.lastChild;
	ddelement.firstChild.style.display="none";
	var anchor = target.firstChild.lastChild;
	if (nr == "1" || "2" || "3") { anchor.style.background="#001703 url('/media/navicon1.gif') no-repeat scroll center right" }
	if (nr == "4") { anchor.style.background="#F0BD0D url('/media/navicon2.gif') no-repeat scroll center right" }	
}


function initPortalBlocks() {
	var portalBlocks = document.getElementsByClassName("portalBlock");
	for(var i = 0; i < portalBlocks.length; i++) {
		portalBlocks[i].className = "portalBlock js";
		var targetBlock = $(portalBlocks[i]);
		registerPortalBlockEvent(targetBlock);
	}
}

function registerPortalBlockEvent(target) {
	if (document.addEventListener) { // DOM Level 2 Event Registration
			target.addEventListener("mouseover",mouseOver,false);
			target.addEventListener("mouseout",mouseOut,false);
			target.addEventListener("click",mouseClick,false);
		} 
		else { // Microsoft Event Registration
			target.attachEvent('onmouseover',mouseOver);
			target.attachEvent('onmouseout',mouseOut);
			target.attachEvent('onclick',mouseClick);
		}
	function mouseOver() {overPortalBlock(target);}
	function mouseOut() {outPortalBlock(target);}
	function mouseClick() {clickPortalBlock(target);}
}

function overPortalBlock(portalBlock) {
	var target = $(portalBlock);
	target.className = "portalBlockHover js";
}

function outPortalBlock(portalBlock) {
	var target = $(portalBlock);
	target.className = "portalBlock js";
}

function clickPortalBlock(portalBlock) {
	if (portalBlock.hasChildNodes()) {
		var children = portalBlock.childNodes;
		var target = children[1].firstChild.firstChild.href;
		parent.location=target;
		}
		else {
			alert("JS error; verwijder witregels in broncode");
		}
}
