
var x = -1; // nombre de tour
var pos = 1;
var nbserv = 6;

var infosInterval;

var noAutoMove = false;

var ajaxInProgress = false;

var oldMarge = 0;
var stopAnim = false;

function infoserv() {
	
	if (stopAnim) {
		return;
	}
	
	if (x == -1) {
		getinfo();
		x++;
	} else {	
		if (!noAutoMove) {
			moveinfoserv(1);
		}
		
		if (x == 6) {
			x=-1;
		}
	}
}

function moveinfoserv(sens) {

	if (sens == 1) {
		if (pos < nbserv) {
			var m = $("#servinfodata").css("margin-top");
		
			var m2 = m.substr(0,(m.length-2));
			m2 = parseInt(m2);	
			m2 = m2 - 13;
			
			$("#servinfodata").animate( { marginTop: m2+"px"}, 300 );

			pos = pos +1;
		} else {
		
			$("#servinfodata").animate( { marginTop: "0px"}, 300 );
			pos = 1;
			x++;
		}	
	} else {
	
		if (pos > 1) {
			var m = $("#servinfodata").css("margin-top");
		
			var m2 = m.substr(0,(m.length-2));
			m2 = parseInt(m2);	
			m2 = m2 + 13;
			
			$("#servinfodata").animate( { marginTop: m2+"px"}, 300 );

			pos = pos - 1;
		} else {
		
			var maxmarge = (nbserv-1) * 13;
			maxmarge = -maxmarge;
		
			$("#servinfodata").animate( { marginTop: maxmarge+"px"}, 300 );
			pos = nbserv;
			x++;
		}	
	
	}
}

function infoservprev() {
	noAutoMove = true;
	moveinfoserv(-1);
}
function infoservnext() {
	noAutoMove = true;
	moveinfoserv(1);
}

function getinfo() {

	if (ajaxInProgress)
		return;

	var rnd = Math.random();
	
	ajaxInProgress = true;
	$.post("/ajax.php", { rand: rnd, code: 3 }, function(data){
		//alert(data);
		ajaxInProgress = false;
		$("#servinfodata").html(data);
	});
}

 $(document).ready(function() {
	infoserv();
	infosInterval = setInterval("infoserv()",6500);  
	
	
	$("#servinfodata").mouseover(function() {
		stopAnim = true;
		oldMarge = $("#servinfodata").css("margin-top");
		$("#servinfodata").css("margin-top","0px");
		$("#bandoserv").css("height","auto");
		$("#bandoserv").css("overflow","auto");
		$("#servinfodata").css("position","absolute");
		$("#servinfodata").css("height", (nbserv*13) );
		
	});
	
	$("#servinfodata").mouseout(function() {
		stopAnim = false;
		$("#servinfodata").css("margin-top",oldMarge);
		$("#bandoserv").css("height","");
		$("#bandoserv").css("overflow","");
		$("#servinfodata").css("position","");		
		$("#servinfodata").css("height","");
	});
	
 });
