/* Cross Fade Portfolio images */
var Portfolio4 = new Class({

	Implements: [Events, Options],

	options: {
		//onError:$empty
		//onLoad:$empty
		debug:false,
		images:'header',
		delay:7000,
		duration:2000,
		transition:Fx.Transitions.Sine.easeInOut,
		fps:60
	},

	initialize: function(options){
		this.setOptions(options);
		
		if (this.options.debug) this.checkElements();
		this.createInterface();
		this.play();
	},
	
	checkElements:function(){
		if (document.id(this.options.images).getElements('img').length < 1) this.fireEvent('onError','Portfolio4 - No image elements defined');
	},
	
	createInterface:function() {
		this.images = document.id(this.options.images).getElements('img');
		
		this.number = 0;
		this.images.each(function(e,i){
			e.set({
				styles:{opacity:i==0 ? 1:0,display:i==0 ? 'block':'none'},	
				tween:{duration:this.options.duration,fps:this.options.fps,transition:this.options.transition}
			});
		}.bind(this));
	},
	
	increment:function(){this.selectItem(this.number == this.images.length-1 ? 0 : this.number+1);},	
	decrement:function() {this.selectItem(this.number == 0 ? this.images.length-1 : this.number-1);},
	
	selectItem:function(selection) {
		this.images[this.number].tween('opacity',0);
		this.number = selection;
		this.images[this.number].setStyle('display','block').tween('opacity',1);
	},
	
	play:function(){clearInterval(this.timer);this.timer = this.increment.periodical(this.options.delay,this);}	
});
