function initEvents()
{
	// Lissage  des polices avec Cufon
	
	Cufon.replace("h2");
	Cufon.replace("h3");
	
	// Fédération
	$("#moteur-recherche_filtres_federation").change(function (e) {
		cleanMoteurRechercheFiltres('federation');
		submitMoteurRechercheFiltres();
	});
	
	// Hippodrome
	$("#moteur-recherche_filtres_hippodrome").change(function (e) {
		cleanMoteurRechercheFiltres('hippodrome');
		submitMoteurRechercheFiltres();
	});
	
	// Prix
	$("#moteur-recherche_filtres_prix_nom").autocomplete('ajax/ajax.recherche_prixs.php', {
		minChars: 1,
		max: 50,
		width: 190,
		dataType: "json",
		parse: function(data) {
	        var parsed = [];

	        for (var i = 0; i < data.length; i++) {
	            parsed[parsed.length] = {
	                data: data[i],
	                value: data[i].prix_nom,
	                result: data[i].prix_nom
	            };
	        }
	 
	        return parsed;
		},
		formatItem: function(item) {
			return item.prix_nom;
		}
	});
	
	$("#moteur-recherche_filtres_prix_nom").result(function(event, data, formatted) {
		if (data)
		{
			cleanMoteurRechercheFiltres('prix');
			$("#moteur-recherche_filtres_prix").val(data.prix_id);
			submitMoteurRechercheFiltres();
		}
	});
	
	// cheval
	$("#moteur-recherche_filtres_cheval_nom").autocomplete('ajax/ajax.recherche_chevals.php', {
		minChars: 1,
		max: 50,
		width: 190,
		dataType: "json",
		parse: function(data) {
	        var parsed = [];

	        for (var i = 0; i < data.length; i++) {
	            parsed[parsed.length] = {
	                data: data[i],
	                value: data[i].cheval_nom,
	                result: data[i].cheval_nom
	            };
	        }
	 
	        return parsed;
		},
		formatItem: function(item) {
			if (item.cheval_suffixe != '' && item.cheval_suffixe != item.cheval_nom)
				return item.cheval_nom + ' (' + item.cheval_suffixe + ')';
			else
				return item.cheval_nom;
		}
	});
	
	$("#moteur-recherche_filtres_cheval_nom").result(function(event, data, formatted) {
		if (data)
		{		
			cleanMoteurRechercheFiltres('cheval');
			$("#moteur-recherche_filtres_cheval").val(data.cheval_id);
			submitMoteurRechercheFiltres();
		}
	});
	
	// jockey
	$("#moteur-recherche_filtres_jockey_nom").autocomplete('ajax/ajax.recherche_jockeys.php', {
		minChars: 1,
		max: 50,
		width: 190,
		dataType: "json",
		parse: function(data) {
	        var parsed = [];

	        for (var i = 0; i < data.length; i++) {
	            parsed[parsed.length] = {
	                data: data[i],
	                value: data[i].jockey,
	                result: data[i].jockey
	            };
	        }
	 
	        return parsed;
		},
		formatItem: function(item) {
			return item.jockey;
		}
	});
	
	$("#moteur-recherche_filtres_jockey_nom").result(function(event, data, formatted) {
		if (data)
		{		
			cleanMoteurRechercheFiltres('jockey');
			$("#moteur-recherche_filtres_jockey").val(data.jockey_id);
			submitMoteurRechercheFiltres();
		}
	});
	
	// porprietaire
	$("#moteur-recherche_filtres_proprietaire_nom").autocomplete('ajax/ajax.recherche_proprietaires.php', {
		minChars: 1,
		max: 50,
		width: 190,
		dataType: "json",
		parse: function(data) {
	        var parsed = [];

	        for (var i = 0; i < data.length; i++) {
	            parsed[parsed.length] = {
	                data: data[i],
	                value: data[i].proprietaire,
	                result: data[i].proprietaire
	            };
	        }
	 
	        return parsed;
		},
		formatItem: function(item) {
			return item.proprietaire;
		}
	});
	
	$("#moteur-recherche_filtres_proprietaire_nom").result(function(event, data, formatted) {
		if (data)
		{		
			cleanMoteurRechercheFiltres('proprietaire');
			$("#moteur-recherche_filtres_proprietaire").val(data.proprietaire_id);
			submitMoteurRechercheFiltres();
		}
	});
	
	// eleveur
	$("#moteur-recherche_filtres_eleveur_nom").autocomplete('ajax/ajax.recherche_eleveurs.php', {
		minChars: 1,
		max: 50,
		width: 190,
		dataType: "json",
		parse: function(data) {
	        var parsed = [];

	        for (var i = 0; i < data.length; i++) {
	            parsed[parsed.length] = {
	                data: data[i],
	                value: data[i].eleveur,
	                result: data[i].eleveur
	            };
	        }
	 
	        return parsed;
		},
		formatItem: function(item) {
			return item.eleveur;
		}
	});
	
	$("#moteur-recherche_filtres_eleveur_nom").result(function(event, data, formatted) {
		if (data)
		{		
			cleanMoteurRechercheFiltres('eleveur');
			$("#moteur-recherche_filtres_eleveur").val(data.eleveur_id);
			submitMoteurRechercheFiltres();
		}
	});
	
	// entraineur
	$("#moteur-recherche_filtres_entraineur_nom").autocomplete('ajax/ajax.recherche_entraineurs.php', {
		minChars: 1,
		max: 50,
		width: 190,
		dataType: "json",
		parse: function(data) {
	        var parsed = [];

	        for (var i = 0; i < data.length; i++) {
	            parsed[parsed.length] = {
	                data: data[i],
	                value: data[i].entraineur,
	                result: data[i].entraineur
	            };
	        }
	 
	        return parsed;
		},
		formatItem: function(item) {
			return item.entraineur;
		}
	});
	
	$("#moteur-recherche_filtres_entraineur_nom").result(function(event, data, formatted) {
		if (data)
		{		
			cleanMoteurRechercheFiltres('entraineur');
			$("#moteur-recherche_filtres_entraineur").val(data.entraineur_id);
			submitMoteurRechercheFiltres();
		}
	});
}

/*
 * Vide les autres champs de recherche
 * @param except
 */
function cleanMoteurRechercheFiltres(except)
{
	if (except != 'federation')
	{
		if ($("#moteur-recherche_filtres_federation"))
			$("#moteur-recherche_filtres_federation").val('-');
	}
	
	if (except != 'hippodrome')
	{
		$("#moteur-recherche_filtres_hippodrome").val('-');
	}
	
	if (except != 'prix')
		$("#moteur-recherche_filtres_prix").val('');

	if (except != 'cheval')
		$("#moteur-recherche_filtres_cheval").val('');
	
	if (except != 'jockey')
		$("#moteur-recherche_filtres_jockey").val('');
	
	if (except != 'proprietaire')
		$("#moteur-recherche_filtres_proprietaire").val('');
	
	if (except != 'eleveur')
		$("#moteur-recherche_filtres_eleveur").val('');
	
	if (except != 'entraineur')
		$("#moteur-recherche_filtres_entraineur").val('');
}

/**
 * Changement d'Url avec les filtres sélectionnés
 */
function submitMoteurRechercheFiltres()
{
	// Url de la page de la page "Trouver une vidéo"
	
	var href = $("#form_moteur-recherche_action").val().replace('.html', '');
	var filtres = '';
	

	
	if ($("#moteur-recherche_filtres_hippodrome").val() != '-')
		filtres += "hippodrome," + $("#moteur-recherche_filtres_hippodrome").val() + ",";
	
	if ($("#moteur-recherche_filtres_prix").val() != '')
		filtres += "prix," + $("#moteur-recherche_filtres_prix").val() + ",";
	
	if ($("#moteur-recherche_filtres_cheval").val() != '')
		filtres += "cheval," + $("#moteur-recherche_filtres_cheval").val() + ",";

	if ($("#moteur-recherche_filtres_jockey").val() != '')
		filtres += "jockey," + $("#moteur-recherche_filtres_jockey").val() + ",";

	if ($("#moteur-recherche_filtres_proprietaire").val() != '')
		filtres += "proprietaire," + $("#moteur-recherche_filtres_proprietaire").val() + ",";

	if ($("#moteur-recherche_filtres_eleveur").val() != '')
		filtres += "eleveur," + $("#moteur-recherche_filtres_eleveur").val() + ",";
	
	if ($("#moteur-recherche_filtres_entraineur").val() != '')
		filtres += "entraineur," + $("#moteur-recherche_filtres_entraineur").val() + ",";
	
	if ($("#moteur-recherche_filtres_federation").val() != '-')
		filtres += "federation," + $("#moteur-recherche_filtres_federation").val() + ",";

	
	if (filtres != '')
	{
		filtres = filtres.substring(0, filtres.length - 1);
		href += ',' + filtres;
	}
	
	href += '.html';
	
	document.location.href = href;
}
