// mediaSlide.js           
// Tim Bijkerk, Jan Jaap Wennekes             
// Copyright 2009 - Wennet Webdesign - http://www.wennet.nl/

var mediaSlide = new Class({			 
	Implements: [Options],

	options: {	
		elements 		: '.slideshow img', 
   		mseconds 		: '3000',
    	transition_ms 	: '1400'
	},
    
    media			: [],
	count			: null,
	current			: 0,	
	
	initialize: function(options){
		this.setOptions(options);
		
		if ($$(this.options.elements)){
			
			this.options.elements = $$(this.options.elements);
			
			
			
			this.options.elements.each(function(el){
		        el.set('opacity', 0);
		        el.setStyles({
		        	'position'	: 'absolute',
		        	'display'	: 'block'
		        });
		        this.media.extend([el]);
			}.bind(this));
			
			this.count = this.options.elements.length;		
			this.setImageTimer();
		}
	},
	
	setImageTimer: function(){
		this.imageTimer();
		this.imageTimer.periodical(this.options.mseconds, this);
	},
	
	imageTimer: function(){
		this.media.each(function(el){
			el.set('tween', {duration: this.options.transition_ms});
            if (el.get('opacity') != 0){
                el.tween('opacity', 0);				
            }
		}.bind(this));
		
		this.current = (this.current+1 < this.count) ? this.current+1 : 0;
		this.media[this.current].tween('opacity', 1);
	}
});

var fotoSlide = new Class({			 
	Implements: [Options],

	options: {	
		elements 		: '.fotoshow div', 
   		mseconds 		: '3000',
    	transition_ms 	: '1400'
	},
    
    media			: [],
	count			: null,
	current			: 0,	
	
	initialize: function(options){
		this.setOptions(options);
		this.options.elements = $$(this.options.elements);
		
		this.options.elements.getParent().addEvent('click', function(){
			window.location = 'fotogallerij/';
		});
		
		this.options.elements.each(function(el){
	        el.set('opacity', 0);
	        el.setStyles({
	        	'position'	: 'absolute',
	        	'display'	: 'block'
	        });
	        this.media.extend([el]);
		}.bind(this));
		
		this.count = this.options.elements.length;		
		this.setImageTimer();
	},
	
	setImageTimer: function(){
		this.imageTimer();
		this.imageTimer.periodical(this.options.mseconds, this);
	},
	
	imageTimer: function(){
		this.media.each(function(el){
			el.set('tween', {duration: this.options.transition_ms});
            if (el.get('opacity') != 0){
                el.tween('opacity', 0);				
            }
		}.bind(this));
		
		this.media[this.current].tween('opacity', 1);
		this.current = (this.current+1 < this.count) ? this.current+1 : 0;
	}
});


