$(function(){ // On appelle la fonction au chargement de la page
	// Elements graphiques (corner) 
   $('#suggestions').hide();
   $('#footer').corner('6px');
      
    //Ajax
        registerAjaxSetUp(); // Fonction qui gère automatiquement les gif de chargement ajax
        // Pagintation Ajax
        $('.numeros-pagination a').live('click',changeList);
        $('#bt-moteur').live('click',changeList2);

           
});

function derouleFormulaire(){
    $('#formulaire-ajout-annonce').slideDown(1500);
}

function enrouleFormulaire(){
    $('#formulaire-ajout-annonce').slideUp(1500);
}

function registerAjaxSetUp(){ 
    $('#loader').ajaxSend(function(){
        $(this).show();
    });
    $('#loader').ajaxSuccess(function(){
        $(this).hide();
    });    
}

// Autocompletion

function lookup(inputString) {
	if(inputString.length == 0) {
		// Hide the suggestion box.
		$('#suggestions').hide();
	} else {
		$.post("library/php/autocompletion/rpc.php", {queryString: ""+inputString+""}, function(data){
			if(data.length >0) {
				$('#suggestions').show();
				$('#autoSuggestionsList').html(data);
			}
		});
	}
} // lookup

function fill(thisValue) {
	$('#ville').val(thisValue);
	setTimeout("$('#suggestions').hide();", 200);
	}

function changeList(){      
    var params=$(this).attr('href');
    // Fondu de la div actuelle
    $('#fonduJquery').animate({
        opacity:0
    },500);
    $.ajax({url:'index.php',
            data:params,
            success:function(response){
                $('#fonduJquery').html(response);
                $('#fonduJquery').animate({
                    opacity:1
                },300,function(){
                    this.style.removeAttribute("filter");    
                });
                registerAjaxSetUp();
            }
    });
    return false;    
}


//Ajax pr le formulaire du moteur de recherche
function changeList2(){      
    var params=$('#form-moteur').serialize();
     //Fondu de la div actuelle
    $('#fonduJquery').animate({
        opacity:0
    },500);
    $.ajax({url:'index.php',
            data:params,
            success:function(response){
                $('#fonduJquery').html(response);
                $('#fonduJquery').animate({
                    opacity:1
                },300);
                registerAjaxSetUp();
            }
    });
    return false;    
}

