/* onload */
bodyOnload_list = new Array(0);

bodyOnload_add = function(f) {
	
	bodyOnload_list[bodyOnload_list.size()] = f;
}

Event.observe(window, 'load', function() {
	for(var i = 0; i < bodyOnload_list.length; i++)
		bodyOnload_list[i]();
});
/* /onload */

/* scroller */

var JSScroller = Class.create();

JSScroller.prototype = {
	
	initialize: function(target, body, track) {
		
		this.sTarget = target;
		this.target = null;
		this.target = $(this.sTarget); // FIXME
		this.di = 0;
		this.value = 0;
		this.pe = null;
		this.slider = new Control.Slider(body, track, {
			axis: 'vertical',
			onSlide: (function(v) { this.scrollVertical(v); }).bind(this),
			onChange: (function(v) { this.scrollVertical(v); }).bind(this)
		});
	},
	
	start: function(di) {
		
		if(this.target == null)
			this.target = $(this.sTarget);
		
		this.di = di*2;
		
		if(this.pe == null)
			this.pe = new PeriodicalExecuter(this.scroll.bind(this), 0.01);
	},
	
	stop: function() {
		
		this.pe.stop();
		this.pe = null;
	},
	
	scroll: function() {
		
		var val = Math.min(1, this.value + 0.01 * this.di);
		
		this.scrollVertical(val);
		this.slider.setValue(val);
	},
	
	scrollVertical: function(value) {
		
		this.value = value;
		this.target.scrollTop = Math.round(value/this.slider.maximum*(this.target.scrollHeight-this.target.offsetHeight));
	}
};

/* /scroller */
