/**************************************
 *	Fadeshow
 **************************************/

var Fadeshow = new Class({
	object:				null,
	data: 				null,
	index: 				0,
	effect: 			null,
	periodicalTimer: 	null,
	
	setOptions: function(options){
		this.options = {
			interval: 5000,
			duration: 2000
		}
		Object.extend(this.options, options || {});
	},
	
	initialize: function(object, data, options){
		this.object		= object;
		this.data		= data;
		
		this.setOptions(options);
		if (this.options.duration > this.options.interval) { this.options.interval = this.options.duration + 2000 }
		
		this.showNew();
		if(this.data.length > 1){
			this.periodicalTimer = this.transist.periodical(this.options.interval, this);
		}
	},
	
	transist: function(){
		//Fade out
		this.object.fade(0);
		this.showNew.delay(750, this);
	},
	
	showNew: function(){
		//Set new image + url
		this.setCurrentData(this.data[this.index]);
		
		//Fade in
		this.object.fade(1);
		
		//Next index
		if(this.index == this.data.length -1) { 
			this.index = 0;
		} else { 
			this.index++;
		}
	},
	
	setCurrentData: function(data){
		// Image
		this.object.src = '/design/images/layout/header/' + data;
	}
});

fireOn = Window.ie ? 'load' : 'domready';
window.addEvent(fireOn, function(){
	
	// Load fadeshow
	var spotlight		= $$('#intro div.header_left img')[0];
	var spotlightData	= ['header_img_01.jpg', 'header_img_02.jpg', 'header_img_03.jpg', 'header_img_04.jpg'];
	if(spotlightData && spotlight){
		new Fadeshow(spotlight, spotlightData , {duration: 2000, interval: 8000} );
	}
	
	// Search
	$('q').addEvents({
		'click': function() {
			if($('q').value == "Zoeken") $('q').value = "";
		}
		,'blur': function() {
			if($('q').value == "") $('q').value = "Zoeken";
		}
	});
});
