var MyScroller = new Class({
	options: {
		velocity: 1
	},
	initialize: function(element, options){
		this.setOptions(options);
		this.element = $(element);
		this.lastPage = null;
		this.coord = this.getCoords.bindWithEvent(this);
		
		this.mouseover = ([window, document].contains(element)) ? $(document.body) : this.element;
		
		this.mouseover.addEvent('mousedown', function() {
			var tempCapture = null;
			if(this.mouseover.setCapture){
				this.mouseover.setCapture();
				tempCapture = this.mouseover;
			}else if(window.captureEvents){
				window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
				tempCapture = window;
			}
			
			tempCapture.addEvent('mousemove', this.coord);
			
			var release = function(){
				if(this.mouseover.releaseCapture){
					this.mouseover.releaseCapture();
				}else if(window.releaseEvents){
					window.releaseEvents(Event.MOUSEMOVE|Event.MOUSEUP);
				}
				tempCapture.removeEvents('mouseup');
				tempCapture.removeEvents('mousemove');
				this.lastPage = null;
			}
			tempCapture.addEvent('mouseup', release.bind(this));
		}.bind(this));
	},
	
	getCoords: function(event){
		this.page = (this.element == window) ? event.client : event.page;
		if(this.lastPage == null){			
			this.lastPage = this.page;
		}
		var el = this.element.getSize();
		var pos = this.element.getPosition();
		var change = {'x': 0, 'y': 0};
		for (var z in this.page){
			change[z] = (this.page[z] - this.lastPage[z]) * this.options.velocity;
		}
		this.element.scrollTo(el.scroll.x - change.x, el.scroll.y - change.y)
		this.lastPage = this.page;	
	}	
});
MyScroller.implement(new Events, new Options);