var ShowReel = new Class({

	Implements: Options,
	
	options: {
		speed		: 7500
	},

	initialize: function(view,items,options){
		//Extend Array Class
		Array.implement({
			randomize: function() {
				return this.sort(function() {return 0.5 - Math.random();});
			}
		});
		//Set Options
		this.setOptions(options);
		//Define variables
		this.current	= 0;
		this.viewport 	= view;
		this.items		= items.randomize();
		this.length		= this.previous = this.items.length - 1;
		
		if (view) {
			//Show first item
			this.next();
			if (this.items.length > 1) {
				//Loop
				this.next.periodical(this.options.speed,this);
			}
		}
	},
	
	next: function(){
		this.viewport.empty();
		
		var next 	= this.items[this.current].getElement('img');
		var nextsrc	= next.get('src');
		next.set('src',nextsrc.replace('GS_',''));
		
		var prev	= this.items[this.previous].getElement('img');
		var prevsrc	= prev.get('src');
		prev.set('src',prevsrc.replace('/SR','/GS_SR'));

		var big 	= new Element('img',{'src':nextsrc.replace('GS_SR_','BR_')}).fade('hide');
		big.inject(this.viewport);
		big.addEvent('load',function(){
			big.fade('in');
		});
		
		(function(){
			this.previous	= this.current;
			this.current 	= (this.current == this.length) ? 0 : this.current + 1;
		}).delay(1000,this);
	}

});

window.addEvent('load',function(){
	var showreel = new ShowReel($('showreel-big'),$$('.showreel-item'));
});