Fixedbox = Class.create();

Fixedbox.prototype = {
   initialize: function( element, options ) {
      this.element = $( element );
      this.effect = false;
      
      this.options = {
         space: 6,
         duration: .4
      }
      Object.extend( this.options, options );

      Position.prepare();
      this.xy = Position.cumulativeOffset( this.element );

      window.onscroll = this.scroll.bindAsEventListener( this );
   },

   scroll: function( event ) {
      if( this.effect )
         this.effect.cancel();

      Position.prepare();
      var deltay = Position.deltaY;
      var xy = Position.cumulativeOffset( this.element );

      var move = deltay - xy[1] + this.options.space;

      if( (xy[1] + move) < this.xy[1] )
         move = this.xy[1] - xy[1];

      this.effect = new Effect.MoveBy( this.element, move, 0,
         { duration: this.options.duration } );
   }

}
