/*
** Zorg voor Beter JavaScript in combinatie met mootools v1.11
** versie: 1.3 ~ 20-01-2009
** Lodewijk Schutte ~ freelance@loweblog.com
*/

// write the css needed for js
document.write('<link rel="stylesheet" type="text/css" media="screen" href="/index.php?css=home/css_js" />');

// Extend String with getHash()
String.extend({
 getHash : function() {
  var hash = this.split('#');
  return hash[1] || false;
 }
});

var ZVB = {};

// Filter toggeler
ZVB.Filter = {
	clicked: function(e) {
		new Event(e).stop();
		this.getParent().getParent().toggleClass('open');
	},
	init: function() {
		var wrap = $('filters');
		if (!wrap) return;
		wrap.addClass('js-on');
		$$('#filters h3 a').each(function(el){
			el.addEvent('click',this.clicked);
		},this);
	}
};
window.addEvent('domready',ZVB.Filter.init.bind(ZVB.Filter));

if (window.ie6) {
	window.addEvent('domready',function(){
		var nav = $('nav');
		if (!nav) return;
		
		$$('#nav li').each(function(el){
			if (el.getParent() != nav) return;
			el.addEvent('mouseenter',function(){
				this.addClass('hover');
			});
			el.addEvent('mouseleave',function(){
				this.removeClass('hover');
			});
		});
	});
}


// toggle links (faq)
var Toggle = {
 init : function() {
  window.addEvent('domready',function(){
   if (!(A = $$('a.toggle'))) return;
   // loop thru toggle links, add event
   A.each(function(el){
    el.addEvent('click',Toggle.hop);
   });
   Toggle.check();
  });
 },
 hop : function(e) {
  // catch event
  var ev = new Event(e);
  // get target for event
  var a = ev.target;
  // get hash, toggle element
  if (!(id = a.href.getHash())) return;
  if (!$(id)) return;
  $(id).toggleClass('verstoppen');
  ev.preventDefault();
 },
 check : function() {
  // open by default
  if (!(id = location.href.getHash())) {
   // open first nieuwsbrief item, if present
   if ($('nieuwsbrief')) { $('onderwerp').getElement('ul').removeClass('verstoppen'); }
   return;
  }
  if (!$(id)) return;
  $(id).removeClass('verstoppen');
 }
}
Toggle.init();


//var Filters


// De Week Van image switcher
window.addEvent('domready',function(){
 if (!(IM = $$('#mensen img'))) return;
 IM.each(function(el){
  // original src (grayscale)
  var uit  = el.src;
  // new src (without grayscale filter)
  var over = el.src.replace('&fltr=gray','');
  // preload new src
  var tmp = new Image();
  tmp.src = over;
  // add eventhandlers
  el.addEvent('mouseover',function(){this.src = over;});
  el.addEvent('mouseout',function() {this.src = uit;});
 });
});


// Fade header
window.addEvent('load',function(){
 if (!(header = $('gordijn'))) return;
 new Fx.Style(header,'opacity',{duration:3000,onComplete:function(){header.remove()}}).start(1,0);
});


// home page clickety things
window.addEvent('domready',function(){
 if (!(D = $$('.clickety'))) return;
 D.each(function(el){
  el.style.cursor = 'pointer';
  el.addEvent('click',function(){location.href = el.getElement('a').href});
  el.addEvent('mouseover',function(){el.addClass('hover')});
  el.addEvent('mouseout',function(){el.removeClass('hover')});
 });
});


// eerste li
window.addEvent('domready',function(){
 if (!(o = $$('.home div#onderwerpen'))) return;
 o.getElement('li').addClass('eerste');
});

// VIDEO CLASS
var Video = new Class({
 initialize : function(el) {
  this.element = $(el);
  this.target  = this.element.getElement('.preview');
  this.image   = this.target.getElement('img');
  this.downloads = this.element.getElement('.downloads');
  this.links   = this.downloads.getElements('ul a');
  this.transcript = this.element.getElement('.transcription');
  this.subs    = this.element.getElement('a.subs');
  
  if (!this.target || !this.downloads || !this.links ) return;
  
  this.create();

 },
 create : function() {
  this.movie = new GovVid('myVid','400','224');
  this.links.each(function(el){ this.movie.addMovie(el.href); },this);
  if (this.image) this.movie.addImage(this.image.src);
  if (this.subs) this.movie.addCaption('flv',this.subs.href);
  
  this.movie.write(this.target.id);
 }
});

window.addEvent('domready',function() {
 $$('.moviecontent').each(function(el){ new Video(el); });
});


/*
-- LINK ACTIVATOR
---------------------------------------------------*/

function ActivateLinks(container,setParent,label,attribute) {

 // do nothing if container is not given
 if (!container) return;
 
 // set vars
 this.container = container;
 this.setParent = arguments[1] || false;
 this.label     = arguments[2] || 'active';
 this.attribute = arguments[3] || 'class';
 
 // activate function
 this.activate = function() {
  if (!document.getElementsByTagName || !document.getElementById) return;
  if (!document.getElementById(this.container)) return;

  // get links in container
  var A = document.getElementById(this.container).getElementsByTagName('a');

  // loop thru links, compare href to location.href
  for (var i = 0; i < A.length; i++) {
    
   // if (part of) the link does not match the URI, skip it
   if (location.href.indexOf(A[i].href) == -1) continue;

   // activate the anchor or its parent?
   var el = (this.setParent && A[i].parentNode) ? A[i].parentNode : A[i];
    
   // set id, or append class name
   if (this.attribute == 'id') {
     el.id = this.label;
   } else {
     el.className += ' ' + this.label;
   }
   
  } // end for loop
 } // end activate function
 
} // end ActivateLinks

window.addEvent('domready',function() {
 new ActivateLinks('submenu',true,'actief').activate();
});

/*
-- SITESTAT
---------------------------------------------------*/
function sitestat(ns_l){
	ns_l+='&amp;ns__t='+(new Date()).getTime();
	ns_pixelUrl=ns_l;
	ns_0=document.referrer;
	ns_0=(ns_0.lastIndexOf('/')==ns_0.length-1)?ns_0.substring(ns_0.lastIndexOf('/'),0):ns_0;
	if(ns_0.length>0)
		ns_l+='&amp;ns_referrer='+escape(ns_0);
	if(document.images){
		ns_1=new Image();
		ns_1.src=ns_l;
	}
	else
		document.write('<img src="'+ns_l+'" width="1" height="1" alt="">');
}

