/* 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 */

/* rolloverImage */
var rolloverImage_className = "rolloverImage";

rolloverImage_init = function(matchBy) {
	
	var s;
	
	if(matchBy)
		s = matchBy;
	else
		s = 'img.' + rolloverImage_className;
	
	$$(s).each(function(o) {
		
		o.observe('mouseover',rolloverImage_over.bind(o));
		o.observe('mouseout',rolloverImage_out.bind(o));
	});
}

rolloverImage_over = function(event) {
	
	document.body.style.cursor = 'pointer';
	event.target.src = event.target.src.replace(/_normal./, "_over.");
}

rolloverImage_out = function(event) {
	
	document.body.style.cursor = 'default';
	event.target.src = event.target.src.replace(/_over./, "_normal.");
}
/* /rolloverImage */

/* scroller */
var JSScroller = Class.create();

JSScroller.prototype = {

    initialize: function(target, body, track) {

        this.sTarget = target;
        this.target = null;
        this.target = $(this.sTarget); // FIXME
        if(this.target == null || this.target == 'undefined')
            return;
        this.target.style.overflow = 'hidden';
        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) {

        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) {
//document.title = 'val:' + value;
        this.value = value;
        this.target.scrollTop = Math.round(value/this.slider.maximum*(this.target.scrollHeight-this.target.offsetHeight));
    }
};
/* /scroller */

/* debug */

DEBUG = function(o,dst) {
	
	var s = '';
	for(var i in o)
		s += i + ':' + o[i] + '\n';
	
	if(dst)
		$(dst).update(s.replace("\n","<br>\n"));
	//else
		alert(s);
}
