// JavaScript Document

function getObj(name)
{
  if (document.getElementById)
  {
    this.obj = document.getElementById(name);
	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];
  }
}
/*

|----------------------------------|
| |----------------------| | |UP | |
| |                      | |       |
| |                      | | |---| |
| |                      | | |   | |
| |                      | | | | | |
| |                      | | | | | |
| |                      | | | | | |
| |                      | | |   | |
| |                      | | |   | |
| |                      | | |---| |
| |                      | |       |
| |                      | | |DWN| |
| |----------------------| |-------|
|----------------------------------|

*/

var RT_SCROLLBAR_WIDTH = 11
var RT_CELLSPACE = 2;

var rtScrollboxCount = 0;
var rtScrollboxObjects = new Array();

function RT_ScrollBox(id,anchorname,width,height,text,bgcolor) {

	var ap = new getObj(anchorname);
	
	this.anchor = ap;
    this.id = id
	this.index = rtScrollboxCount++;
    this.top = 0;
    this.left  = 0;
	this.width = width;
	this.height = height;
	this.text = text;
	this.bgcolor = bgcolor;	

	this.clipTop = null;
	this.clipWidth = null;
	this.clipBottom = null;
	
	this.content_height = 0;
 	this.scrollbar_height = 0;
	
	this.thelayer = "";
	this.theTime = null;
	this.time = null;
	this.amount = null;
	this.topper = 0;
	this.scr_amount = 0;
	
	this.Show = RT_ScrollBox_Show;
	this.toString =  RT_ScrollBox_toString;
	
	window["rtScrollboxObjects"][this.index] = this;
}

function RT_ScrollBox_Show() {
       	this.Box = document.createElement("DIV");

		this.Box.id 			= "rt_"+this.id;
		this.Box.name 			= "rt_"+this.id;
		this.Box.style.position = "relative";
		this.Box.style.top 		= this.top;
		this.Box.style.left 	= this.left;
		this.Box.style.width 	= this.width;
		this.Box.style.height 	= this.height;
			
		this.CropBox = document.createElement("DIV");
		this.CropBox.id = "rt_"+this.id+"_cropbox";
		this.CropBox.name = "rt_"+this.id+"_cropbox";
		this.CropBox.style.position = "absolute";
		this.CropBox.style.overflow = "hidden";
		this.CropBox.style.top = RT_CELLSPACE;
		this.CropBox.style.left = RT_CELLSPACE;
		this.CropBox.style.width = this.width - RT_SCROLLBAR_WIDTH - (RT_CELLSPACE*3);
		this.CropBox.style.height = this.height - (RT_CELLSPACE*2);

		var ContentBox = new getObj(this.text);
		this.ContentBox = ContentBox.obj
//		this.ContentBox = document.createElement("DIV");
		this.ContentBox.id = "rt_"+this.id+"_contentbox";
		this.ContentBox.name = "rt_"+this.id+"_contentbox";
		this.ContentBox.style.position = "absolute";
		this.ContentBox.style.top = RT_CELLSPACE;
		this.ContentBox.style.left = RT_CELLSPACE;
		this.ContentBox.style.width = this.width - RT_SCROLLBAR_WIDTH - (RT_CELLSPACE*3);
		this.ContentBox.style.height = this.ContentBox.clientHeight;

		this.ScrollBar = document.createElement("DIV");
		this.ScrollBar.id = "rt_"+this.id+"_scrollbar";
		this.ScrollBar.name = "rt_"+this.id+"_scrollbar";
		this.ScrollBar.style.position = "absolute";
		this.ScrollBar.style.top = (RT_CELLSPACE *2) + RT_SCROLLBAR_WIDTH;
		this.ScrollBar.style.left = this.width - RT_SCROLLBAR_WIDTH - RT_CELLSPACE;
		this.ScrollBar.style.width = RT_SCROLLBAR_WIDTH;
		this.ScrollBar.style.height = this.height - (RT_CELLSPACE*4) - (RT_SCROLLBAR_WIDTH * 2);
		this.ScrollBar.style.pixelHeight = this.height - (RT_CELLSPACE*4) - (RT_SCROLLBAR_WIDTH * 2);
		
		this.Tracker = document.createElement("DIV");
		this.Tracker.id = "rt_"+this.id+"_tracker";
		this.Tracker.name = "rt_"+this.id+"_tracker";
		this.Tracker.style.position = "absolute";
		this.Tracker.style.top = 0;
		this.Tracker.style.left = 0;
		this.Tracker.style.width = RT_SCROLLBAR_WIDTH;
//		Tracker.style.height = this.height - (RT_CELLSPACE*4) - (RT_SCROLLBAR_WIDTH * 2);
/*FIX EXPLORER*/
		this.Tracker.style.fontSize = '0px';
		this.Tracker.style.margin = "0px";
		this.Tracker.style.padding = "0px";			
/*FIX EXPLORER*/

		this.UpBtn = document.createElement("DIV");
		this.UpBtn.id = "rt_"+this.id+"_upbtn";
		this.UpBtn.name = "rt_"+this.id+"_upbtn";
		this.UpBtn.style.position = "absolute";
		this.UpBtn.style.top = RT_CELLSPACE;
		this.UpBtn.style.left = this.width - RT_SCROLLBAR_WIDTH - RT_CELLSPACE;
		this.UpBtn.style.width = RT_SCROLLBAR_WIDTH;
		this.UpBtn.style.height = RT_SCROLLBAR_WIDTH;
		
		this.UpBtn.onmouseover = new Function('RT_ScrollBox_ScrollLayer('+this.index+',-5,100)');
		this.UpBtn.onmouseout = new Function('RT_ScrollBox_StopScroll('+this.index+')');

		this.UpBtn.onmousedown = new Function('RT_ScrollBox_ScrollLayer('+this.index+',-10,100)');
		this.UpBtn.onmouseup = new Function('RT_ScrollBox_StopScroll('+this.index+')');

/*FIX EXPLORER*/
		this.UpBtn.style.fontSize = '0px';
		this.UpBtn.style.margin = "0px";
		this.UpBtn.style.padding = "0px";			
/*FIX EXPLORER*/

		this.DnBtn = document.createElement("DIV");
		this.DnBtn.id = "rt_"+this.id+"_dnbtn";
		this.DnBtn.name = "rt_"+this.id+"_dnbtn";
		this.DnBtn.style.position = "absolute";
		this.DnBtn.style.top = this.height - RT_SCROLLBAR_WIDTH - RT_CELLSPACE;
		this.DnBtn.style.left = this.width - RT_SCROLLBAR_WIDTH - RT_CELLSPACE;
		this.DnBtn.style.width = RT_SCROLLBAR_WIDTH;
		this.DnBtn.style.height = RT_SCROLLBAR_WIDTH;

		this.DnBtn.onmouseover = new Function('RT_ScrollBox_ScrollLayer('+this.index+',5,100)');
		this.DnBtn.onmouseout = new Function('RT_ScrollBox_StopScroll('+this.index+')');

		this.DnBtn.onmousedown = new Function('RT_ScrollBox_ScrollLayer('+this.index+',10,100)');
		this.DnBtn.onmouseup = new Function('RT_ScrollBox_StopScroll('+this.index+')');

/*FIX EXPLORER*/
		this.DnBtn.style.fontSize = '0px';
		this.DnBtn.style.margin = "0px";
		this.DnBtn.style.padding = "0px";			
/*FIX EXPLORER*/

		this.clipTop = 0;
		this.clipWidth = parseFloat(this.CropBox.style.width);
		this.clipBottom = parseFloat(this.CropBox.style.height);

		if (document.layers)
		{
/*NS4*/
			this.content_height = parseFloat(this.ContentBox.obj.offsetHeight);
			this.CropBox.style.clip.top = this.clipTop;
			this.CropBox.style.clip.left = 0;
			this.CropBox.style.clip.right = this.clipWidth;
			this.CropBox.style.clip.bottom = this.clipBottom;			
		}
		else if (document.getElementById || document.all)
		{
			this.content_height = parseFloat(this.ContentBox.clientHeight);
			this.CropBox.style.clip = 'rect('+this.clipTop+' '+this.clipWidth+' '+this.clipBottom+' 0)';
			
			if (this.content_height <= parseFloat(this.ScrollBar.style.height)) 
			{
				this.Tracker.style.height = parseFloat(this.ScrollBar.style.height);
				this.Tracker.style.pixelHeight = parseFloat(this.ScrollBar.style.height);
			}else{
				this.Tracker.style.height = parseFloat(this.ScrollBar.style.height)*parseFloat(this.ScrollBar.style.height)/this.content_height ;				
				this.Tracker.style.pixelHeight = parseFloat(this.ScrollBar.style.height)*parseFloat(this.ScrollBar.style.height)/this.content_height ;				
			}
			this.scrollbar_height = parseFloat(this.ScrollBar.style.height)-parseFloat(this.Tracker.style.height);
		}
		
								
//		document.body.appendChild(this.Box);
		this.anchor.obj.appendChild(this.Box);
		this.Box.appendChild(this.CropBox);
			this.CropBox.appendChild(this.ContentBox);
		this.Box.appendChild(this.ScrollBar);
			this.ScrollBar.appendChild(this.Tracker);
		this.Box.appendChild(this.UpBtn);
		this.Box.appendChild(this.DnBtn);
		
}

function RT_ScrollBox_ScrollLayer(index,amt,tim)
{
	obj = rtScrollboxObjects[index]

	obj.thelayer = obj.ContentBox;
	obj.amount = amt;	
	obj.theTime = tim;
	RT_ScrollBox_RealScroll();
}

function RT_ScrollBox_StopScroll(index)
{
	obj = rtScrollboxObjects[index];

	if (obj.time) clearTimeout(obj.time);
}


function RT_ScrollBox_RealScroll()
{
	obj.clipTop += obj.amount;
	obj.clipBottom += obj.amount;
	obj.topper -= obj.amount;
	obj.scr_amount = (obj.clipTop * obj.scrollbar_height) / (obj.content_height - parseFloat(obj.CropBox.style.height));
	obj.Tracker.style.top = obj.scr_amount;

//debug	
//	obj.Tracker.innerHTML = obj.scrollbar_height+" "+obj.content_height+" "+obj.scr_amount;
	
	if (obj.clipTop < 0)
	{
		obj.clipTop = 0;
		obj.clipBottom = parseFloat(obj.CropBox.style.height);
		obj.topper = 0;
		if (document.getElementById || document.all)
		{
			obj.ContentBox.style.clip = 'rect('+obj.clipTop+' '+obj.clipWidth+' '+obj.clipBottom+' 0)';
			obj.ContentBox.style.top = obj.topper;
		}
		else if (document.layers)
		{
			obj.ContentBox.style.clip.top = obj.clipTop;
			obj.ContentBox.style.clip.bottom = obj.clipBottom;
			obj.ContentBox.style.top = obj.topper;
		}
		obj.Tracker.style.top = 0;
		return;
	}

	if (obj.clipBottom > obj.content_height)
	{
		if (obj.content_height < parseFloat(obj.CropBox.style.height))
		{
			obj.clipTop = 0;
			obj.clipBottom = parseFloat(obj.CropBox.style.height);
			obj.topper = 0;
		}else{
			obj.clipTop = obj.content_height - parseFloat(obj.CropBox.style.height);
			obj.clipBottom = obj.content_height;
			obj.topper = -(obj.content_height - parseFloat(obj.CropBox.style.height));
		}
		
		if (document.getElementById || document.all)
		{
			obj.ContentBox.style.clip = 'rect('+obj.clipTop+' '+obj.clipWidth+' '+obj.clipBottom+' 0)';
			obj.ContentBox.style.top = obj.topper;
		}
		else if (document.layers)
		{
			obj.ContentBox.style.clip.top = obj.clipTop;
			obj.ContentBox.style.clip.bottom = obj.clipBottom;
			obj.ContentBox.style.top = obj.topper;
		}
		obj.Tracker.style.top = obj.scrollbar_height;
		return;
	}
	
	if (document.getElementById || document.all)
	{
		obj.ContentBox.style.clip = 'rect('+obj.clipTop+' '+obj.clipWidth+' '+obj.clipBottom+' 0)';
		obj.ContentBox.style.top = obj.topper;
	}
	else if (document.layers)
	{
		obj.ContentBox.style.clip.top = obj.clipTop;
		obj.ContentBox.style.clip.bottom = obj.clipBottom;
		obj.ContentBox.style.top = obj.topper;
	}

	obj.time = setTimeout('RT_ScrollBox_RealScroll('+obj.index+')',obj.theTime);
}

function RT_ScrollBox_toString() {
    return alert(this.top + " " + this.left+ " " + this.width+ " " + this.height);
}