/*
	Scrolling v1.0
	
	Written by Anders Norin
	Contact: contact@impulseye.com
*/
var curSpeed = 5;

if (typeof window.addEventListener != 'undefined') { window.addEventListener('load', initScroll, false); }
else if (typeof window.attachEvent != 'undefined') { window.attachEvent('onload', initScroll); }
else {
	window.onload = function () {
		initScroll();
	}
}

function initScroll() { }

function startScroll(contId,layerId, direct) {
	sTimer = setInterval("scrollLayer('" + contId + "','" + layerId + "'," + direct + ")", 100);
}

function scrollLayer(container, content, dir) {
	cont	= document.getElementById(container);
	lyr		= document.getElementById(content);

	if (dir == "stop")
		stopScroll();
		
	var currPosX, currPosY, lheight, calcstop, speed;
	currPosX 	= lyr.offsetLeft;
	currPosY 	= lyr.offsetTop;
	lheight		= lyr.offsetHeight;
	calcstop	= (cont.offsetHeight - lheight) - 5;
	speed		= curSpeed;
	
	// Direction: Up
	if (dir == 0) {
		if (currPosY < -3)
			lyr.style.top = currPosY + (2 * speed) + "px";
	}
	// Direction: Down
	if (dir == 1) {
		if (currPosY > calcstop)
			lyr.style.top = currPosY - (2 * speed) + "px";
	}
}

function incrSpeed() {
	curSpeed = curSpeed + 4;
}
function decrSpeed() {
	curSpeed = 5;
}

function stopScroll() {
	decrSpeed();
	clearInterval(window.sTimer);
	return;
}
