function findPos(obj) {
	var x = y = 0;
	if (obj.offsetParent) {
		x = obj.offsetLeft
		y = obj.offsetTop
		while (obj = obj.offsetParent) {
			x += obj.offsetLeft
			y += obj.offsetTop
		}
	}
	// Safari and Opera need some help
	if (Env.browser == 'Safari' || Env.browser == 'Opera') {
		y -= 85;
	}
	return [x,y];
}

function scrollLayer(amt, tim) {
	amount = amt;
	scroll_delay = tim;
	realScroll();
}

function realScroll() {
	clipTop += amount;
	clipBottom += amount;
	topper -= amount;
	if (clipTop < 0 || clipBottom > lyrheight) {
		clipTop -= amount;
		clipBottom -= amount;
		topper += amount;
		return;
	}
	pane.style.clip = 'rect('+clipTop+'px,'+clipWidth+'px,'+clipBottom+'px,0)';
	pane.style.top = topper+'px';
	time = setTimeout('realScroll()', scroll_delay);
}

function stopScroll() { if (time) clearTimeout(time); }

var ScrollButtonWatcher = Class.create();
ScrollButtonWatcher.prototype = {
	initialize: function(buttonId, srcLow, srcHigh, scrollAmount) {
		this.buttonId = buttonId;
		this.srcLow = srcLow;
		this.srcHigh = srcHigh;
		this.scrollAmount = scrollAmount;
		this.html = '<img src="'+this.srcLow+'" alt="" id="'+this.buttonId+'" />';
	},
	display: function() {
		document.write(this.html);
		this.button = $(this.buttonId);
		this.button.onmouseover = this.mover.bindAsEventListener(this);
		this.button.onmouseout = this.mover.bindAsEventListener(this);
		this.button.onmousedown = this.mover.bindAsEventListener(this);
		this.button.onmouseup = this.mover.bindAsEventListener(this);
	},
	mover: function(evt) {
		stopScroll();
		switch (evt.type) {
			case 'mouseover':
				this.button.src = this.srcHigh;
				scrollLayer(this.scrollAmount, 20);
				break;
			case 'mouseout':
				this.button.src = this.srcLow;
				break;
			case 'mousedown':
				scrollLayer(this.scrollAmount*5, 20);
				break;
			case 'mouseup':
				scrollLayer(this.scrollAmount, 20);
				break;
		}
	}
};


function initRcolScrolling() {
	cont = $('scrollingcontainer');
	pane = $('scrollingpane');
	if (typeof(pane) == 'undefined') return false;
	pane.style.display = 'block';
	pane_pos = findPos(pane);
	
	clipTop = 0;
	clipWidth = (pane.hasClassName('table')) ? 590 : 470;
	clipBottom = 390;
	lpad = (pane.hasClassName('table')) ? 0 : 140;

	if ((cont.style.height && pane.scrollHeight > cont.style.height)
		|| (cont.getHeight() && pane.scrollHeight > cont.getHeight())) {
	
		topper = pane_pos[1];
		lyrheight = pane.offsetHeight + 0;
		time = amount = scroll_delay = 0;
	
		pane.style.position = 'absolute';
		pane.style.left = (pane_pos[0] + lpad) + 'px';
		pane.style.top = pane_pos[1] + 'px';
		pane.style.width = clipWidth+'px';
		pane.style.clip = 'rect(0px,'+clipWidth+'px,'+clipBottom+'px,0px)';

		// create scroll buttons
		upScrollButton = new ScrollButtonWatcher('upscrollicon', '/img/tarr_grey.gif', '/img/tarr_white.gif', -2);
		downScrollButton = new ScrollButtonWatcher('downscrollicon', '/img/barr_grey.gif', '/img/barr_white.gif', 2);
		
		return true;
			
	} else {
		
		pane.style.position = 'absolute';
		pane.style.left = (pane_pos[0] + lpad) + 'px';
		pane.style.top = pane_pos[1] + 'px';
		pane.style.width = clipWidth+'px';
		
		return false;

	}
}

function initMcolScrolling() {
	cont = $('scrollingcontainer');
	pane = $('scrollingmcol');
	if (typeof(pane) == 'undefined') return false;
	pane.style.display = 'block';
	pane_pos = findPos(pane);
	clipTop = 0;
	clipWidth = 122;
	clipBottom = thumbcol ? 340 : 390;

	if ((cont.style.height && pane.scrollHeight > cont.style.height)
		|| (cont.getHeight() && pane.scrollHeight > cont.getHeight())) {
	
		topper = pane_pos[1];
		lyrheight = pane.offsetHeight + 0;
		time = amount = scroll_delay = 0;
	
		pane.style.position = 'absolute';
		pane.style.left = pane_pos[0]+'px';
		pane.style.top = pane_pos[1]+'px';
		pane.style.width = clipWidth+'px';
		pane.style.clip = 'rect(0px,'+clipWidth+'px,'+clipBottom+'px,0px)';

		// create scroll buttons
		upScrollButton = new ScrollButtonWatcher('upscrollicon', '/img/tarr_grey.gif', '/img/tarr_white.gif', -2);
		downScrollButton = new ScrollButtonWatcher('downscrollicon', '/img/barr_grey.gif', '/img/barr_white.gif', 2);
		
		return true;
			
	} else {
		
		pane.style.position = 'absolute';
		pane.style.left = pane_pos[0]+'px';
		pane.style.top = pane_pos[1]+'px';
		pane.style.width = clipWidth+'px';
		
		return false;

	}
}