/*
		dw_scroll.js, dw_layr_scroll.js
		version date: July 2002
		constructor and basic methods for scrollers
				
		This code is from Dynamic Web Coding 
    at http://www.dyn-web.com/
    Copyright 2001-2 by Sharon Paine 
    See Terms of Use at http://www.dyn-web.com/bus/terms.html
    Permission granted to use this code 
    as long as this entire notice is included.
*/


var scrTimer = 80; // interval between calls to scroll onmouseover
var scrTmId=0;	// for setTimeouts

// control scroll speed/amount
var jump_inc = 100; // amount of scroll per click (jump functions)
// amount of scroll per loop during onmouseover
var movr_inc = 4;		// higher number for faster scroll

function stopScroll() {
	clearTimeout(scrTmId);
	scrTmId = 0;
}

function loadScrLyr(num,lyr,id) {
	if (!pgLoaded) return; // avoid not loaded errors
	if (typeof wndo[num].cnt != "undefined") wndo[num].cnt.hide();
	wndo[num].cnt = new dw_scrollObj(lyr,id);
	wndo[num].cnt.show();
	wndo[num].cnt.shiftTo(0,0);	// restore top/left to 0 
	wndo[num].maxX = wndo[num].cnt.width - wndo[num].width;
	wndo[num].maxY = wndo[num].cnt.height - wndo[num].height
} 


function inchDown(num,inc) {
	if (!pgLoaded||!wndo[num]) return;
	if (scrTmId) clearTimeout(scrTmId);
	var y = parseInt(wndo[num].cnt.css.top);
	if (y>-wndo[num].maxY) { 
		wndo[num].cnt.shiftBy(0,-inc);
		scrTmId = setTimeout("inchDown("+num+","+inc+")",scrTimer);	
	}
}

function inchUp(num,inc) {
	if (!pgLoaded||!wndo[num]) return;
	if (scrTmId) clearTimeout(scrTmId);
	var y = parseInt(wndo[num].cnt.css.top);
	if (y<0) { 
		wndo[num].cnt.shiftBy(0,inc);
		scrTmId = setTimeout("inchUp("+num+","+inc+")",scrTimer);	
  }
}

function inchRight(num,inc) {
	if (!pgLoaded||!wndo[num]) return;
	if (scrTmId) clearTimeout(scrTmId);
	var y = parseInt(wndo[num].cnt.css.left);	
	if (y>-wndo[num].maxX) { 
		wndo[num].cnt.shiftBy(-inc,0);
		scrTmId = setTimeout("inchRight("+num+","+inc+")",scrTimer);	
	}
}

function inchLeft(num,inc) {
	if (!pgLoaded||!wndo[num]) return;
	if (scrTmId) clearTimeout(scrTmId);
	var y = parseInt(wndo[num].cnt.css.left);
	if (y<0) { 
		wndo[num].cnt.shiftBy(inc,0);
		scrTmId = setTimeout("inchLeft("+num+","+inc+")",scrTimer);	
  }
}


function jumpDown(num,jump) {
	if (!pgLoaded||!wndo[num]) return;
	var y = parseInt(wndo[num].cnt.css.top);
	if (y>(-wndo[num].maxY)) { 
		if ((y-jump)>(-wndo[num].maxY)) wndo[num].cnt.shiftBy(0,-jump);
		else wndo[num].cnt.shiftBy(0,-(wndo[num].maxY-Math.abs(y)));	
  }
}

function jumpUp(num,jump) {
	if (!pgLoaded||!wndo[num]) return;
	var y = parseInt(wndo[num].cnt.css.top);
	if (y<0) { 
		if ((y+jump)<=0) wndo[num].cnt.shiftBy(0,jump); 
		else wndo[num].cnt.shiftBy(0,-y); 
	}
}

function jumpRight(num,jump) {
	if (!pgLoaded||!wndo[num]) return;
	var x = parseInt(wndo[num].cnt.css.left);
	if (x>(-wndo[num].maxX)) {
		if ((x-jump)>(-wndo[num].maxX)) wndo[num].cnt.shiftBy(-jump,0);
		else wndo[num].cnt.shiftBy(-(wndo[num].maxX-Math.abs(x)),0);	
  }
}

function jumpLeft(num,jump) {
	if (!pgLoaded||!wndo[num]) return;
	var x = parseInt(wndo[num].cnt.css.left);
	if (x<0) { 
		if ((x+jump)<=0) wndo[num].cnt.shiftBy(jump,0); 
		else wndo[num].cnt.shiftBy(-x,0); 
	}
}

function dw_scrollObj(obj,id,x,y) {
	this.el = (document.getElementById)? document.getElementById(obj): (document.all)? document.all[obj]: (document.layers)? getLyrRef(obj,document): null;
	if (!this.el) return null;
	this.css = (this.el.style)? this.el.style: this.el;
	var px = (document.layers||window.opera)? "": "px";
	this.x = x || 0;	if (x) this.css.left = this.x+px;
	this.y = y || 0;	if (y) this.css.top = this.y+px;
	this.width = (this.el.clientWidth)? this.el.clientWidth: (id && document.getElementById && document.getElementById(id).offsetWidth)? document.getElementById(id).offsetWidth: (this.el.offsetWidth)? this.el.offsetWidth: (this.css.clip.width)? this.css.clip.width: 0;
	this.height = (this.el.offsetHeight)? this.el.offsetHeight: (this.css.clip.height)? this.css.clip.height: 0;
	this.obj = obj + "Obj"; eval(this.obj+"=this");
}


function dw_shiftTo(x,y) {
	if (x!=null) this.x=x; if (y!=null) this.y=y;	
	if (this.css.moveTo) { 
		this.css.moveTo(Math.round(this.x),Math.round(this.y)); 
	} else { 
		this.css.left=Math.round(this.x)+"px"; 
		this.css.top=Math.round(this.y)+"px"; 
	}
}

function dw_shiftBy(x,y) {
	this.shiftTo(this.x+x,this.y+y);
}

function dw_show() {	this.css.visibility = "visible"; }
function dw_hide() { this.css.visibility = "hidden"; }


dw_scrollObj.prototype.shiftBy=dw_shiftBy;
dw_scrollObj.prototype.shiftTo=dw_shiftTo;
dw_scrollObj.prototype.show=dw_show; 
dw_scrollObj.prototype.hide=dw_hide;

function getLyrRef(lyr,doc) {
	if (document.layers) {
		var theLyr;
		for (var i=0; i<doc.layers.length; i++) {
	  	theLyr = doc.layers[i];
			if (theLyr.name == lyr) return theLyr;
			else if (theLyr.document.layers.length > 0) 
	    	if ((theLyr = getLyrRef(lyr,theLyr.document)) != null)
					return theLyr;
	  }
		return null;
  }
}
