Element.implement({

 fadeTo : function( amount, whenFinished, duration ) {
   if(typeof whenFinished != 'function') {
	 whenFinished = function() {}   
   }
   this.setStyle('visibility','visible');
   this.effect('opacity', {
      transition : new Fx.Transition(Fx.Transitions.Quad.easeOut, 6).easeOut 
    , duration : ( (duration!=null && duration>0) ? duration : 600 )
    , onComplete : function() { 
	    if(amount==0) this.element.setStyle('visibility','hidden');
	    this.whenFinished.bind(this.element)();
	  }.bind({whenFinished:whenFinished,element:this})
   }).start(this.getOpacity(),amount);
   return this;
 }
		
});

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

window.addEvent('load', function() {

if(document.getElementById('page')) {

  photos = $$('#page img');
  var i = 0;
  photos.each(function(myEl){
	  if(i!=currentPhoto) { 
		myEl.setOpacity(0); 
	  } else {
		myEl.setOpacity(1);  
	  }
	  i++; 
  });
  gid = setInterval(function(){
	if(currentPhoto>=photos.length-1) {	
	  var myImg = photos[0];
	  currentPhoto = 0;
	} else {
	  myImg = photos[currentPhoto];
	  currentPhoto++; 
	}

	i = 0;
	photos[currentPhoto];
	photos.each(function(myEl){
	  if(i!=currentPhoto) { 
		myEl.fadeTo(0); 
	  } else {
		myEl.fadeTo(1);  
	  }
	  i++; 
	});
  },3000);
  
}

if(document.getElementById('galerie')) {

  photos = $$('#galerie img');
  var i = 0;
  photos.each(function(myEl){
	  if(i!=currentPhoto) { 
		myEl.setOpacity(0); 
	  } else {
		myEl.setOpacity(1);  
	  }
	  i++; 
  });
  gid = setInterval(function(){
	if(currentPhoto>=photos.length-1) {	
	  var myImg = photos[0];
	  currentPhoto = 0;
	} else {
	  myImg = photos[currentPhoto];
	  currentPhoto++; 
	}

	i = 0;
	photos[currentPhoto];
	photos.each(function(myEl){
	  if(i!=currentPhoto) { 
		myEl.fadeTo(0); 
	  } else {
		myEl.fadeTo(1);  
	  }
	  i++; 
	});
  },3000);
  
}

});

function addToFavorites() {
	if (document.all) { window.external.AddFavorite(location.href, document.title); }
	else { alert("Votre navigateur n'autorise pas l'ajout direct de signets.\n"
	            +"Pour ce faire, faites 'Control + D' pour l'ajouter ou utilisez le menu marque-pages.") }
}