/*
	Class:    	fadeSlides
	Author:   	Gerard Corr
	Website:    http://www.spaceandtimedesign.com
	Version:  	0.0.1
	Date:     	28/08/2009
	Built For:  MooTools 1.2
*/


var fadeSlides = new Class({

	//implements
	Implements: [Options,Events],

	//options
	options: {
		slideVariable: 'slide',
		slideNumber: -1,
		slideCurrent: -1,
		slideDelay:8000
	},

	//initialization
	initialize: function(options) {
		//set options
        this.setOptions(options);
		
		this.fadder = function(){ this.fadeSlide(); this.fireEvent('fadeSlide'); }.bind(this);
        this.periodical = this.fadder.periodical(this.options.slideDelay);
	},
	
	
	fadeSlide: function(){
		
		
		//alert('fade slide');
		//console.log('fade slide');
		//console.log('total slides:'+this.options.slideNumber);
	
		var currentFade = this.options.slideCurrent;
		if(currentFade==-1){
			currentFade = this.options.slideNumber-1;
		}
		
		var nextFade = currentFade - 1;
		var slideVariable = this.options.slideVariable;
	
		if(nextFade<0){
			nextFade = this.options.slideNumber-1;
		}
		
		//console.log('current:'+currentFade);
		//console.log('next:'+nextFade);
		
		if(nextFade==this.options.slideNumber-1){
			
			$(slideVariable+nextFade).set('tween', {duration: 'long'});
			$(slideVariable+nextFade).tween('opacity', 1);
			
		}else{

			$(slideVariable+nextFade).setStyle('opacity',1);
			$(slideVariable+currentFade).set('tween', {duration: 'long'});
			$(slideVariable+currentFade).tween('opacity', 0);
		}

		this.options.slideCurrent = nextFade;

		
	}
});

