window.addEvent("domready", function() {
	var posId=0;
	var tableauPos=new Array;
	var hautChange = new Fx.Style($('picto-haut'), 'margin-top');
	var basChange = new Fx.Style($('picto-bas'), 'margin-top');
	var stretchers = $$('div.album');
	var togglers = $$('a.toggler');

	Fx.Slide.implement({
  		isVisible: function() {
    		return (this.wrapper.offsetHeight == 0 || this.wrapper.offsetWidth == 0) ? false: true;
  		}
	});
	
	$$('.affiche').addReflection({height:0.5,opacity:0.5});
	
	var count=0;
	var lireComments = $$('div.ecrire_comment');
	lireComments.each(function(item, index){
		monNom = "slide"+count;
		var monNom = new Fx.Slide(item).hide();
		var monToggle = "toggle"+count;
		var countTemp = (Math.floor(count/2))*2;
		var monAccordion = "article"+countTemp;
		var monSlide = "ecrire_comment"+count;
		$(monToggle).addEvent('click', function(e){
			e = new Event(e);
			if (!monNom.isVisible()) {
				$(monAccordion).effect('height', {duration: 500}).start($(monAccordion).getCoordinates().height.toInt()+$(monSlide).getCoordinates().height.toInt());
			}
			if (monNom.isVisible()) {
				$(monAccordion).effect('height', {duration: 500}).start($(monAccordion).getCoordinates().height.toInt()-$(monSlide).getCoordinates().height.toInt());
			}
			monNom.toggle();
			e.stop();
		});
		count++;
	});
	
	stretchers.each(function(item, index){
		var ypos = item.offsetHeight;
		tableauPos[index] = ypos;
	});
	var accordion = new Accordion(togglers, stretchers, {
		display:posId,
		opacity: false,
		//fixedHeight: '200px',
		onActive: function(toggler, element){
			posId=this.previous;
			//var hauteur=((posId+1)*16)+100+5-38;
			var hauteur=((posId+1)*16)+(tableauPos[posId]/2)+5-38;
			//16:hauteur <h2> 100:moitie album 5:bordure de la rubrique 38:milieu de la fleche
			hautChange.start(hauteur);
			basChange.start(hauteur);
			//alert("---"+element.offsetHeight);
		}
		}, $('cont_rubrique'));
	$$('.nextToggle').addEvent('click', function(){
		if (posId<togglers.length-1){
			posId+=1;
		}
		accordion.display(posId);
	});
	$$('.prevToggle').addEvent('click', function(){
		if (posId>0){
			posId-=1;
		}
		accordion.display(posId);
	});
		
});