var scrolltimer;

function verScroll(dir, spd, loop, fin) {
	loop = true;
	direction = "up";
	
	direction = dir;
	speed = parseInt(spd);
				
	page= eval("document.getElementById('scrollContentDiv').style");
	windowHeight = document.getElementById("scrollWindowDiv").offsetHeight;
	contentHeight = document.getElementById("scrollContentDiv").offsetHeight; 
	offsetHeight = windowHeight - contentHeight ; 
	var y_pos_actual = parseInt(page.top);
	
	ini_top_y = 0; // el passo a mā xq a vegades sino va prou rāpid el valor no estā carregat, és el top de la content
	if ( (ini_top_y - y_pos_actual ) >= Math.abs(offsetHeight)  && direction == "dn"){
		stopScroll();
		return true;
	}
	
	if (loop == true) {
		if (direction == "dn") {
			page.top = (y_pos_actual - (5)); // 5 es el valor de speed
		} else {
			
			if (direction == "up" && y_pos_actual < 0) {
				page.top = (y_pos_actual + (5));
			} else {
				if (direction == "top") {
					page.top = 0;
	    		}
		    }
		}
		scrolltimer = setTimeout("verScroll(direction,5, 'true')", 1);
   }
}

function stopScroll() {
	loop = false;
	clearTimeout(scrolltimer);
}

function init() {
	if (document.getElementById('scrollWindowDiv')) {

		page= eval("document.getElementById('scrollContentDiv').style");
		
		ini_top_y=parseInt(page.top);
		windowHeight =document.getElementById("scrollWindowDiv").offsetHeight;
		contentHeight = document.getElementById("tbl").offsetHeight; 
		offsetHeight = windowHeight - contentHeight ;  // si > 0 llavors scroll
		
		if ( offsetHeight < 0) { 
			document.getElementById("scrollMenu").style.visibility="visible";
		} else {
			document.getElementById("scrollMenu").style.visibility="hidden";
		}
	}
}

