// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
Effect.BackgroundScroll = Class.create();
Object.extend(Object.extend(Effect.BackgroundScroll.prototype, Effect.Base.prototype), {
  initialize: function(element) {
    this.element = $(element);
    if(!this.element.currentBackgroundPosition)
      this.element.currentBackgroundPosition = [-2000, 0];
    this.offsets = arguments[1];
    this.start(arguments[2] || {});
  },
  setup: function() {
    this.current = this.element.currentBackgroundPosition;
    this.delta = [
      this.offsets[0] - this.current[0],
      this.offsets[1] - this.current[1]];
  },
  update: function(position) {
    this.element.currentBackgroundPosition = [
      Math.round(this.current[0] + (this.delta[0]*position)),
      Math.round(this.current[1] + (this.delta[1]*position)) ];
    this.element.style.backgroundPosition = 
      this.element.currentBackgroundPosition[0] + 'px ' +
      this.element.currentBackgroundPosition[1] + 'px';
  }
});

var X_REF = -1;

var pos = 0;
var status = 0;

function slideFX() {
  if (status == 0) {
    if (pos == 2000) {
      pos = 0;
      status = 1;
      new Effect.BackgroundScroll('body', [X_REF*pos, 0], {duration: 10, afterFinish: function(){status = 0;}});
    } else {
      pos += 1;
      new Effect.BackgroundScroll('body', [X_REF*pos, 0], {duration: 0.01});
    }
  }
};
