// browser sniffer
function Browser(){
  this.iE = navigator.appName.toLowerCase().indexOf('microsoft') != -1 ? 1 : 0;
  this.mac =  navigator.userAgent.toLowerCase().indexOf('mac') != -1 ? 1 : 0;
  this.win = navigator.userAgent.toLowerCase().indexOf('windows') != -1 ? 1 : 0;
  this.safari =  navigator.userAgent.toLowerCase().indexOf('safari') != -1 ? 1 : 0;
  this.opera =  navigator.userAgent.toLowerCase().indexOf('opera') != -1 ? 1 : 0;
  this.mozilla = navigator.appName.toLowerCase().indexOf('netscape') != -1 && !this.safari ? 1 : 0;
  this.winMozilla = this.mozilla && this.win ? 1 : 0;
  this.winIE = this.iE && this.win && !this.opera ? 1 : 0;
  this.macIE = this.iE && this.mac ? 1 : 0;
}
var browser = new Browser();

// handy timer
var animTimer;
animTimer = [];

// framebuster
if (window!= top)top.location.href=location.href;

// getElementById
function getEl(el){
  return document.getElementById(el);
}

//top nav
var activeMenu;
var active;
active = function(id) {
var nav = document.getElementById(id);
if (!nav){return;}
var e = nav.getElementsByTagName("LI");
for (var i=0; i<e.length; i++) {
	e[i].onmouseover=function() {
     if (activeMenu){activeMenu.onmouseout();}
     activeMenu = this;
		this.className+=" active";}
	e[i].onmouseout=function() {
		this.className=this.className.replace(/active/g, '');}
	}
	navFocus(id,true);
}

//focus nav on tab
var navFocus;
navFocus = function(id,mouseOverMenu){
  var subnav = document.getElementById(id);
   if (!subnav){return;}
   var list = subnav.getElementsByTagName("A");
   for (var i = 0; i < list.length; i++){
      var e = list[i];
      if (e.parentNode.parentNode.id == id){
		  if (mouseOverMenu){
		    e.onfocus = function(){this.parentNode.onmouseover();}
		  }
		  else {
		    e.onfocus = function(){this.parentNode.onclick();}
		  }
      }
    }
	if (list.length == 0){return;}
   var lastSub = list[list.length-1];
   if (lastSub.parentNode.parentNode.id == id){return;}
    lastSub.onblur = function(){
     this.parentNode.parentNode.parentNode.onmouseout();
  }
}

// tabbed simple
if (document.getElementById && document.getElementsByTagName && document.createElement) {
	document.write('<style type="text/css">#tabs #agenda{ display: none; }</style>');
}
function setTab() {
	var as = document.getElementById('toggle').getElementsByTagName('a');
	for (var i = 0; i < as.length; i++) {
		as[i].onclick = function() {
			toggle(this);
			return false;
		}
	}
	toggle(as[0]);
}
function toggle(s) {
	var id = s.href.match(/#(\w.+)/)[1];
	s.parentNode.parentNode.parentNode.className = id;
	  if(id == 'nieuws') {
	  	document.getElementById('agenda').style.display = 'none';
	  	document.getElementById(id).style.display = 'block';
	  }
	  else if(id == 'agenda') {
	  	document.getElementById('nieuws').style.display = 'none';
	  	document.getElementById(id).style.display = 'block';
	 }
}

// setClassName
function setClassName(el,className){
  if (!className){
    return;
  }
  if (el.getAttribute('className') != null){
    el.setAttribute('className',className);
  }
  else {
    el.setAttribute('class',className);
  }
}

// getClassName
function getClassName(el){
  var cN;
  if (el.getAttribute('className') != null){
    cN = el.getAttribute('className');
  }
  else {
    cN = el.getAttribute('class');
  }
  return cN ? cN : '';
}

// set external links
var setExternalLinks = function(){
  var localDomain = (location.href.split('/')[2]);

    var localExtensionsInNewWindow = Array('doc','xls','pdf');

    var list = document.getElementsByTagName('A');
    for (var i = 0; i < list.length; i++){
      var aEl = list[i];
      var aElHref = aEl.href;

      // check for extensions
      var extension = (aElHref.substring(aElHref.length - 4,aElHref.length)).toLowerCase();
      var foundExtension = false;
      for (var j = 0; j < localExtensionsInNewWindow.length; j++){
        if (extension == '.' + localExtensionsInNewWindow[j]){
          foundExtension = true;
          break;
        }
      }

      // open in new window if conditions are right
      if ((aElHref.split('/')[2] != localDomain && aElHref.indexOf('mailto:') == -1 && aElHref.indexOf('javascript:') == -1) || foundExtension){
        aEl.onclick = function(){
        window.open(this.href);
        return false;
      }
    }
  }
};

//hover form buttons
var setHover = function(){
var hbg = document.getElementsByTagName('input');
	for (var i = 0; i < hbg.length; i++) {
		if(hbg[i].getAttribute('type')=='submit' || hbg[i].getAttribute('type')=='reset' || hbg[i].getAttribute('type')=='button' || hbg[i].getAttribute('type')=='file') {
			hbg[i].onmouseover=function(){
				this.className = 'buttonhover';
			}
			hbg[i].onmouseout=function(){
				this.className = 'button';
				}
			}
		}
	}
//color test
var setColor = function(){
var c = document.getElementById('colors');
var d = c.getElementsByTagName('A');
	for (var i = 0; i < d.length; i++) {
		d[i].onmouseover=function(){
			document.getElementsByTagName('body')[0].className = this.parentNode.className;
		}
	}
}
//keuzes div:hover for IE
var setKeuzes = function(){
var k = document.getElementById('keuzes');
var l = k.getElementsByTagName('DIV');
	for (var i = 0; i < l.length; i++) {
	if (l[i].className=='block'){
		l[i].onmouseover=function(){
			this.className = 'active';
			//this.className += ' active';
		}
		l[i].onmouseout=function(){
			this.className = 'block';
			//this.className = this.className.replace(/\s*active/, "");
			}
		}
	}
}

//toggle
function showhide(id) {
	var el = document.getElementById(id).style;
	  if(el.display == "none") {
	  el.display = "block";}
	  else if(el.display == "block") {
	  el.display = "none";}
}
//layout case switcher
var currentLarge = 1;
function checkWindowWidth() {
	var smaller = ((document.documentElement.clientWidth > 0 && document.documentElement.clientWidth < 960) || document.body.clientWidth < 960);
	if (smaller) {
		if (currentLarge == 0){
			return;
		}
		currentLarge = 0;
		if (e = document.getElementById('framework'))
			e.className = 'small';
//		document.getElementsByTagName('body')[0].className = 'small';
//		getEl('framework').className = 'small';
	}
	else {
		if (currentLarge == 1){
			return;
		}
		currentLarge = 1;
		if (e = document.getElementById('framework'))
			e.className = '';
//		document.getElementsByTagName('body')[0].className = '';
//		getEl('framework').className = '';
		}
	}
/*
function setupSubNav() {
  var n = getEl('subnavlist');
  var nl = n.getElementsByTagName('span');
  for (var i = 0, l = nl.length; i < l; i++) {
    if (nl[i].parentNode.getElementsByTagName("ul").length > 0) {
      nl[i].onclick = function() {
        if (this.parentNode.className.indexOf('active') > -1)
          this.parentNode.className = 'haschildren';
        else
          this.parentNode.className = 'haschildren active';
      };
    }
  }
}
*/


function initIEnav()
{
	checkWindowWidth();
	if (getEl('nav'))active('nav');
	if (getEl('keuzes'))setKeuzes();
	if (getEl('colors'))setColor();
	if (getEl('tabs'))setTab();
	if (getEl('subnavlist'))setupSubNav();
}

if (typeof addEvent == 'function') {
	addEvent( window, 'load', initIEnav );
} else {
	window.onload = initIEnav;
}	

window.onresize = function(){
	checkWindowWidth();
}
