function begin(cpt){
	if(cpt == 1){
		document.getElementById("m2pi4content").style.height = "100px";
	}
	setTimeout("autonext('1','"+cpt+"')",7000);
}
function hide(){
	document.getElementById("m2pi4content").style.overflow = "hidden";
}

function getXhr(){
  
  var xhr = null; 
        
  // Firefox et autres	
  if(window.XMLHttpRequest) 
	{
	   xhr = new XMLHttpRequest(); 
	}
	else if(window.ActiveXObject){ // Internet Explorer 
	  try {
	         xhr = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
			             xhr = new ActiveXObject("Microsoft.XMLHTTP");
		  }
	}
	else { // XMLHttpRequest non supporté par le navigateur 
		   alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
		   xhr = false; 
	} 
  return xhr;
    
}

function next(sens,cpt){
  var xhr    = getXhr();
  var elem   = document.getElementById("move").style;
  
  // On défini ce qu'on va faire quand on aura la réponse
	xhr.onreadystatechange = function(){
		// On ne fait quelque chose que si on a tout recu et que le serveur est ok
	   if(xhr.readyState == 4 && xhr.status == 200){
			var nb = parseInt(xhr.responseText);
			nb=nb*190;
			var top = nb + "px"
			elem.marginTop = top;
			grow("-500","move");
	   }
  }
  var url = "typo3conf/ext/mobit2/pi4/js/ajax.php?l="+cpt+"&s=" + sens;
	xhr.open("GET", url, true);
	xhr.send(null);			
}

function autonext(sens,cpt){
  var xhr    = getXhr();
  var elem   = document.getElementById("move").style;
  var bigger = document.getElementById("m2pi4content").style;
  
  // On défini ce qu'on va faire quand on aura la réponse
	xhr.onreadystatechange = function(){
		// On ne fait quelque chose que si on a tout recu et que le serveur est ok
	   if(xhr.readyState == 4 && xhr.status == 200){
			var nb = parseInt(xhr.responseText);
			nb=nb*190;
			
			var top = nb + "px"
			elem.marginTop = top;
			grow("-500","move");
	   }
  }
  var url = "typo3conf/ext/mobit2/pi4/js/ajax.php?l="+cpt+"&s=" + sens;
	xhr.open("GET", url, true);
	xhr.send(null);
	
	setTimeout("autonext('1','"+cpt+"')",7000);	
}


function grow(debut,div){

	var elem = document.getElementById(div).style;
	var lg;
	var fin;

	lg = parseInt(debut) + 20;
	fin = lg+"px";
	elem.marginLeft = fin;
	if(lg <= 0){
		setTimeout("grow('"+lg+"','"+div+"')",1);
	}else{
		elem.marginLeft = "0px";
	}
}
