function startList(){
	if (document.all && document.getElementById) {
		navRoot = document.getElementById("nav");
		if (navRoot) {
			for (i=0; i<navRoot.childNodes.length; i++) {
				node = navRoot.childNodes[i];
				if (node.nodeName=="LI") {
					node.onmouseover = function() {
						this.className += " over";
					}
					node.onmouseout = function() {
						this.className = this.className.replace(" over", "");
					}
				}
			}
		}
	}
}

function doHeadings() {
	var h3 = document.getElementsByTagName("A");
	var img;
	var cls;
	var sel;

	for (var i = 0; i < h3.length; i++) {
		if (h3[i].parentNode.tagName == "H2") {
			cls = h3[i].className != "" ? "-"+h3[i].className : "";
			if (cls != "") {
				sel = h3[i].innerHTML;
			}
			h3[i].innerHTML = "<img id=\"" + h3[i].innerHTML + "\" src=\"images/headings/" + h3[i].innerHTML + ".gif\" alt=\"" + h3[i].innerHTML + "\" border=\"0\">";
		}
	}
	init();
	setCurrent(document.getElementById(sel));
}

var preloads = new Object();
var current_action = "";

function setCurrent(img) {
	if (old_img = document.getElementById(current_action)) {
		old_img.src = preloads['n' + current_action].src;
	}
	current_action = img.id;
	img.src = preloads['o'+img.id].src;
}

function doOver(img) {
	if (img.id != current_action) {
		img.src = preloads['o'+img.id].src;
	}
}

function doOut(img) {
	if (img.id != current_action) {
		img.src = preloads['n'+img.id].src;
	}
}

//
// from: http://www.quirksmode.org/js/newmouseover.html
//

function init() {
	if (document.getElementById) {
		var x = document.getElementById('menulist').getElementsByTagName('IMG');
	} else if (document.all) {
		var x = document.all['mouseovers'].all.tags('IMG');
	} else {
		return;
	}

	for (var i = 0; i < x.length; i++) {
		if (x[i].parentNode.tagName == "A") {
			preloads['n' + x[i].id] = new Image;
			preloads['n' + x[i].id].src = 'images/headings/'+ x[i].id + '.gif';
			preloads['o' + x[i].id] = new Image;
			preloads['o' + x[i].id].src = 'images/headings/'+ x[i].id + '-selected.gif';

			x[i].onclick = function () {setCurrent(this);}
			x[i].onmouseover = function () {doOver(this);}
			x[i].onmouseout = function () {doOut(this);}
			x[i].parentNode.onfocus = function() {this.blur();}
		}
	}
}

function doBanner() {
	var fo = new FlashObject("images/swf/topbanner.swf", "topbanner", 748, 86, "7", "#1e354c", true);
	if (fo) {
		fo.write("headline");
	}
}

Event.observe(window, 'load', doHeadings);
//Event.observe('window', 'load', 'init', false);
Event.observe(window, 'load', doBanner);
Event.observe(window, 'load', startList);

// id voor verschillende timers
var timer = 0;

// ImageLoop plugin
var loopcounter = 0;
var loop = new Array();
function displayImageLoop(imageloop) {
	var result = '';
	result += '<div class="sideloopwrapper" style="height: 153px; background-color: #ffffff;">';
	for (var idx = 0; idx < imageloop.length; idx++) {
		var timerid = ++timer;
		
		loop.push('loop'+loop.length);
		
		result += '<div class="sideimagebox" id="loop'+ (loop.length - 1) +'" style="display: none">';
		
		if (imageloop[idx]['url']) {
			result += '<a href="'+imageloop[idx]['url']+'">';
		}
		
		result += '<img src="' + imageloop[idx]['image'] +'" alt="' + imageloop[idx]['text'] + '">';
		
		if (imageloop[idx]['url']) {
			result += '</a>';
		}
		
		if (imageloop[idx]['timer'] == 'true') {
			result += '<span class="sideimageboxtimer" id="timer'+timerid+'">'+getTimeString(imageloop[idx]['timezone'])+'</span>';
			var updatefunction = 'updateImageBoxTimer("timer'+timerid+'","' + imageloop[idx]['timezone'] + '")';
			setInterval(updatefunction, 500);
		}
		result += '<span class="sideimageboxtitle">' + imageloop[idx]['text'] + '</span>';
		result += '<br style="clear: both">';
		result += '</div>';	
	}
	result += '</div>';
	document.write(result);
	
	if (imageloop.length) {
		for (var idx = 1; idx < loop.length; idx++) {
			Element.hide(loop[idx]);
		}
		new Effect.Appear('loop0');
	}
	setTimeout(updateImageLoop, 2500);
}

function updateImageLoop() {
	var oldcounter = loopcounter;
	loopcounter = (loopcounter < (loop.length - 1)) ? loopcounter + 1 : 0;
	new Effect.Fade(loop[oldcounter], {queue: 'front'});
	new Effect.Appear(loop[loopcounter], {queue: 'end'});
	setTimeout(updateImageLoop, 9000);
}

// ImageSideBox plugin
function displayImageBox(title, location, link, timed, timezoneoffset) {
	var result = '';
	var timerid = ++timer;
	
	if (link) {
		result += '<a href="'+link+'">';
	}


	result += '<img src="'+location+'" alt="'+title+'">';

	if (link) {
		result += '</a>';
	}

	if (timed == true) {
		result += '<span class="sideimageboxtimer" id="timer'+timerid+'">'+getTimeString(timezoneoffset)+'</span>';
		var updatefunction = 'updateImageBoxTimer("timer'+timerid+'","'+timezoneoffset+'")';
		setInterval(updatefunction, 1000);
	}

	result += '<span class="sideimageboxtitle">'+title+'</span>';
	result += '<br style="clear: both">';
	document.write(result);
}

function getTimeString(timezoneoffset) {
    var here = new Date();
    var ts = here.getTime() + ( here.getTimezoneOffset() * 60000 );
    var there = new Date( ts + ( 3600000 * timezoneoffset ) );
    var seconds = there.getSeconds();
    seconds = (seconds < 10) ? '0'+seconds : seconds;
    var minutes = there.getMinutes();
    minutes = (minutes < 10) ? '0'+minutes : minutes;
    var hours = there.getHours();
    hours = (hours < 10) ? '0'+hours : hours;
    return hours+':'+minutes+':'+seconds;
}

function updateImageBoxTimer(id, timezoneoffset) {
	if ($(id)) {
		$(id).innerHTML = getTimeString(timezoneoffset);
	}
}
