// auto scroller Giulio de feudis 2008
var AreaAutoScroll = function (id, speed, pause, delayb4scroll, direction){
	direction = direction? 0 : 1; // verical 0 horiz, 1
    pause = (pause)? 0 : 1;
    var div =  $(id);
    var area =  $(div.id+'_scroll');
    if(!(area&&div)) return;
	//div.style.width='auto';
	var t = area.innerHTML;
	var _elementHeight  = (!OM.is.dom? div.Height() : parseInt(area.style.height));
	var _elementWidth  = (!OM.is.dom? div.Width() : parseInt(area.style.width));
	var _rollHeight = 16-_elementHeight;
	var _rollWidth = Math.round(16-_elementWidth/2);
	// public
    this.speed = 1;
    this.setHeight = function(h){
    	_elementHeight=h;
    	_rollHeight = 16-_elementHeight;
    };
    this.setWidth = function(w){
    	_elementWidth=w;
    	_rollWidth = Math.round(16-_elementWidth/2);
    };
	// event
	var _wheel_v = function (){var p=area.y();area.y(((p>0)? p+_rollHeight : ((p>_rollHeight)? p+OM.mouse.wheelDelta*30 : 0)))};
	var _wheel_h = function (){var p=area.x();area.x(((p>0)? p+_rollWidth : ((p>_rollWidth)? p+OM.mouse.wheelDelta*30 : 0)))};
	
	var _wheel = direction? _wheel_v : _wheel_h;
	div.addEvent('mousewheel', function(ev){OM.mouse.wheel(ev, _wheel)});
    var o=this;
	area.addEvent('mouseover', function (){o.speed=pause});
	area.addEvent('mouseout', function (){o.speed=1});
	// action
	area.write(t+t);
	var _scroll_h = function() {var p=area.x();area.x(((p>_rollWidth)? p-o.speed : 0))};
	var _scroll_v = function() {var p=area.y();area.y(((p>_rollHeight)? p-o.speed : 0))};
	var _scroll = direction? _scroll_v : _scroll_h;
	setTimeout(function (){setInterval(_scroll,speed)} , delayb4scroll)
};
