/*
Script: Fx.ScrollWindow.js
	Contains <Fx.ScrollWindow>
	
Author:
	Valerio Proietti, <http://mad4milk.net>

License:
	MIT-style license.
*/

/*
Class: Fx.ScrollWindow
	The Window Scroller effect; scrolls the window to a specified location. Extends <Fx.Base>, inherits all its properties.

Arguments:
	options - the Fx.Base options (see: <Fx.Base>)
*/

Fx.ScrollWindow = Fx.Base.extend({

	initialize: function(options){
		this.element = window;
		this.parent(options);
		this.now = [];
		var b = document.body, stop = this.clearTimer.create({'arguments': false, 'bind': this});
		if (b.addEventListener) b.addEventListener('DOMMouseScroll', stop, false);
		else b.onmousewheel = stop;
	},

	setNow: function(){
		for (var i = 0; i < 2; i++) this.now[i] = this.compute(this.from[i], this.to[i]);
	},

	/*
	Property: scrollTo
		Scrolls the window to the x/y coordinates.
	
	Arguments:
		x - the x coordinate to scroll the window to
		y - the y coordinate to scroll the window to
	*/

	scrollTo: function(x, y){
		if (this.timer && this.options.wait) return this;
		x = Math.min(x, Window.getScrollWidth() - Window.getWidth());
		y = Math.min(y, Window.getScrollHeight() - Window.getHeight());
		return this.custom([Window.getScrollLeft(), Window.getScrollTop()], [x, y]);
	},

	/*
	Property: toElement
		Scrolls the specified element
	
	Arguments:
		el - the $(element) to scroll the window to
	*/

	toElement: function(el){
		return this.scrollTo($(el).getLeft(), $(el).getTop());
	},

	increase: function(){
		window.scrollTo(this.now[0], this.now[1]);
	}

});
