$( transit );

function transit() {
  var self = transit;

  // init
  if( ! ("container" in self) ) {
    self.container = document.getElementById("top-banner-container");
    self.divs = self.container.getElementsByTagName( "DIV" );

    // no sense to toggle zero or one divs
    if( self.divs.length < 2 ) {
      return;
    }

    self.divsLength = self.divs.length;
    self.current = 0;
    self.timeout = 0;
    self.inAction = 0;

    self.setTimeout = function() {
      if( self.timeout ) {
        window.clearTimeout ( self.timeout );
      }
      self.timeout = window.setTimeout( self, TDELAY );
    }
  }


  // do fade
  if( self.inAction ) {
    var curDiv = self.divs[self.current];

    $( curDiv ).fadeOut( 800, function() {

      // this div is no more current
      $( curDiv ).removeClass( "current" );

      // compute next current div
      self.current = (self.current+1) % self.divsLength;

      // set the computed div current and fade it in
      $( self.divs[self.current] )
        .addClass( "current" )
        .hide()
        .fadeIn( 800, self.setTimeout );
    });

  } else {
    self.inAction = 1;
    self.setTimeout();
  }
}

