// Newsticker class ------------------------------------------------------------
var Ticker = {
	_id: '',
	initialize: function(id){
		_id = id;
    this.list = $(_id).childElements()[0];    
    setTimeout(this.slide_up, 3000);
	},
  slide_up: function(){
    Position.prepare();
    container_y = Position.cumulativeOffset($(_id))[1]
    element_y = Position.cumulativeOffset($(_id).childElements()[0].childElements()[1])[1]
    new Effect.Scroll($(_id), {x:0, y:(element_y-container_y), duration: 1.0, afterFinish: function() {
      //Take first element out and put to end of list
      Ticker.list.insert(Ticker.list.childElements()[0].remove());

      //Now instantly move back to the correct point
      $(_id).scrollTop = 0;
      
      //Set to slide_up again in 3 seconds
      setTimeout(Ticker.slide_up, 3000);
    } });
    return false;
  }
};




//Scriptaculous extension fond from http://elia.wordpress.com/2007/01/18/overflow-smooth-scroll-with-scriptaculous/
Effect.Scroll = Class.create();
Object.extend(Object.extend(Effect.Scroll.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;
    } else {

    }
  },
  update: function(position) {   
    this.element.scrollLeft = this.options.x * position + this.originalLeft;
    this.element.scrollTop  = this.options.y * position + this.originalTop;
  }
});

