var templinks	= false;
var links		= new Array();
var current	 	= false;
var active 		= false;
var timeout 	= false;

var flash 		= false;

/**
 * Timeout interval
 *
 */
var interval = 5000;

/**
 * Zet een element op actief
 *
 */
function set_active(el) {
	if(el != active || active === false) {
		if(active !== false) {
			links[active].className = '';
		}
	
		active = el;
		current = el;
	
		links[el].className = 'active';
		
		flash.set_active(current);
	}
}

/**
 * Doorloop alle doelgroepen
 *
 */
function loop() {
	if(current < (links.length - 1))
		current++;
	else
		current = 0;

	flash.set_active(current);
	set_active(current);

	timeout = window.setTimeout('loop()', interval);
}

/**
 * Functie om de Flash movie aangemaakt met AC_RunActiveContent.js
 * te kunnen aanspreken (bug in AC_RunActiveContent.js)
 */
function getSWF(movieName) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	} else {
		if(document[movieName].length != undefined){
			return document[movieName][1];
		}

		return document[movieName];
	}
}


window.onload = function() {
	templinks 	= document.getElementById('topmenu').getElementsByTagName('a');
	
	for(var i = 0; i < templinks.length; i++) {
		if (i!=0) {
			links[i-1] = templinks[i];
		}
	}
	
	flash 	= getSWF('header');

	if(links.length && flash) {
		current = links.length - 1;

		for(var i = 0; i < links.length; i++) {
			links[i].onmouseover = function() {
				if(timeout) {
					window.clearTimeout(timeout);
					timeout = false;
				}
				if (this.rel != '') {
					flash.set_active(this.rel);
				}
				set_active(this.rel);
			}

			links[i].onmouseout = function() {
				timeout = window.setTimeout('loop()', interval);
			}
		}

		loop();
	}
}