window.onload( function() {
	//Le clic sur le gros pavé de zoom le referme, effet zoomOut
	$('zoom').onclick = function() {
		//Si le Alt est stabilizé, on le déstabilise et on le vire
		if ( stabilized ) {
			destabilizeAlt();
			hideAlt();
		}
		else { //Sinon, on dézoom
			startZoomOut.call($('zoom'));
		}
	}
	//Quand on enfonce une touche, on mémorise la taille du champ
	$('search').onkeydown = function() {
		searchLength = this.value.length;
	}
	//Dès qu'on relâche ma touche pressée sur le champ de recherche, on lance une recherche avec délai
	$('search').onkeypress = searchChanged;
	//Si on click sur le champ de recherche, on lance la recherche aussi
	$('search').onclick = searchChanged;
	//Dès qu'on quitte le champ d'ajout d'une URL ou du mail, on check si le formulaire est bon
	$('url').onblur = checkForm;
	$('email').onblur = checkForm;
	//Quand on clic sur le bouton, ça soumet le formulaire
	$('submit').onclick = submitForm;
	//On traque les déplacements sur la carte
	$('events').onmousemove = move;
	//Clic sur la carte, on zoom
	$('events').onclick = click;
	//Quand on quitte la liste de résultats, on la cache
	$('results').onmouseover = function() { show('results'); }
	$('results').onmouseout = function() { hide('results'); }
	//Quand on arrive sur le champ de recherche, on montre les résultats s'il y en a
	$('search').onmouseover = function() { if ( $('results').innerHTML != '' ) show('results'); }
	$('search').onmouseout = function() { hide('results'); }
	//Dès qu'on clic dans le champ pour mettre l'URL du site
	$('url').onclick = function() {
		this.style.color = 'black';
		this.value = '';
		this.onclick = function() {}
		this.onfocus = function() {}
	}
	$('url').onfocus = $('url').onclick;
	//Idem pour le titre
	$('titre').onclick = function() {
		this.style.color = 'black';
		this.value = '';
		this.onclick = function() {}
		this.onfocus = function() {}
	}
	$('titre').onfocus = $('titre').onclick;
	//Et la zone de recherche
//	$('search').onclick = function() {
//		this.style.color = 'black';
//		this.value = '';
//		this.onclick = searchChanged;
//		this.onfocus = function() {}
//	}
	$('search').onfocus = $('search').onclick;
//	$('params').onmouseover = function() {
//		$('label-option').style.visibility = 'hidden';
//		this.style.width = 212+'px';
//	}
//	$('params').onmouseout = function() {
//		$('label-option').style.visibility = 'visible';
//		this.style.width = 10+'px';
//	}
	//On met le focus sur search
	$('search').focus();
	//Quand on clic sur le titre de la carte sélectionnée
	$('titreCarte').onclick = function() {
		//On montre/cache le sélecteur de carte
		$('selectCarte').style.visibility = ( $('selectCarte').style.visibility == 'visible' ? 'hidden' : 'visible' );
		//On ajuste le top du sélecteur
		$('selectCarte').style.top = ($('titreCarte').offsetTop+$('titreCarte').offsetHeight-1)+'px';
	}
	//On place le sélecteur de carte au même left que le titre
	$('selectCarte').style.left = $('titreCarte').offsetLeft+'px';
	//Pour chaque item dans le sélecteur
	for (var i=0; i < $('selectCarte').childNodes.length; i++) {
		var li = $('selectCarte').childNodes[i];
		li.onmouseover = function() {
			this.style.backgroundColor = '#778ECF';
		}
		li.onmouseout = function() {
			this.style.backgroundColor = 'transparent';
		}
	}
});