// 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();

//incl. .js
document.write('<script type="text/javascript" src="scripts/formcheck.js"><\/script>');
document.write('<script type="text/javascript" src="scripts/jquery.js"><\/script>');
document.write('<script type="text/javascript" src="scripts/thickbox.js"><\/script>');
document.write('<script type="text/javascript" src="scripts/flashObject.js"><\/script>');
document.write('<script type="text/javascript" src="scripts/motiongallery.js"><\/script>');



// framebuster
if (window!= top)top.location.href=location.href;

// getElementById
function getEl(id){
  return document.getElementById(id);
}

// 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 : '';
};

//stripe table

//top nav
var activeMenu;
 active = function(id) {
 var nav = document.getElementById(id);
 var hbg = document.getElementById('content').getElementsByTagName('select');
 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";
		if (browser.iE){
			for (var i = 0; i < hbg.length; i++) {		
			hbg[i].style.visibility = 'hidden';
			}
		}
	}
	e[i].onmouseout=function() {
		this.className=this.className.replace(/active/g, '');
		if (browser.iE){
			for (var i = 0; i < hbg.length; i++) {		
				hbg[i].style.visibility = 'visible';
				}
			}
		}
	}
	navFocus(id,true);
};

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();
   }
 };
 
//sub nav
var activeSubMenu;
var activeSub;
activeSub = function(id) {
var nav = document.getElementById(id);
var hbg = document.getElementById('container').getElementsByTagName('select');
if (!nav){return;}
var e = nav.getElementsByTagName("LI");
for (var i=0; i<e.length; i++) {
	e[i].onmouseover=function() {
     if (activeSubMenu){activeSubMenu.onmouseout();}
     activeSubMenu = this;
		this.className+=" active";
		if (browser.iE){
			for (var i = 0; i < hbg.length; i++) {		
			hbg[i].style.visibility = 'hidden';}
		}
	}
	e[i].onmouseout=function() {
		this.className=this.className.replace(/active/g, '');
		if (browser.iE){
			for (var i = 0; i < hbg.length; i++) {		
			hbg[i].style.visibility = 'visible';}
			}
		}
	}
};

//hover form buttons
var setHover = function(){
if(!document.getElementsByTagName('input')) return false;
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';
			}
		}
	}
};

//object images
var setObject = function(){
if(!document.getElementById('motioncontainer')) return false;
var c = document.getElementById('trueContainer');
var d = c.getElementsByTagName('A');
	for (var i = 0; i < d.length; i++) {		
		d[i].onclick=function(){
			for (var i = 0; i < d.length; i++) {
				d[i].childNodes[0].style.borderBottom = "3px solid #836E2C";
			}
			this.childNodes[0].style.borderBottom = "3px solid #F1A000";
			//getEl('objimg').src=this.href;
			$("#objimg").html("<a class='thickbox' href='"+this.href + "'><img class='rightimg border' src='"+this.childNodes[0].getAttribute('src')+"' width='156'  alt='' /></a>");
      	showTentoonstelling(getEl(this.className));
			TB_init();
      return false;
		}
	}
};

function showFirstTentoonstelling() {
 	var getImg =  $("#trueContainer a img:first").attr("src");
	var getUrl =  $("#trueContainer a:first").attr("href");
  $("#motiontxt div:first").show();
  $("#trueContainer a img:first").css("border-bottom","3px solid #F1A000");
  $("#objimg").html("<a class='thickbox' href='"+getUrl+"'><img class='rightimg border' src='"+getImg+"' width='156' alt='' /></a>");
}

// Show a tentoonstelling
function showTentoonstelling(tentoonstelling) {
  var motionTxt = getEl('motiontxt');
  var tmp = 0;
  for(var i = 0; i < motionTxt.childNodes.length; i++) {
    if (motionTxt.childNodes[i].nodeType == 1) {
      motionTxt.childNodes[i].style.display = 'none';
    }
  }
  if (tentoonstelling != null) {
    tentoonstelling.style.display = 'block';
  }
}

/*#object #motioncontainer a img{ border-bottom: 3px solid #836E2C; }
#object #motioncontainer a:hover img{ border-bottom: 3px solid #F1A000; }*/

//search toggle value
var setSearch = function(id,key){
  var el = document.getElementById(id);
  if(!el) return false;
  el.setAttribute('key',key);
	el.onfocus = function(){
		if(this.value == this.getAttribute('key'))
      this.value = '';
	}
	el.onblur = function(){
		if(this.value == '')
      this.value = this.getAttribute('key');
	}
};
	
// 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 && aElHref.className != 'thickbox') || foundExtension){
		aEl.onclick = function(){
			window.open(this.href);
			return false;
			}
		}
	}
};

/*function toggle(id) {
  	document.getElementById(id).style.display = 'none' ? 'block' : '';
}*/
var toggle = function(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(){
//if(!document.getElementById(id)) return false;
	var smaller = ((document.documentElement.clientWidth > 0 && document.documentElement.clientWidth < 940) || document.body.clientWidth < 940);
	if (smaller) {
		if (currentLarge == 0){
			return;
		}
		currentLarge = 0;
		document.getElementsByTagName('html')[0].className = 'small';
		//getEl(id).className = 'small';
	}
	else {
		if (currentLarge == 1){
			return;
		}
		currentLarge = 1;
		document.getElementsByTagName('html')[0].className = '';
		//getEl(id).className = '';
	}
};

//DOM loader
function init() {
	if (arguments.callee.done) return;
	arguments.callee.done = true;
	if (getEl('navigation'))active('nav');
	if (getEl('subnavigation'))activeSub('subnav');
    
    if (getEl('motioncontainer')){fillup();setObject();showFirstTentoonstelling();}
	//if (getEl('motioncontainer'))fillup();setObject();showFirstTentoonstelling();
	setSearch('searchbox','zoeken');
	setSearch('newsletter','uw email adres');
	setSearch('searchboxagenda');
	checkWindowWidth();
	setExternalLinks();
	setHover();
	createFlashObjects();
	TB_init();
	$(document).ready(function(){	$(".stripe tr:odd").addClass("alt");});
};
if (document.addEventListener) {
	document.addEventListener("DOMContentLoaded", init, null);
}
if (/WebKit/i.test(navigator.userAgent)) {  
var _timer = setInterval(function() {        
	if (/loaded|complete/.test(document.readyState)) {            
		clearInterval(_timer); init();}}, 10);
};
// for Internet Explorer (using conditional comments)
/*@cc_on @*/
/*@if (@_win32)document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
var script = document.getElementById("__ie_onload");
script.onreadystatechange = function() {    
	if (this.readyState == "complete") {        
		init();  
	}
};
/*@end @*/
window.onload = init;
window.onresize = function(){
	checkWindowWidth();
};