window.addEvent('domready', function() {
	f4_pushBox();
	Shadowbox.init({
    	handleOversize: "drag",
    	modal: true
	});
	
});

/*
window.addEvent('load', function() {
	
});
*/


/**
 * EfxBaseSlideShow Class
 * Reusable slideshow class.
 *
 * @author Ralph Meeuws (ralph-meeuws[AT]efocus.nl)
 * @param arrSlides, intStartSlide, blnLoop, intInterval, blnAutoPlay, blnPlaying
 * @param strOutEffectProperty, intOutEffectStartValue, intOutEffectEndValue, intOutEffectDuration
 * @param strInEffectProperty, intInEffectStartValue, intInEffectEndValue, intInEffectDuration
 * @return EfxBaseSlideShow
 */
var EfxBaseSlideShow = new Class({
	Implements: [Options, Events, Chain],
	options: {
		arrSlides: [],
		intStartSlide: 0,
		blnLoop: true,
		intInterval: 2500,
		blnAutoPlay: true,
		blnPlaying: false,
		
		strOutEffectProperty: 'opacity',
		intOutEffectStartValue: 1,
		intOutEffectEndValue: 0,
		intOutEffectDuration: 'long',
		
		strInEffectProperty: 'opacity',
		intInEffectStartValue: 0,
		intInEffectEndValue: 1,
		intInEffectDuration: 'long'
	},
	initialize: function(options) {
		var that = this;
		this.setOptions(options);
		this.addSlides(this.options.arrSlides);
		this.options.arrSlides.each(function(slide){
			slide.setStyle('opacity', 0);
		});
		this.showSlide(this.options.intStartSlide);
		if (this.options.blnAutoPlay == true && this.options.blnPlaying == false) {
			this.playSlideShow();
		}
		this.intSlideCount = 0;
	},
	arrSlideCollection: [],
	addSlides: function(arrSlides){
		arrSlides.each(function(slide){
			this.arrSlideCollection.include(slide);
		}, this);
	},
	addSlide: function(slide){
		this.addSlides($splat(slide));
	},
	cycleForwards: function(){
		if ($chk(this.intCurrentSlideNumber) && this.intCurrentSlideNumber < this.arrSlideCollection.length-1) {
			this.showSlide(this.intCurrentSlideNumber+1);
		} else if ((this.intCurrentSlideNumber) && this.options.blnLoop) {
			this.showSlide(0);
		} else if (!defined(this.intCurrentSlideNumber)) {
			this.showSlide(this.options.intStartSlide);
		}
	},
	cycleBackwards: function(){
		if (this.intCurrentSlideNumber > 0) {
			this.showSlide(this.intCurrentSlideNumber-1);
		} else if (this.options.blnLoop) {
			this.showSlide(this.arrSlideCollection.length-1);
		}
	},
	showSlide: function(intSlideNumberToShow){
		if (this.arrSlideCollection[intSlideNumberToShow]) {
			var that = this;
			//Current slide
			if (this.arrSlideCollection[this.intCurrentSlideNumber]) {
				var intPreviousSlideNumber = this.intCurrentSlideNumber;
		//		this.arrSlideCollection[intSlideNumberToShow].setStyle(that.options.strInEffectProperty, that.options.intInEffectEndValue);
				this.arrSlideCollection[intSlideNumberToShow].setStyle(that.options.strOutEffectProperty, that.options.intOutEffectStartValue); // DEBUG THIS LINE!!!

				var myFx1 = new Fx.Tween(this.arrSlideCollection[this.intCurrentSlideNumber],{
					property: that.options.strOutEffectProperty, 
					duration: that.options.intOutEffectDuration
                });
				myFx1.start(that.options.intOutEffectStartValue, that.options.intOutEffectEndValue).chain(function(){
					that.arrSlideCollection[intPreviousSlideNumber].setStyle(that.options.strInEffectProperty, that.options.intInEffectStartValue)
				});
			}
			//The other slides
			var myFx2 = new Fx.Tween(this.arrSlideCollection[intSlideNumberToShow], {
                property: that.options.strInEffectProperty,
                duration: that.options.intInEffectDuration
                });
			myFx2.start(that.options.intInEffectStartValue, that.options.intInEffectEndValue);
			this.intCurrentSlideNumber = intSlideNumberToShow;
			
			
		}
		this.fireEvent('slideShown', this);
	},
	runSlideShow: function(){
		var that = this;
		
		if (that.intCurrentSlideNumber != this.intSlideCount) {
			this.intSlideCount = that.intCurrentSlideNumber;
		}
		this.intSlideCount++;
		if (this.intSlideCount >= that.arrSlideCollection.length) {
			this.intSlideCount = 0;
		}			
		this.showSlide(this.intSlideCount);
	},
	playSlideShow: function(){
		this.options.blnPlaying = true;
		this.slideShowTimer = this.runSlideShow.periodical(this.options.intInterval, this);
	},
	resetTimer: function(){
		if ($chk(this.slideShowTimer)) {
			this.slideShowTimer = $clear(this.slideShowTimer);
			this.playSlideShow();
		}
	},
	name: 'EfxBaseSlideShow'
});


function clearSearchTerm(el){
	if(el.value=='Zoek informatie'){
		el.value='';
	}
}

/**
 * EfxListSlideShow Class
 * Customized slideshow class.
 *
 * @author Ralph Meeuws (ralph-meeuws[AT]efocus.nl)
 * @param elNav, strLabelPrev, strLabelNext, strLabelFirst, strLabelLast, strLabelPlay, strLabelPause
 * @return EfxListSlideShow
 */

var EfxListSlideShow = new Class({
	Extends: EfxBaseSlideShow,
	options: {
		elNav: $('nav'),
		t: null
	},
	initialize: function(options){
		this.parent(options);
		if ($defined(this.options.elNav)) {
			this.arrNavListItems = this.options.elNav.getElements('li');
			this.arrNavLinks = this.options.elNav.getElements('a');
			this.initNav();
			if (this.arrNavLinks.length != 0) {
				this.activateNavLink(this.arrNavLinks[this.options.intStartSlide]);
			}
			this.addEvent('slideShown', function(){
				if (this.arrNavLinks.length != 0) {
					this.activateNavLink(this.arrNavLinks[this.intCurrentSlideNumber]);
				}
			});
		}
	},
	initNav: function(){
		var that = this;
		this.arrNavLinks.each(function(elNavLink, n){
			elNavLink.addEvent('mouseover', function(){
				that.options.t = window.setTimeout(function(){
					that.showSlide(n);
					that.resetTimer();
					
				}, 500);
				that.activateNavLink(elNavLink);	
			});
			
			elNavLink.addEvent('mouseout', function(){
				window.clearTimeout(that.options.t);
			});
			elNavLink.addEvent('click', function(){
				var url = that.arrSlideCollection[n].getElements("ul li a")[0];
				window.location.href = url;
			});
		});
		$$('.pushbox_viewport')[0].addEvents({
			'mouseenter': function(){
				// pause slideshow
				that.slideShowTimer = $clear(that.slideShowTimer);
			},
			'mouseleave': function(){
				// play slideshow
				that.playSlideShow();
			}
		});
	},
	activateNavLink: function(elNavLink){
		this.arrNavListItems.each(function(elNavListItem){
			elNavListItem.removeClass('active');
		});
		elNavLink.getParent().addClass('active');
	},
	name: 'EfxListSlideShow'
});



/**
 * f4_pushBox
 * Animates the pushbox and defines the interaction.
 *
 * @author Ralph Meeuws (ralph-meeuws[AT]efocus.nl)
 * @param arrSlides, intStartSlide, blnLoop, intInterval, blnAutoPlay, blnPlaying
 * @param strOutEffectProperty, intOutEffectStartValue, intOutEffectEndValue, intOutEffectDuration
 * @param strInEffectProperty, intInEffectStartValue, intInEffectEndValue, intInEffectDuration
 * @param elNav, strLabelPrev, strLabelNext, strLabelFirst, strLabelLast, strLabelPlay, strLabelPause
 * @return EfxListSlideShow Class instance
 */
function f4_pushBox(){
	arrPushBoxes = $$('.pushbox');
	if (arrPushBoxes.length == 0) return;
	
	var elMyPb = arrPushBoxes[0].getElement('.pushbox_viewport');
	var arrMySlides = elMyPb.getElements('.pushbox_slide');
	var elMyNav = arrPushBoxes[0].getElement('.pushbox_nav');
	
	var objPushbox = new EfxListSlideShow({
		arrSlides: arrMySlides,
		elNav: elMyNav,
		intInterval: 5000,
		intStartSlide: 0,
		strOutEffectProperty: 'left',
		intOutEffectStartValue: 0,
		intOutEffectEndValue: 940
	});
}





