Effect.RightMove = Class.create(Effect.Base, {
  initialize: function(element) {
    this.element = $(element);
    if (!this.element) throw(Effect._elementDoesNotExistError);
    var options = Object.extend({
      x:    0,
      y:    0,
      mode: 'relative'
    }, arguments[1] || { });
    this.start(options);
  },
  setup: function() {
    this.element.makePositioned();
    this.originalRight = parseFloat(this.element.getStyle('right') || '0');
    this.originalTop  = parseFloat(this.element.getStyle('top')  || '0');
    if (this.options.mode == 'absolute') {
      this.options.x = this.options.x - this.originalRight;
      this.options.y = this.options.y - this.originalTop;
    }
  },
  update: function(position) {
    this.element.setStyle({
      right: (this.options.x  * position + this.originalRight).round() + 'px',
      top:  (this.options.y  * position + this.originalTop).round()  + 'px'
    });
  }
});

Effect.vShake = function(element) {
  element = $(element);
  var options = Object.extend({
    distance: 20,
    duration: 0.5
  }, arguments[1] || {});
  var distance = parseFloat(options.distance);
  var split = parseFloat(options.duration) / 10.0;
  var oldStyle = {
    top: element.getStyle('top'),
    right: element.getStyle('right')
  };
  return new Effect.RightMove(element,
    { y:  distance, x: 0, duration: split, afterFinishInternal: function(effect) {
  new Effect.RightMove(effect.element,
    { y: -distance*2, x: 0, duration: split*2,  afterFinishInternal: function(effect) {
  new Effect.RightMove(effect.element,
    { y:  distance*2, x: 0, duration: split*2,  afterFinishInternal: function(effect) {
  new Effect.RightMove(effect.element,
    { y: -distance*2, x: 0, duration: split*2,  afterFinishInternal: function(effect) {
  new Effect.RightMove(effect.element,
    { y:  distance*2, x: 0, duration: split*2,  afterFinishInternal: function(effect) {
  new Effect.RightMove(effect.element,
    { y: -distance, x: 0, duration: split, afterFinishInternal: function(effect) {
      effect.element.undoPositioned().setStyle(oldStyle);
  }}) }}) }}) }}) }}) }});
};

