var clipTop=new Array();
var clipBottom=new Array();
var topper=new Array();
var lyrheight=new Array();
var time,amount,theTime,theHeight,DHTML;
var n=0;
var agent;


function getObj(name)
{
  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
	if(this.obj!=null){
		this.style = document.getElementById(name).style;
	}
  }
  else if (document.all)
  {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (document.layers)
  {
   	this.obj = document.layers[name];
   	this.style = document.layers[name];
  }
}

function init(elemento,init,bottom,top)
{	
	DHTML = (document.getElementById || document.all || document.layers)
	if (!DHTML) return;
	var x = new getObj(elemento);
	var y = new getObj(init);
	var i = 0;
	if((x.obj==null)||(y.obj==null)){
		return;
	}
	if(y.obj.value)i+=eval(y.obj.value);
	
	clipTop[n]=i;
	clipBottom[n]=bottom+i;
	
	agent=navigator.userAgent;
		
	if (document.layers)
	{
		lyrheight[n] = x.style.clip.bottom;
		x.style.clip.top = clipTop[n];
		x.style.clip.left = auto;
		x.style.clip.right = auto;
		x.style.clip.bottom = clipBottom[n];
		topper[n]=top-i;

	}
	else if (document.getElementById || document.all)
	{
		lyrheight[n] = x.obj.offsetHeight;
		x.style.overflow='hidden';
		
		if(x.obj.offsetHeight<x.obj.scrollHeight && agent.indexOf('Opera')==-1)
		{
			x.obj.scrollTop+=i;
			n++;
			return;
		}
		x.style.overflow='';
		topper[n]=top-i;
		x.style.top=topper[n];
		x.style.clip = 'rect('+clipTop[n]+' auto '+clipBottom[n]+' auto)';
		
		n++;
	}
}

function scrollayer(layername,amt,tim,sbn)
{
	if (!DHTML) return;
	thelayer = new getObj(layername);
	if (!thelayer) return;
	amount = amt;
	theTime = tim;
	n=sbn;
	time=setInterval('realscroll()',theTime);
}

function realscroll()
{
	if (!DHTML) return;
	
	clipTop[n] += amount;
	
	if(thelayer.obj.offsetHeight<thelayer.obj.scrollHeight && agent.indexOf('Opera')==-1)
		{
			thelayer.obj.scrollTop+=amount;
			return;
		}
	clipBottom[n] += amount;
	topper[n] -= amount;
	
	if (clipTop[n] < 0 || clipBottom[n] > lyrheight[n])
	{
		clipTop[n] -= amount;
		clipBottom[n] -= amount;
		topper[n] += amount;
		return;
	}
	if (document.getElementById || document.all)
	{
		clipstring = 'rect('+clipTop[n]+' auto '+clipBottom[n]+' auto)';
		thelayer.style.clip = clipstring;
		thelayer.style.top = topper[n];
	}
	else if (document.layers)
	{
		thelayer.style.clip.top = clipTop[n];
		thelayer.style.clip.bottom = clipBottom[n];
		thelayer.style.top = topper[n];
	}
}

function stopScroll(hid)
{
	if (!time) return;
	var y = new getObj(hid);
	y.obj.value=clipTop[n];
	clearInterval(time);
}
