
var all_showcases = new Array();




var Showcase = new Class({
    initialize: function(item){
		var me = this;
		this.element = item;
		this.number = 0;
		
		item.getElements('.showcase-diapo').each(function(i,x) {
			i.setStyles({'opacity':'0'});
			i.setStyles({'visibility':'visible'});
		});
		item.getElements('.showcase-nav li').each(function(i,x) {
			i.addEvent('click', function(event){
				event.stop();
				me.showshowcase(x);
				me.number = x;
			});
		});
		
		this.animation();
    },
	showshowcase: function(pnb) {
		this.activatethumbnail(pnb);
		
		var big = 'showcase-' + pnb + '-big';
		this.element.getElement('.showcase-loader').setStyles({'display':'none'});	
		
		this.element.getElements('.showcase-diapo').each(function(i) {
			var fx = new Fx.Tween(i,{property:'opacity',duration:750});
			
			if (!i.hasClass(big)) {
				fx.start(0);
			}
			else {
				fx.start(1);
			}
		});
	},
	activatethumbnail: function(pnb) {
		var me = this;
		this.element.getElements('.showcase-nav li').each(function(i,x) {
			if (x == pnb) {
				i.addClass('active');
			}
			else{
				i.removeClass('active');
			}
		});
	},
	
	animation: function() {
		var me 	= this;
		var nav = this.element.getElement('.showcase-nav');
		if (this.number > nav.getElements('li').length-1) { this.number = 0;}
		
		me.showshowcase(me.number)
	
		var fx = new Fx.Tween(nav,{property:'opacity',duration:5000});
		fx.start(1).chain(
			function(){this.start( me.number = me.number+1);},
			function(){this.start( me.animation());}
		);
	}

});




window.addEvent('domready', function(){
	$$('.showcase').each(function(item) {		
		all_showcases.push(new Showcase(item));
	});
});






