var Diaporama = new Class({
    initialize: function(zoneId){
  		this.elements = [];
  		this.effects = [];
  		this.descZone = $$('p.img_desc')[0];
  		this.currentDiapo = 0;
  		var self = this;
  		$$("#diaposzone li").each(function (el) { 
  			self.elements.push(el);
  			el.setStyle('display', 'none');
  			el.addEvent('click', self.next.bindWithEvent(self));
  			self.effects.push( new Fx.Style(el, 'opacity'));
  		} );
  		
  		this.display(this.elements[0]);
  		this.descZone.setText(this.elements[0].firstChild.alt);
    },
	
	next: function() {
		var elToHide = this.elements[this.currentDiapo];
		this.currentDiapo = this.currentDiapo + 1;
		if(this.currentDiapo == this.elements.length) {this.currentDiapo = 0; }
		this.display(this.elements[this.currentDiapo], elToHide);
	},
	
	display: function(elToShow, elToHide) { 
		function fadeIn(e){
            e.setStyles({
                    display:'block',
                    visibility: 'visible',
                    opacity: 0
            });
            this.effects[this.elements.indexOf(e)].start(1);
		}
		if($chk(elToHide)) { //on verifie si on doit cacher un element ou non 
			this.effects[this.elements.indexOf(elToHide)].start(0).chain(function(){
				elToHide.setStyle('display', 'none');
				fadeIn.apply(this, [elToShow]); //apply() redefinit le this de la fct
			}.bind(this));
		} 
		else {
			fadeIn.apply(this, [elToShow]);
		}
		this.descZone.setText(elToShow.firstChild.alt); 
	},
	
	timeInterval : 5000
});
function initDiapos() { 
	mesDiapos = new Diaporama("diaposzone"); mesDiapos.next.periodical(mesDiapos.timeInterval, mesDiapos); 
}

/* mootools menu */

var szNormal = 118, szSmall  = 110, szFull   = 132;

window.addEvent('domready', function(){
	var kwicks = $$("#kwicks li");
	var fx = new Fx.Elements(kwicks, {wait: false, duration: 300, transition: Fx.Transitions.Back.easeOut});
	kwicks.each(function(kwick, i) {
		kwick.addEvent("mouseenter", function(event) {
			var o = {};
			o[i] = {width: [kwick.getStyle("width").toInt(), szFull]};
			kwicks.each(function(other, j) {
				if(i != j) {
					var w = other.getStyle("width").toInt();
					if(w != szSmall) {o[j] = {width: [w, szSmall]}; }
				}
			});
			fx.start(o);
		});
	});
	$("kwicks").addEvent("mouseleave", function(event) {
	var o = {};
	kwicks.each(function(kwick, i) {
		o[i] = {width: [kwick.getStyle("width").toInt(), szNormal]};
	});
	fx.start(o);
	});
});

