window.onload = function() {
	pullDown();
	tooltips();
	toggleGastenboek();
	rotateImages();
}

function rotateImages() {
	
  if (!document.getElementById('sponsor') || rotating_images.length < 1) return;
  var new_image_code = '';
    			
  new_image = document.createElement('IMG');
  new_image.src = rotating_images[active_image_index].image;
  new_image.border = "0";
  new_image.title = rotating_images[active_image_index].title;
		
  new_link = document.createElement('A');
  new_link.href = rotating_images[active_image_index].url;
  new_link.target = '_blank';
	
	if(rotating_images[active_image_index].url=='http://') {
  	new_link = new_image;
  } else {
		new_link.appendChild(new_image);
  }
	
  if (document.getElementById('sponsor').hasChildNodes() ) {
  	while (document.getElementById('sponsor').childNodes.length >= 1 ) {
  		document.getElementById('sponsor').removeChild(document.getElementById('sponsor').firstChild );
  	}
  }

  document.getElementById('sponsor').appendChild(new_link);

  active_image_index = Math.round(Math.random()*(rotating_images.length-1));

  setTimeout('rotateImages();',active_image_delay*1000);
}

function RotatingImage(image_url, title, url) {
  this.image = image_url;
  this.title = title;
  this.url = url;
}

function tooltips() {
	var Tips2 = new Tips($$('.Tips2'),{
		initialize:function(){ this.fx = new Fx.Style(this.toolTip, 'opacity', {duration: 500, wait: false}).set(0);},
		onShow: function(toolTip) {this.fx.start(1);}, 
		onHide: function(toolTip) {this.fx.start(0);}}
	);
}

sfHover = function() {
	var sfEls = document.getElementById("header").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

function toggleGastenboek() {
		
	if(!$('berichttoevoegen')) return;
	
	if($('gastenboekformcontainer').hasClass('open'))  {
		$('gastenboekformcontainer').setStyle('height', 412);
		$('berichttoevoegen').setStyle('visibility', 'hidden');
	} else {
		$('gastenboekformcontainer').setStyle('height', '1px');
	}
		
	$('berichttoevoegen').addEvent('click', function() {
		$('berichttoevoegen').removeEvents();
		$('berichttoevoegen').setStyle('visibility', 'hidden');
		$('gastenboekformcontainer').effect('height',{
			duration: 300
		}).start($('gastenboekformcontainer').scrollHeight);
	});
	
	$E('span.sluitformulier', 'gastenboekform').addEvent('click', function() {
		
		$('berichttoevoegen').setStyle('visibility', 'visible');

		$E('span.sluitformulier', 'gastenboekform').removeEvents();
		$('gastenboekformcontainer').effect('height',{
			duration: 300,
			onComplete: function() { toggleGastenboek() }
		}).start(1);
		
		$('gastenboekformcontainer').removeClass('open')
		
	});
		
}

function openGastenboek() {
	$('gastenboekformcontainer').setStyle('height', 392);
}

function ticker() {
	var Ticker = new Class({
	  setOptions: function(options) {
	  	this.options = Object.extend({
	  		speed: 1000,
	  		delay: 5000,
	  		direction: 'vertical',
	  		onComplete: Class.empty,
	  		onStart: Class.empty
	  	}, options || {});
	  },
	  initialize: function(el,options){
	  	this.setOptions(options);
	  	this.el = $(el);
	  	this.items = this.el.getElements('li');
	  	var w = 0;
	  	var h = 0;
	  	if(this.options.direction.toLowerCase()=='horizontal') {
	  		h = this.el.getSize().size.y;
	  		this.items.each(function(li,index) {
	  			w += li.getSize().size.x;
	  		});
	  	} else {
	  		w = this.el.getSize().size.x;
	  		this.items.each(function(li,index) {
	  			h += li.getSize().size.y;
	  		});
	  	}
	  	this.el.setStyles({
	  		position: 'absolute',
	  		top: 0,
	  		left: 0,
	  		width: w,
	  		height: h
	  	});
	  	this.fx = new Fx.Styles(this.el,{duration:this.options.speed,onComplete:function() {
	  		var i = (this.current==0)?this.items.length:this.current;
	  		this.items[i-1].injectInside(this.el);
	  		this.el.setStyles({
	  			left:0,
	  			top:0
	  		});
	  	}.bind(this)});
	  	this.current = 0;
	  	this.next();
	  },
	  next: function() {
	  	this.current++;
	  	if (this.current >= this.items.length) this.current = 0;
	  	var pos = this.items[this.current];
	  	this.fx.start({
	  		top: -pos.offsetTop,
	  		left: -pos.offsetLeft
	  	});
	  	this.next.bind(this).delay(this.options.delay+this.options.speed);
	  }
	});
	var vert = new Ticker('activiteiten',{speed:2000,delay:3000,direction:'vertical'});
}

function pullDown() {
	var showmore = new Accordion($$('span.uitklap'), $$('div.pulldown'),{
	alwaysHide: true, 
	show: 999,
	onActive: function(toggler, element){
		var toggletext = toggler.getText();
		if (toggletext=='<img src="../../img/arrow_down_white.gif" />'){
			toggler.setHTML('<img src="../../img/arrow_up_white.gif" />')}
		},
	onBackground: function(toggler, element){
		var toggletext = toggler.getText();
		if (toggletext=='<img src="../../img/arrow_up_white.gif" />'){
			toggler.setHTML('<img src="../../img/arrow_down_white.gif" />')}
		}			
	}).stop();
}