// scroll object: makes a browser-independent object for easy 2D scrolling or animation

function makeScrollObj(objId,layerId,parent){
	if (document.getElementById) {
		// IE
		this.style = document.getElementById(layerId).style; 
		this.style.top=0; this.style.left=0;
		this.unit = 'px';
		this.scrollHeight = document.getElementById(layerId).offsetHeight;
		this.scrollWidth = document.getElementById(layerId).offsetWidth;
		
		this.clipHeight = document.getElementById(parent).offsetHeight;
		this.clipWidth = document.getElementById(parent).offsetWidth;
		
	} else if (document.all) {
		// ?
		this.style = eval('document.all.'+layerId+'.style');
		this.style.top=0; this.style.left=0;
		this.unit = 'px';	
		this.scrollHeight = eval('document.all.'+layerId+'.offsetHeight');
		this.scrollWidth = eval('document.all.'+layerId+'.offsetWidth');
		
		this.clipHeight = eval('document.all.'+parent+'.offsetHeight');
		this.clipWidth = eval('document.all.'+parent+'.offsetWidth');
		
	} else if (document.layers) {
		// NS
	    thisParent=(parent)? 'document.'+parent+'.':'';
		
	    this.style = eval(thisParent+'document.'+layerId);
		this.unit = '';
		this.scrollHeight = this.style.document.height;	
		this.scrollWidth = this.style.document.width;	
		
		this.clipHeight = eval(thisParent+'clip.height');
		this.clipWidth = eval(thisParent+'clip.width');
		
	}
	
    this.id   = objId;
    this.top  = getTop;
    this.left = getLeft;
	this.setTop  = setTop;
	this.setLeft = setLeft;
	this.moveTo  = moveTo;
}
function getTop() {return parseInt(this.style.top);}
function getLeft() {return parseInt(this.style.left);}
function setTop(y) {this.style.top=y+this.unit;}
function setLeft(x) {this.style.left=x+this.unit;}
function moveTo(x,y) {this.style.left=x+this.unit; this.style.top=y+this.unit;}

// Scroll Variables
var scrollTimer = new Array();	// timeouts for each scrolling object

function scroll(obj,vx,vy){
    if (scrollTimer[obj.id]) clearTimeout(scrollTimer[obj.id]);
    px=obj.left(); py=obj.top();
    px+=vx; xMin=0; xMax=obj.clipWidth-obj.scrollWidth;
    py+=vy; yMin=0; yMax=obj.clipHeight-obj.scrollHeight;
	if(px<xMax){px=xMax;vx=0;} if(px>xMin){px=xMin;vx=0;}
	if(py<yMax){py=yMax;vy=0;} if(py>yMin){py=yMin;vy=0;}
	obj.setLeft(px); obj.setTop(py);
    if (vy!=0 || vx!=0) scrollTimer[obj.id]=setTimeout("scroll("+obj.id+","+vx+","+vy+")",iGlobalSpeed);
}
function noScroll(obj){
    if (scrollTimer[obj.id]) clearTimeout(scrollTimer[obj.id]);
}