// 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 = [0, 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';
  }
});

Effect.ScrollTo = Class.create();
Object.extend(Object.extend(Effect.ScrollTo.prototype, Effect.Base.prototype), {
  initialize: function(element) {
    this.element = $(element);
    this.start(arguments[1] || {});
  },
  setup: function() {
    Position.prepare();
    var offsets = Position.cumulativeOffset(this.element);
    if(this.options.offset) offsets[1] += this.options.offset;
    var max = window.innerHeight ? 
      window.height - window.innerHeight :
      document.body.scrollHeight - 
        (document.documentElement.clientHeight ? 
          document.documentElement.clientHeight : document.body.clientHeight);
    this.scrollStart = Position.deltaY;
    this.delta = (offsets[1] > max ? max : offsets[1]) - this.scrollStart;
  },
  update: function(position) {
    Position.prepare();
    var offset = this.scrollStart + (position*this.delta);
    if(Engine.isMSIE6) {
      document.body.scrollTop = offset;
    }
    else
      window.scrollTo(Position.deltaX, offset)
  }
});

var X_REF = -930, Y_REF = -300;

function slide(x, y) {
  new Effect.BackgroundScroll('frame', [X_REF*x, Y_REF*y], {duration: 1.0});
};

var pos = 0;

function slideFX() {
  slide(pos, 0); 
  if (pos == 4)
    pos = 0;
  else
    pos += 1;
};

function filter_events() {
  var s, e;
  s = new Date($('range_start_at_1i').value + "/" + $('range_start_at_2i').value + "/" + $('range_start_at_3i').value);
  e = new Date($('range_end_at_1i').value + "/" + $('range_end_at_2i').value + "/" + $('range_end_at_3i').value);
  new Effect.BlindUp("all_events", {duration: 0.3, afterFinish: function(){
    $$(".event").each(function(input) {
      if (parseFloat(input.title + "000") - s.getTime() <= 0 || parseFloat(input.title + "000") - e.getTime() >= 0) {
        Element.hide(input);
      } else {
        Element.show(input); 
      }
    }); 
    new Effect.BlindDown("all_events", {duration: 0.5});
  }});
};