var curr_off = 1;
var intervallo = 8000;
var stillmoving = 1;

$(document).ready(function(){
													 
var tot_off = $(".offerte table tr").size();

if(autoscroll) {
	var tempo = setInterval(function () { go_next() }, intervallo);
}

function go_next() {
	if(curr_off<(tot_off-visible_off)) {
		curr_off = curr_off + step_off;
		if(curr_off>=(tot_off-visible_off)) {
			curr_off = (tot_off-visible_off);
			$("#off_down").css({"opacity":"0.3"});
			if(autoscroll && stillmoving==1) {
				var da_capo = setTimeout(function () { go_first() }, intervallo);
			}
		}
		$(".offerte").scrollTo("#off_" + curr_off,200);
		$("#off_up").css({"opacity":"1"});
	}
}

function go_first() {
	$(".offerte").scrollTo("#off_1",200);
	curr_off = 1;
	$("#off_up").css({"opacity":"0.3"});
	$("#off_down").css({"opacity":"1"});
	clearInterval(tempo);
	tempo = setInterval(function () { go_next() }, intervallo);
}

$("#off_down").click(function(event){
		event.preventDefault();
		stillmoving=0;
		go_next();
		if(autoscroll) {
			clearInterval(tempo);
			//tempo = setInterval(function () { go_next() }, intervallo);
		}
});

$("#off_up").click(function(event){
		event.preventDefault();
		stillmoving=0;
		if(curr_off>1) {
			curr_off = curr_off - step_off;
			if(curr_off<=1) { curr_off = 1; $("#off_up").css({"opacity":"0.3"}); }
			$(".offerte").scrollTo("#off_" + curr_off,200);
			if(autoscroll) {
				clearInterval(tempo);
				//tempo = setInterval(function () { go_next() }, intervallo);
			}
		}
		$("#off_down").css({"opacity":"1"});
});

});
