// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
var Panoramic = Class.create();

Panoramic.prototype = {
  initialize: function(element,width,speed)
  {
    this.element = $(element);
    this.width = width;
    this.speed = speed || 1;
    this.offset = 0;
    this.velocity = this.speed;
    this.interval = setInterval(this.frame.bind(this), 50)
  },
  
  frame: function()
  {
    this.offset += this.velocity;
    if ( this.offset <= 0 )
    {
      this.offset = 0;
      this.velocity = this.speed;
    }
    if ( this.offset >= this.width )
    {
      this.offset = this.width;
      this.velocity = -this.speed;
    }
    this.element.style.backgroundPosition=this.offset + "px 0px";
  } 
}