/* Cross Fade Portfolio with enlarge options.  */
var Portfolio4 = new Class({

	Implements: [Events, Options],

	options: {
		//onError:$empty
		//onLoad:$empty
		debug:false,
		images:'anisequence',
		selected:0.9,
		rest:.6,
		delay:3500,
		duration:1800,
		transition:Fx.Transitions.Sine.easeIn,
		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.slideshow = document.id(this.options.images);
		this.images = this.slideshow.getElements('img');
		this.number = 0;
		this.large = false;
				
		
		this.images.each(function(e,i){
			if (e.hasClass('start')) this.number = i;
			e.set({
				styles:{opacity:e.hasClass('start') ? 1 : 0},
				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);
	},
	
	stop:function() {clearInterval(this.timer);},
	play:function(){clearInterval(this.timer);this.timer = this.increment.periodical(this.options.delay,this);}
});



var PageLoader = new Class({
	initialize:function() {
		window.addEvents({
			domready:function() {
				if (document.id('anisequence')) new Portfolio4({debug:false});
			}.bind(this)
		});
	}
});
