// browser sniffer
function Browser(){
  this.uA = navigator.userAgent.toLowerCase();
  this.aN = navigator.appName.toLowerCase();
  this.iE = this.aN.indexOf('microsoft') != -1 ? 1 : 0;
  this.mac =  this.uA.indexOf('mac') != -1 ? 1 : 0;
  this.win = this.uA.indexOf('windows') != -1 ? 1 : 0;
  this.safari =  this.uA.indexOf('webkit') != -1 ? 1 : 0;
  this.opera =  this.uA.indexOf('opera') != -1 ? 1 : 0;    
  this.mozilla = this.aN.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.winIE6Down = this.winIE && parseInt(this.uA.split('msie ')[1].substring(0,1)) <= 6 ? 1: 0;
  this.macIE = this.iE && this.mac ? 1 : 0;
};
var browser = new Browser();

// addStyle
function addStyle(selector,properties){
  if (document.styleSheets) {
    var s = document.getElementsByTagName('STYLE');
    if (s.length == 0){
      var sheet = document.createElement('style');
      sheet.setAttribute('type','text/css');
      document.getElementsByTagName('HEAD')[0].appendChild(sheet);}
    if (browser.winIE){
      var lastSheet = document.styleSheets[document.styleSheets.length - 1];
      lastSheet.addRule(selector, properties);}
    else {var lastSheet = s[0];
      lastSheet.appendChild(document.createTextNode(selector + ' { ' + properties + ' }'));}
  	}
};
addStyle('#tabs #agendal','display:none;');
addStyle('.drempel','display:none;');

// 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();
  }
}

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";}
};

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';
      };
    }
  }
};

//search toggle value
var setSearch = function(id){
if(!document.getElementById(id)) return false;
var j = document.getElementById(id);
var key = j.value;
	j.onfocus=function(){
		if(j.value==key)j.value='';
	}
	j.onblur=function(){		
		if (j.value=='')j.value=key;
	}
};	

//layout case switcher 
var currentLarge = 1;
function checkWindowWidth() {
// volgende regel aangepast met dank aan Kees Noyens 
// het bestaan van document.body testen alvorens de waarde van document.body.clientWidth te bepalen 
 var smaller = ((document.documentElement.clientWidth > 0 && document.documentElement.clientWidth < 960) || (document.body && document.body.clientWidth < 960));
// var smaller = ((document.documentElement.clientWidth > 0 && document.documentElement.clientWidth < 960) || document.body.clientWidth < 960);
	if (smaller) {
		if (currentLarge == 0){
			return;
		}
		currentLarge = 0;
		//document.getElementsByTagName('body')[0].className = 'small';
		getEl('framework').className = 'small';
	}
	else {
		if (currentLarge == 1){
			return;
		}
		currentLarge = 1;
		//document.getElementsByTagName('body')[0].className = '';
		getEl('framework').className = '';
		}
	}

function init() {
	if (arguments.callee.done) return;
	arguments.callee.done = true;
	if (_timer) clearInterval(_timer);
	
	checkWindowWidth();
	if (getEl('nav'))active('nav');
	if (getEl('keuzes'))setKeuzes();
	if (getEl('colors'))setColor();
	if (getEl('tabs'))setTab();
	if (getEl('subnavlist'))setupSubNav();
	if (getEl('livesearch'))setSearch('livesearch');
	
	try {document.execCommand('BackgroundImageCache', false, true);} catch(e) {};
};
if (document.addEventListener) {
	document.addEventListener("DOMContentLoaded", init, false);
}
// for Internet Explorer (using conditional comments)
/*@cc_on @*/
var dummy = (location.protocol == "https:") ? "//:" : "javascript:void(0)";
/*@if (@_win32)document.write("<script id=__ie_onload defer src='" + dummy + "'><\/script>");
var script = document.getElementById("__ie_onload");
script.onreadystatechange = function() {    
	if (this.readyState == "complete") {        
		init();  
	}
};
/*@end @*/

if (/WebKit/i.test(navigator.userAgent)) {  
var _timer = setInterval(function() {        
	if (/loaded|complete/.test(document.readyState)) {            
		clearInterval(_timer); init();}}, 10);
};

window.onload = init;

window.onresize = function(){
	checkWindowWidth();
};

//New window voor plattegrond (photoreality)
  function launchnewwin()
  {
    var w = screen.availWidth;
    var h = screen.availHeight;

    if (navigator.userAgent.indexOf("Opera") == -1) {
      if (navigator.appName.indexOf("Microsoft") != -1) {
         // Adjust settings for Internet Explorer 6
         w -= 10; h -= 59;
      } else {
         // Adjust for Firefox 1 and 1.5 (and hopefully others...)
         w -= 6; h -= 54;
      }
    } else {
      // Adjust for Opera (8.5)
      w -= 10; h -= 49;
    }

    // Calculate maximum window size (inner) for this screen, keeping screen aspect ratio
    var aspectRatio = 1016/708;   // exact measures of flash movie
    if ((h*aspectRatio) > w) {
       // +0.9 zorgt dat afronding altijd naar boven gebeurd
       h=parseInt((w/aspectRatio)+0.9);
    } else {
       w=parseInt((h*aspectRatio)+0.9);
    }

    // top & left is voor Opera (v8.5) wat screenX & screenY voor Netscape Navigator 4 was.
    // resizable kan aangezet indien gewenst, maar resulteert ook in verschijnen van windows startbalk bij gebruik van IE
    features = 'width='+w+',height='+h+',resizable=0,top=0,left=0,screenX=0,screenY=0,fullscreen=0,directories=0,location=0,menubar=0,scrollbars=0,status=0,toolbar=0';
    newwin = window.open("http://www.plattegronduvt.nl/photo.html","newwindow",features);

    if(javascript_version > 1.0)
    {
      // vertraag een beetje voor IE4 welke problemen geeft bij focus op een net geopende window
      setTimeout('newwin.focus();',250);
    }
  };




