// by neiker - 05/30/2011

var smooth = new Class({
	elements: null,
	timer: null,
	activeElement: {key:0, value:null}, 
    options: {
        wrapper: 'photoSection',
        time: 1000
    },
    initialize: function(options){
    	this.setOptions(options);
    	this.elements = $$('#'+this.options.wrapper+' img');
    	if (this.elements.length>1){
    		this.elements.setStyle('opacity',0);
    		this.activeElement.value = this.elements[0];
	    	this.activeElement.value.setStyle('opacity',1)
	    	this.play();
    	}
    },
    setOptions: function(options){ //mootools 1.1 :(
    	var options = options || {};
    	if (options.wrapper) this.options.wrapper = options.wrapper;
    	if (options.time) this.options.time = options.time;
    },
    fire: function(){    	
    	if(this.activeElement.value) this.fadeOut(this.activeElement.value);
    	var element = this.getNext();
    	this.activeElement.key = element[0];
    	this.activeElement.value = element[1];
    	this.fadeIn(this.activeElement.value);
    },
    getNext: function(){ //iterator (?)
    	var key = (this.activeElement.key==this.elements.length-1) ? 0 : this.activeElement.key+1;
    	return [key,this.elements[key]];
    },
	fadeOut: function(element){
		return Effect.Fade(element) || false;
	},
	fadeIn: function(element){
		return Effect.Appear(element) || false;
	},
	play: function(){
		this.timer = this.fire.periodical(this.options.time, this);
		return true;
	},
	stop: function(){
		return $clear(this.timer);
	}
});

