// based on quirksmode.org's "scrolling layer" http://www.quirksmode.org/js/layerscroll.html
// dropped: legacy browser support
// added: multiple scroll layer support

var s = {}, id = false;
var DHTML = (document.getElementById);
var padding = 10;

function scrollInit (name) {

	if (!DHTML) return;

	var x = document.getElementById(name);
	
    s[name] = {

    	clipTop: 0 + padding,
    	clipBottom: x.parentNode.offsetHeight - padding,
    	clipHeight: x.parentNode.offsetHeight - padding,
    	height: x.offsetHeight,
    	width: x.offsetWidth,
    	top: 0,
    	speed: 0,
    	time: 0
    	
    };

    clipstring = 'rect(' + s[name].clipTop + 'px ' + s[name].width + 'px ' + s[name].clipBottom + 'px 0px)';
    x.style.clip = clipstring;

}

function scrollStart (nm, sp, tm) {
	if (!DHTML) return;
	thelayer = document.getElementById(nm);
	if (!thelayer) return;
    id = nm;
	s[id].speed = sp;
	s[id].time = tm;
	scrollLayer();
}

function scrollLayer () {
	if (!DHTML) return;
    if (id!=false) {
    	var scroll_needed = (s[id].height > s[id].clipHeight);
	    var limit = (s[id].speed < 0) ? ((s[id].clipBottom - padding) >= s[id].height) : (s[id].clipTop <= padding);

	    if ( scroll_needed && !limit ) {
	        s[id].clipTop -= s[id].speed;
	        s[id].clipBottom -= s[id].speed;
	        s[id].top += s[id].speed;
	        clipstring = 'rect(' + s[id].clipTop + 'px ' + s[id].width + 'px ' + s[id].clipBottom + 'px 0px)';
	        thelayer.style.clip = clipstring;
	        thelayer.style.top = s[id].top;

	        setTimeout('scrollLayer()', s[id].time);
	    }
    }
}

function scrollStop() {
	id = false;
}
