Fx.ScrollWindow = Fx.Base.extend({

	initialize: function(options){
		this.setOptions(options);
		this.now = [];
		var b = document.body;
		var stop = this.clearTimer.bind(this);
		if (!this.options.continuer){
			if (b.addEventListener) b.addEventListener('DOMMouseScroll', stop, false);
			else b.onmousewheel = stop;
		}
	},

	setNow: function(){
		[0,1].each(function(i){
			this.now[i] = this.compute(this.from[i], this.to[i]);
		}, this);
	},

	scrollTo: function(x, y){
		if (this.timer && this.options.wait) return;
		var left = Window.getScrollLeft();
		var top =  Window.getScrollTop();
		var width = Window.getWidth();
		var height = Window.getHeight();
		var fullWidth = Window.getScrollWidth();
		var fullHeight = Window.getScrollHeight();
		var maxScrollWidth = fullWidth - width;
		var maxScrollHeight = fullHeight - height;
		if (x > maxScrollWidth) x = maxScrollWidth;
		if (y > maxScrollHeight) y = maxScrollHeight;
		return this.custom([left, top], [x, y]);
	},

	toElement: function(el, dif){
		return this.scrollTo($(el).getLeft(), $(el).getTop()-(dif ? dif : 0));
	},

	increase: function(){
		window.scrollTo(this.now[0], this.now[1]);
	}

});

