var cursor_speedCoeff = 0.04;
var cursor_x = 0;
var cursor_xToGo = 0;

var nbMailMax = 400;
var jaugeWidth = 291;
var cursorWidth = 9;

var cursorStartLeft = 1;

//Jauge
function getJauge(firstPass) {
  var nbMails = 0;
  
  var XHR = null;
  if(window.XMLHttpRequest) // Firefox
  	XHR = new XMLHttpRequest();
  else if(window.ActiveXObject) // Internet Explorer
  	XHR = new ActiveXObject("Microsoft.XMLHTTP");
  else { // XMLHttpRequest non supporté par le navigateur
  	alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
  }
  
  var url = "ajax/getJauge.php?action=0&dataprocess="+new Date();
  XHR.open('GET', url, true);
  
  XHR.onreadystatechange = function attente() {
		if (XHR.readyState == 4) {
      nbMails = XHR.responseText;
      
		  var percent = (nbMails < nbMailMax) ? nbMails / nbMailMax * 100 : 100; 
		  var jaugeLeft = Math.round((jaugeWidth - cursorWidth) * percent / 100, 0);
		  if (!firstPass) {
		    var cursor = document.getElementById('hotlineJaugeCursor');
		    cursor_xToGo = jaugeLeft;
		  } else {
		    ajaxSend('GET', 'ajaxHotlineJauge', 'action=1', 'ajax/getJauge.php', true);
		    getJauge(false);
		    moveCursor();
		  }
		}
	}
	
	XHR.send(null);
	
  setTimeout('getJauge(false)', 60000);
}

function moveCursor() {
  var cursor = document.getElementById('hotlineJaugeCursor');
  
  if (cursor) {
    if (cursor_x > cursor_xToGo) {
      var speed = Math.floor(cursor_x * cursor_speedCoeff) + 1;
      cursor_x -= speed;
    } else if (cursor_x < cursor_xToGo) {
      var speed = Math.floor((cursor_xToGo - cursor_x) * cursor_speedCoeff) + 1;
      cursor_x += speed;
    }
    
    cursor.style.left = (cursor_x + cursorStartLeft) + "px";
    
  }
    setTimeout("moveCursor()", 25);
}
