// Carroussel
var carroussel = {
  nbSlide : 0,
  nbCurrent : 1,
  elemCurrent : null,
  elem : null,
  timer : null,
  
  init : function(elem){
        this.nbSlide = elem.find('.slide').length;      
        // Créer la pagination
        elem.append('<div class="navigation"></div>');
        for(var i=1; i <= this.nbSlide; i++)
        {
          elem.find('.navigation').append('<span>'+i+'</span>');
        }
        elem.find('.navigation span').click(function(){ carroussel.gotoSlide($(this).text())});
        // Initialisation du caroussel
        this.elem = elem;
        elem.find(".slide").hide();
        elem.find(".slide:first").show();
        this.elemCurrent = elem.find(".slide:first");
        this.elem.find('.navigation span:first').addClass('active');
                
        // On crer le timer.
        carroussel.play();        
        // Stop quand on passe dessus.
        elem.mouseover(carroussel.stop);
        elem.mouseout(carroussel.play);
    },
    
    gotoSlide : function(num){
    	
    	if(num == this.nbCurrent)
    	{
    		return false;
    	}
    	/* Animation en fadeIn/fadeOut
    	this.elemCurrent.fadeOut();
    	this.elem.find('#slide'+num).fadeIn();
    	*/
    	/* Animation en slide */
    	var cssDep = {'left' : this.elem.width()};
    	var cssFin = {'left' : -this.elem.width()};
    	
    	this.elem.find('#slide'+num).show().css(cssDep);
    	
    	this.elem.find('#slide'+num).animate({'top':0, 'left':0}, 500);
    	this.elemCurrent.animate(cssFin, 500);
    	
    	this.elem.find('.navigation span').removeClass('active');
    	this.elem.find('.navigation span:eq('+(num-1)+')').addClass('active');
    	this.nbCurrent = num;
    	this.elemCurrent = this.elem.find('#slide'+num);
    	
    },
    
    next : function(){
    	var num = this.nbCurrent + 1;
    	if(num > this.nbSlide)
    	{
    		num = 1;
    	}
    	this.gotoSlide(num);
    	
    },
    
    prev : function(){
    	var num = this.nbCurrent - 1;
    	if(num < 1)
    	{
    		num = this.nbSlide;
    	}
    	this.gotoSlide(num);
    	
    }, 
    
    stop : function(){
    	window.clearInterval(carroussel.timer);
    },
    
    play : function(){
    	window.clearInterval(carroussel.timer);
    	carroussel.timer = window.setInterval('carroussel.next()', 5000);
    }
  }

$(function(){
  carroussel.init($('#caroussel')); 
  
});

function getXhr(){
    var xhr = null; 
	if(window.XMLHttpRequest) // Firefox et autres
		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 envoyerMail(mesParametrePost){
    		
	var xhr = getXhr();
		
	// 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 reþu et que le serveur est ok
	if(xhr.readyState == 4 )
		{											
			  //alert(xhr.responseText);								        
			alert(xhr.responseText);
		}			
	}
				
	// Ici on va voir comment faire du post
	xhr.open("POST","envoiMail.php",true);
	// ne pas oublier þa pour le post
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');

	var data = mesParametrePost;
	xhr.send(unescape (data));
	
}
