
var unobtrusive_scroller = new Class({
	initialize: function() {
		this.scroller = null;
		this.y_value = 0;

		window.addEvent('load',this.prepare.bindAsEventListener(this));
	},

	prepare: function() {
        if ($.noConflict) { // Tell jQuery to bugger off if it's loaded.
            $.noConflict();
        }
        
		var scroller = $$('body')[0].getElementsByClassName('scroller');
		for(a=0;a<scroller.length;a++) {
			var size = scroller[a].getSize();
			var scroll_height = size.scrollSize.y;
			var overflow = scroll_height - size.size.y;
			
			if (overflow > 0) {

				var me = this;
				scroller[a].addEvent('mouseenter', function() {
					if (me.scroller != null) {
						me.scroller.stop();
					}
				});

				scroller[a].addEvent('mouseleave', function() {
					if (me.scroller != null) {
						me.scroller.options.duration = (me.y_value - this.getSize().scroll.y) * 70;
						me.scroller.scrollTo(0, me.y_value);
					}
				});

				scroller[a].innerHTML += scroller[a].innerHTML;
				this.scroll(scroller[a], scroll_height);
			}
		};
	},
	
	scroll: function(el,y) {
		this.scroller = new Fx.Scroll(el,{
			'transition':Fx.Transitions.linear,
			'duration':(y * 70),
			'wheelStops':false,
			'onComplete': function() {
				var _this = this.options._this;
				var el = this.options._el;
				var y = this.options._y;
				el.scrollTo(0,0);
				_this.scroll(el,y);
			},
			'_this': this,
			'_el': el,
			'_y': y
		});
		this.y_value = y;
		this.scroller.scrollTo(0,y);
	}

});

