$(document).ready(function(){

	$("#contributionButton").click(function(){
		$("#contribution").slideToggle("slow");
		$(this).toggleClass("active"); return false;
	});

 
});



var http;
var globalId;

function createRequestObject() {
  
	var http;

	 // Mozilla, Safari, ...
    if(window.XMLHttpRequest) {
        http = new XMLHttpRequest();
    }

	// Internet Explorer
    else if(window.ActiveXObject) { 
        http = new ActiveXObject("Microsoft.XMLHTTP");
    }

    return http;
}


function vote(id, vote) {
	
	globalId	=	id;

	var voteOn	=	0;
	var voteOff	=	0;

	if (vote == 0) {
		voteOff	=	1;
	} else {
		voteOn	=	1;
	}
	

	// Envoie vers la fonction dites AJAX
    document.getElementById('vote' + globalId).innerHTML	=	'Chargement...';
	http	=	createRequestObject();
	http.open('get', 'http://www.lachetoncom.fr/script/ajaxVote.php?id=' + globalId + '&voteOn=' + voteOn + '&voteOff=' + voteOff, true);
	http.onreadystatechange	=	handleAJAXReturn;
    http.send(null);
}

function fav(id, user) {
	
	globalId	=	id;

	// Envoie vers la fonction dites AJAX
    document.getElementById('vote' + globalId).innerHTML	=	'Chargement...';
	http	=	createRequestObject();
	http.open('get', 'http://www.lachetoncom.fr/script/ajaxFav.php?id=' + globalId + '&user=' + user, true);
	http.onreadystatechange	=	handleAJAXReturn;
    http.send(null);
}

function handleAJAXReturn() {
    if(http.readyState == 4)
    {
        if(http.status == 200)
        {
            document.getElementById('vote' + globalId).innerHTML = http.responseText;
        }
        else
        {
            document.getElementById('vote' + globalId).innerHTML = "<strong>N/A</strong>";
        }
    }
}