defilant = Class.create({
	
	initialize: function(def, length, max) {
		this.moving = def;
		this.itemLength = length;
		this.posMax = max;
		this.timer = null;
		this.curPos = 0;
		
		
		if(arguments[3]) {
			this.wait = arguments[3];
		} else {
			this.wait = 5;
		}
		this.moving.observe("mouseover", this.stop.bindAsEventListener(this));
		this.moving.observe("mouseout", this.start.bindAsEventListener(this));
	},
	
	start: function() {
		this.timer = new PeriodicalExecuter(this.move.bind(this), this.wait);
	},
	stop: function() {
		this.timer.stop();
	},
	
	moveTo: function(pos) {
		new Effect.Move(this.moving, { duration: 1, transition: Effect.Transitions.sinoidal, x: (this.curPos - pos) * this.itemLength, y: 0, mode: 'relative' });
		this.curPos = pos;
	},
	
	move: function(direction) {
		if(direction < 0) {
			this.moveTo(this.curPos - 1);
		} else if(this.curPos >= this.posMax) {
			this.moveTo(0);
		} else {
			this.moveTo(this.curPos + 1);
		}
	}
});

Effect.SmoothScroll = Class.create();
Object.extend(Object.extend(Effect.SmoothScroll.prototype, Effect.Base.prototype), {
  initialize: function(element) {
    this.element = $(element);
    var options = Object.extend({
      x:    0,
      y:    0,
      mode: 'absolute'
    } , arguments[1] || {}  );
    this.start(options);
  },
  setup: function() {
    if (this.options.continuous && !this.element._ext ) {
      this.element.cleanWhitespace();
      this.element._ext=true;
      this.element.appendChild(this.element.firstChild);
    }
   
    this.originalLeft=this.element.scrollLeft;
    this.originalTop=this.element.scrollTop;
   
    if(this.options.mode == 'absolute') {
      this.options.x -= this.originalLeft;
      this.options.y -= this.originalTop;
    } 
  },
  update: function(position) {   
    this.element.scrollLeft = this.options.x * position + this.originalLeft;
    this.element.scrollTop  = this.options.y * position + this.originalTop;
  }
});
