/* dynlite scroll extension- vertical scroll
 * version: 2.1.4/17.11.2003 
 */
function dynscr(name,time,inc)
{	this.name=name;
	this.time=time||35;
	this.inc=inc||7;
	this.timer=null;
window[this.name]=this;
}
dynscr.prototype.init=function()
{	this.cont = new dynobj(this.name);
	this.data = new dynobj(this.name+'Data');
	window[this.name]=this;
	this.css=this.data.css;
	this.start=this.relpos=this.y=0;
	this.end=this.cont.el.offsetHeight-this.data.el.offsetHeight;
	if(this.end<0)
	{	this.initarrw('up','Up')
		this.initarrw('down','Down')
	}
	this.cont.show('inherit');
log.add('- scroll from object '+this.name+' initialised.')	
} 
dynscr.prototype.initarrw=function(dir,name)
{	var adir = 'arr'+dir;
	this[adir] = new dynobj(this.name+name);
		evt.add(this[adir].name,'onmousedown',this.name,dir);
		evt.add(this[adir].name,'onmouseup',this.name,'stop');
		evt.add(this[adir].name,'onmouseout',this.name,'stop');
	this[adir].show('inherit');
}
dynscr.prototype.up=function()
{	if(this.y<this.start)
	{	this.timer=setTimeout(this.name+'.up()',this.time);
		this.relpos=(this.y+this.inc-this.start)/this.end;
	}	
	else
	{	this.relpos=0;
	evt.evoke(this.name,'onscrup');
	}
	this.move(this.relpos);
	if(this.knob)this.knob.move(this.relpos);

}
dynscr.prototype.down=function()
{	if(this.y>this.end)
	{ 	this.timer=setTimeout(this.name+'.down()',this.time);
		this.relpos=(this.y-this.inc-this.start)/this.end;
	}	
	else 
	{	this.relpos=1;
	evt.evoke(this.name,'onscrdown');
	}
	debug.status(this.relpos);
	this.move(this.relpos);
	if(this.knob) this.knob.move(this.relpos);
}
dynscr.prototype.move=function(rel)
{	this.css.top=this.y=parseInt(this.start+rel*this.end);
} 
dynscr.prototype.stop=function()
{	clearTimeout(this.timer);
}
dynscr.prototype.drag=function()
{	page.add(this.name,'draginit()');	
}
dynscr.prototype.draginit=function(top)
{	this.knob=new dynobj(this.name+'Knob');
	this.knob.el.dragobj=this;
	this.bar=new dynobj(this.name+'Bar');
	this.bar.el.dragobj=this;
	this.knob.h=parseInt(this.bar.el.offsetHeight+this.end);
	this.knob.css.height=(this.knob.h<0)?5:this.knob.h;
	this.knob.move=this.move;
	this.top=page.y||top||0;
	this.knob.offset=parseInt(this.bar.el.offsetTop+this.top);
	this.knob.start=this.knob.y=this.hit=0;
	this.knob.end=this.bar.el.offsetHeight-this.knob.el.offsetHeight;
	if(this.end<0)
	{	evt.add(this.knob.name,'onmousedown',dragstart);
		evt.add(this.name+'Bar','onmousedown',barclick);
		if(ns6)	document.addEventListener('mouseup',dragstop,true)
		else document.onmouseup=dragstop;
		window.dragobj=this;
		this.bar.show();
	}
	else this.knob.css.height=0;
log.add('- drag added to object '+this.name+'.');
}
function dragstart(e)
{	(ns6)?document.addEventListener('mousemove',dragmove,true):document.onmousemove=dragmove;
	window.dragobj=(ns6)?e.target.dragobj:event.srcElement.dragobj;
	window.dragobj.hit=(ns6)?e.layerY:event.offsetY+4;
}
function dragmove(e)
{	var obj=window.dragobj;
	var y=(ns6)?e.pageY:event.clientY;
	var posy=y-obj.knob.offset-obj.hit;
	if(posy<0) posy=0;
	else if(posy>obj.knob.end) posy=obj.knob.end;
	obj.move(posy/obj.knob.end);
	obj.knob.move(posy/obj.knob.end);
	if(ns6)e.preventCapture();
return false;
}
function dragstop(e)
{	(ns6)?document.removeEventListener('mousemove',dragmove,true):document.onmousemove=null;
}
function barclick(e)
{	window.dragobj=(ns6)?e.target.dragobj:event.srcElement.dragobj;
	var obj=window.dragobj;
	var el=(ns6)? e.target:event.srcElement;
	if(el.id!=obj.name+'BarDiv') return true;
	else
	{	var clickY=(ns6)?e.layerY:event.offsetY+4;
		var relPos=clickY/obj.bar.el.offsetHeight;
		obj.move(relPos);
		obj.knob.move(relPos);
	}
}
dynscr.prototype.scrollTo=function(relPos)
{	if(!this.knob) return;
	this.move(relPos);
	this.knob.move(relPos);
}