// .arena v2.0 
// .scroll (01.04.01)
// (C) Copyright 2001 por Emiliano Benítez, Israel Pastrana
// Prohibido su uso o distribucion en su totalidad o en parte del codigo sin autorizacion del autor.

arena.scroll = function(name,skin,parent,x,y,w,h,z,spd,res,marg,colBg,cBrd,sBrd,wHor){
	this.id = name;
	this.wHor = wHor;
	this.prop = [x,y,w,h];
	this.bsId = arena("bs"+name,((parent)? parent : null),x,y,w,h,null,z);
	this.wxId = arena("win"+name,"bs"+name,0,0,w,h,null,1,((colBg)? colBg : null));
	this.dxId = arena("dx"+name,"win"+name,0+marg,0+marg,((wHor)? wHor : w-(marg*2)),((wHor)? h-(marg*2) : null),null,1,((colBg)? colBg : null));
	if (cBrd) {
		var aux = (sBrd||1);
		arena("lin"+name,"win"+name,0,0,w,aux,null,4,cBrd);
		arena("lie"+name,"win"+name,0,0,aux,h,null,5,cBrd);
		arena("lis"+name,"win"+name,0,h-aux,w,aux,null,6,cBrd);
		arena("lio"+name,"win"+name,w-aux,0,aux,h,null,7,cBrd);
	}
	this.spd = arena.speed(spd);
	this.res = res;
	this.resLo = res;
	this.resHi = res*3;
	this.timeScr=0;
	this.marg = marg;
	this.onScroll=null;
	this.skinRef=null;
	this.skin = skin;
	eval("this.sSkin"+skin+"()");
}

arena.scroll.prototype.upSpd = function(){ this.res = this.resHi; }
	
arena.scroll.prototype.dwSpd = function(){ this.res = this.resLo; }	
	
arena.scroll.prototype.up = function(){
	var pos = this.dxId.y;
	if (pos < this.marg){
		this.goToPart(0,((this.res+pos >= this.marg)? this.marg-pos : this.res));
		if (this.onScroll) eval(this.onScroll);
		this.timeScr=setTimeout(this.id+".up()",this.spd);
	}
}

arena.scroll.prototype.down = function(){
	var pos = this.dxId.y;
	if (pos > -this.offsetH){
		this.goToPart(0,-((this.res+(-pos) >= this.offsetH)? this.offsetH+pos : this.res));
		if (this.onScroll) eval(this.onScroll);
		this.timeScr=setTimeout(this.id+".down()",this.spd);
	}
}

arena.scroll.prototype.left = function(){
	var pos = this.dxId.x;
	if (pos < this.marg){
		this.goToPart(((this.res+pos >= this.marg)? this.marg-pos : this.res),0);
		if (this.onScroll) eval(this.onScroll);		
		this.timeScr=setTimeout(this.id+".left()",this.spd);
	}
}

arena.scroll.prototype.right = function(){
	var pos = this.dxId.x;
	if (pos > -this.offsetW){
		this.goToPart(-((this.res+(-pos) >= this.offsetW)? this.offsetW+pos : this.res),0);
		if (this.onScroll) eval(this.onScroll);		
		this.timeScr=setTimeout(this.id+".right()",this.spd);
	}
}

arena.scroll.prototype.fill = function(txt,sty){
	this.dxId.fill(((sty)? "<font class="+sty+">" : "")+txt+((sty)? "</font>" : ""),true);
	this.refresh();
}

arena.scroll.prototype.load = function(page){ this.dxId.load(page,true,this.id+".refresh()"); }

arena.scroll.prototype.refresh = function(){
	this.goPart(this.marg,this.marg);
	this.offsetH = this.dxId.h-this.wxId.h+this.marg;
	this.offsetW = this.dxId.w-this.wxId.w+this.marg;
	if (this.skinRef) eval("this.sSkin"+this.skin+"Refresh()");
}

arena.scroll.prototype.goLimit = function(lim){
	var pos = this.dxId.y;
	(lim==0 && pos < this.marg && pos > -this.offsetH)? this.goPart(this.marg,this.marg) : this.goPart(((this.wHor)? -this.offsetW : this.marg),((this.wHor)? this.marg : -this.offsetH));
	if (this.onScroll) eval(this.onScroll);
}

arena.scroll.prototype.goPart = function(x,y){ if (this.offsetH>0) this.dxId.move(x,y); }

arena.scroll.prototype.goToPart = function(x,y){ this.dxId.push(x,y); }

arena.scroll.prototype.stop = function(){ clearTimeout(this.timeScr); }

