SlideShow_options = {
  className:    'SlideShow',
  rotatedEl:    'img',
  playing:      true,
  startIndex:   2 
} ;

(function($) 
{
  $.SlideShow = function( id, el )
  {
    var that        = this ;
    this.id         = id ;
    this.options    = $.SlideShow.options ;
    this.parentEl   = el ;
    this.rotatedEl  = $( this.options.rotatedEl, el ) ;
    this.count      = this.rotatedEl.length ;
    this.index      = ( ( this.options.startIndex - 1 < 0 ) ? ( this.count - 1 ) : ( this.options.startIndex - 1 ) ) ;

    el.addClass( this.options.className ) ;

    if ( this.options.playing )
    {
      $(this.rotatedEl).each( function( i )
      { 
        img = that.rotatedEl[i] ;
        $(img).hide() ; 
      } ) ;
      this.loop() ;
    }
  } ;

  $.SlideShow.prototype.showNext = function()
  {
    $( this.rotatedEl[ this.index ] ).fadeOut( 'fast' ) ;
    this.index += 1 ;
    if ( this.index >= this.count )
      this.index = 0 ;
    $( this.rotatedEl[ this.index ] ).fadeIn( 'normal' ) ;
  }

  $.SlideShow.prototype.loop = function()
  {
    this.showNext() ;
    i = $( '.' + this.options.className ).index( this.parentEl ) ;
    this.timeoutID = window.setTimeout( 'window.slideshows[' + i + '].loop()', 7000 ) ;
  }

  $.fn.SlideShow = function( options )
  {
    $.SlideShow.options = options ;
    if ( undefined === window.slideshows )
      window.slideshows = [] ;

    return this.each( function()
    {
      var el = $( this ) ;
      i = window.slideshows.length ;
      window.slideshows.push( new $.SlideShow( i, el, options ) ) ;
    } ) ;
  }

  $(document).ready( function(){ 
      $( '#diaporama' ).SlideShow( SlideShow_options ) ;
  } ) ;
})(jQuery);
