// Copyright (c) Ekinoxe Origin 2009
// Tous droits réservés

var accordion;

// ----- INITIALISATION

var init = function() {

  if($$('.acc_toggler').length>0)
    accordion = new Fx.Accordion($$('.acc_toggler'), $$('.acc_element'), { display: -1, alwaysHide: true });
  
}

// ----- PAGE ASYNCHRONES (AJAX)

var page = function(catid) {

  var remote = new Remote({ name:'categories' , command:'getCategoryPage' , params:{catid:catid} });

  remote.addEvent('complete', function(r) {
    var p = 'contenu';
    if($(p)) {
    
      $(p).set('html', r.getResponseData());
      
      if(typeof Milkbox != 'undefined')
        new Milkbox();
      
    }
  }.bind(this));
  
  remote.addEvent('error', function(r) {
    W('Erreur pendant le chargement de la page, veuillez réessayez SVP.');
  }.bind(this));
  
  remote.call();

}

// ----- EXECUTION DOMREADY

window.addEvent('domready', init );

var currentPhoto = 0;
var photos = [];
var gid;

window.addEvent('load', function() {
  photos = $$('#diaporama img');
  var i = 0;
  
  photos.each(function(myEl){
		var myFx = new Fx.Tween(myEl);
	  if(i==currentPhoto) {
			myEl.setOpacity(1);
	  } else {
			myEl.setOpacity(0); 
	  }
	  i++; 
  });
  
  gid = setInterval(function(){
	  var i = 0;
	  photos.each(function(myEl){
			var myFx = new Fx.Tween(myEl);
		  if(i==currentPhoto) {
				myFx.start('opacity', 1, 0);
		  }
		  i++; 
	  });
	  
		if(currentPhoto>=photos.length-1) {	
		  myImg = photos[0];
		  currentPhoto = 0;
		} else {
		  myImg = photos[currentPhoto];
		  currentPhoto++; 
		}
		
		i = 0;
		photos[currentPhoto];
		photos.each(function(myEl){
			var myFx = new Fx.Tween(myEl);
		  if(i==currentPhoto) { 
				myFx.start('opacity', 0, 1);
		  }
		  i++; 
		});
  },3000);
});