//ver 2.0
//04 giugno 2008

var t;
var y = 0;
var pixel = 2;
var totale = 0;//conta la quantità di pixel scorsi
var ritardo = 20;

//dir: 1=destra/giu | -1 = sinistra/su
//axis: 0=orizzontale | 1=verticale
//limite: pixel da scorrere
function scroll(DIV,dir,axis,limite) {
	var x;
	var funzione = (pixel + y*y)/7;
	if (y++ >= 25 || totale>limite) {
		stop();
	}else {
		
		x = Math.round(funzione);
		totale += x;
		if(totale>limite) {
			x -= totale-limite
		}
		if(dir > 0) {
			if(axis==0) {
				document.getElementById(DIV).scrollLeft += x;
			}else if(axis==1){
				document.getElementById(DIV).scrollTop += x;
			}
			t = setTimeout(function () {scroll(DIV,1,axis,limite);},ritardo);
		} else if (dir <= 0){
			if(axis==0) {
				document.getElementById(DIV).scrollLeft -= x;
			}else if(axis==1){
				document.getElementById(DIV).scrollTop -= x;
			}
			t = setTimeout(function () {scroll(DIV,-1,axis,limite);},ritardo);
		}
	}

}

function stop() {
	clearTimeout(t);
	y = 0;
	totale = 0;
}


//questa serve a far resettare lo scorrimento quando si carica la pagina
/*window.onload = function() {
	document.getElementById("galleria").scrollLeft = 0;
}*/
