//Ч
//ʾ:http://demos.mootools.net/Scroller
var Scroller = new Class({

 //̳EventsOptions,UI
 Implements: [Events, Options],

 options: {
  //ʹķΧֵ
  area: 20,
  //ٶ
  velocity: 1,
  //λøıʱ¼
  onChange: function(x, y){
   this.element.scrollTo(x, y);
  }
 },

 //캯
 initialize: function(element, options){
  //ϲ
  this.setOptions(options);
  //õĵǰ
  this.element = $(element);
  //¼Ķ
  this.listener = ($type(this.element) != 'element') ? $(this.element.getDocument().body) : this.element;
  this.timer = null;
 },

 //ʼ
 start: function(){
  //ΪgetCoordsհ󶨵ǰ
  this.coord = this.getCoords.bind(this);
  //ƶ¼
  this.listener.addEvent('mousemove', this.coord);
 },

 //ֹͣ
 stop: function(){
  //Ƴ¼
  this.listener.removeEvent('mousemove', this.coord);
  //ʱ
  this.timer = $clear(this.timer);
 },

 //ȡ
 getCoords: function(event){
  //ȡϢ
  this.page = (this.listener.get('tag') == 'body') ? event.client : event.page;
  //δʱ,֮,ÿ50ִscroll
  if (!this.timer) this.timer = this.scroll.periodical(50, this);
 },

 //
 scroll: function(){
  //ȡǰĳߴ,Ϣ
  var size = this.element.getSize(), scroll = this.element.getScroll(), pos = this.element.getPosition(), change = {'x': 0, 'y': 0};
  //ֱϵϵķ
  for (var z in this.page){
   //ڶ,ҵǰϵĹλòΪ0
   if (this.page[z] < (this.options.area + pos[z]) && scroll[z] != 0)
    //ع(ıȽϿ֪Ϊֵ)
    change[z] = (this.page[z] - this.options.area - pos[z]) * this.options.velocity;
   ///·ƶ,ҵǰǸպ
   else if (this.page[z] + this.options.area > (size[z] + pos[z]) && size[z] + size[z] != scroll[z])
    //ǰ(ıȽϿ֪Ϊֵ)
    change[z] = (this.page[z] - size[z] + this.options.area - pos[z]) * this.options.velocity;
  }
  //ֻҪһϵĹֵҪı,onChange¼,Ҫֵ
  if (change.y || change.x) this.fireEvent('onChange', [scroll.x + change.x, scroll.y + change.y]);
 }

});

