google.load("maps", "2",{"other_params":"sensor=true"});
                var map = null;
                var geocoder = null;
				var	all_ids = "";
				var	loc = "";
				var	type = "";
				var	serv = "";
				var	the_point1;
				var	the_point2;
				var	current_marker = null;
				var	get = null;
				//Initialise la carte.
				function initialize()
				{
					map = new google.maps.Map2(document.getElementById("map"));
					map.setCenter(new google.maps.LatLng(45.769954,4.833956), 13);
                    geocoder = new GClientGeocoder();
                    map.addControl(new GSmallMapControl());
					showAddress();
				}
				  
				//Place un point, et créé la bulle d'information correspondante a celle ci.
				function	place_point(pc, title, id, bounds)
				{
					if (pc)
					{
						var	point = pc.split(',');
						point = new GLatLng(parseFloat(point[0]), parseFloat(point[1]));
						bounds.extend(point);
						var	marker = new GMarker(point);
						map.addOverlay(marker);
						GEvent.addListener(marker, "click", function() 
															{
																marker.openInfoWindowHtml("<div style=\"width:400px; min-height: 120px; padding-bottom: 10px;\">" + title + "</div>");
																if (current_marker)
																	map.removeOverlay(current_marker);
															});
						map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds) - 1);
					}
				}
					
				//Recupere les elements dans le div adresse, puis les parse pour afficher les markers correspodant.
				function showAddress() 
				{
					var bounds = new GLatLngBounds();
					if (get)
					{
						geocoder.getLatLng(get,
						function(point)
						{
							bounds.extend(point);
							var icon = new GIcon();
							icon.image = "../../wp-content/themes/urban/images/marker_green.png";
							icon.shadow = "../../wp-content/themes/urban/images/shadow.png";
							icon.iconSize = new GSize(20, 34);
							icon.iconAnchor = new GPoint(10, 34);
							icon.infoWindowAnchor = new GPoint(10, 1);
							var	marker = new GMarker(point, icon);
							map.addOverlay(marker);
							marker.openInfoWindowHtml("<div style=\"width:200px;height: auto;\">Votre recherche: " + get + "</div>");
							GEvent.addListener(marker, "click", function() 
																{
																	marker.openInfoWindowHtml("<div style=\"width:200px;height: 80px;\">Votre recherche: " + get + "</div>");
																});
						});
					}
					if (document.getElementById("adresse").innerHTML != "Aucun resultat" && document.getElementById("adresse").innerHTML != "")
					{
						var	adresses = document.getElementById("adresse").innerHTML.split("@");
						jQuery("#nb_result").html(adresses.length - 1);
						document.getElementById("adresse").innerHTML = "";
						var	loop = 0;
						while (loop != adresses.length)
						{
							var	place = adresses[loop].split("#");
							var	pc = place[1];
							if (pc != "")
								place_point(pc, place[0], "0", bounds);
							loop++
						}
					}
					else
						jQuery("#nb_result").html("0");
				}
				
				//Appelle le script php qui recupere les adresses correspondantes au criteres.
				function	load_map(path, id)
				{
					var	to_search = all_ids.substr(0, all_ids.length - 1);
					var	query = "and";
					jQuery(document).ready(function() {
						jQuery("#map").html("<img style='display: block; text-align:center;' src='../../wp-content/themes/urban/images/load.gif' alt='load'/>");
						jQuery.get('../../' + path, {my_cat: to_search, query: query, action: "to_parse" }, function success(data) { jQuery("#adresse").html(data); initialize(); });
						jQuery.get('../../' + path, {my_cat: to_search, query: query, action: "to_display" }, function success(data) { jQuery("#disp_adresse").html(data); });
					});
				}
				
				//Supprime un critere et recharge la carte avec les nouveaux.
				function	remove_param(cat, path, action, title, lng)
				{
					if (action == "loc")
					{
						loc = "";
						jQuery("#loc").html("");
					}
					if (action == "type")
					{
						type = "";
						if (lng == 'en') jQuery("#type").html("All lodgins"); else jQuery("#type").html("Tous les appartements");
					}
					if (action == "serv")
					{
						serv = serv.replace("<img src='wp-content/themes/urban/images/" + title + ".png' alt='" + title + "'/> ", "");
						if (serv == "")
						{
							if (lng == 'en') jQuery("#serv").html("no services"); else jQuery("#serv").html("aucun service");
						}
						else
							jQuery("#serv").html(serv.substr(0, serv.length - 1));
					}
					document.getElementById(cat).style.visibility = 'hidden';
					all_ids = all_ids.replace(" " + cat + ",", "");
					if (loc != "0")
						load_map(path, "0");
					else
						get_nearest('<?php echo $all; ?>', 'wp-content/themes/urban/get_cat_elems.php');
				}
				
				//Definie la valeur des globales pour le centre de la carte.
				function	centerMap(point1, point2)
				{
					the_point1 = point1; 
					the_point2 = point2;
				}
				
				//Ajoute un critere a la recherche et charge la map avec ceux ci.
				function	add_param(cat, path, action, title)
				{
					MyMapHide();
					get = null;
					var	flag = '1';
					if (action == "loc" && loc != "")
					{
						if (loc != "0")
						{
							all_ids = all_ids.replace(" " + loc + ",", "");
							document.getElementById(loc).style.visibility = 'hidden';
						}
						loc = cat;
						jQuery("#loc").html(title);
						jQuery("#adress").html("");
					}
					else if (action == "loc" && loc == "")
					{
						loc = cat;
						jQuery("#loc").html(title);
					}
					/*if (action == "type" && type != "")
					{
						all_ids = all_ids.replace(" " + type + ",", "");
						document.getElementById(type).style.visibility = 'hidden';
						type = cat;
						jQuery("#type").html(title);
					}
					else if (action == "type" && type == "")
					{
						type = cat;
						jQuery("#type").html(title);
					}
					if (action == "serv")
					{
						if (all_ids.indexOf(" " + cat + ",") == -1)
						{
							serv = serv + "<img src='wp-content/themes/urban/images/" + title + ".png' alt='" + title + "'/> ";
							jQuery("#serv").html(serv.substr(0, serv.length - 1));
						}
						else
							flag = null;
					}*/
					document.getElementById(cat).style.visibility = 'visible';
					if (flag == '1')
					{
						all_ids = all_ids + " " + cat + ",";
						if (loc != "0")
							load_map(path, "0");
						else
							get_nearest('<?php echo $all; ?>', 'wp-content/themes/urban/get_cat_elems.php');
					}
				}
				
				//Centre la map sur le logement selectionné, et zoom sur celui ci en affichant une fenetre d'information.
				/*function	centerTheMap(point1, point2, title)
				{
					var	the_title = title.replace(new RegExp("~39","g"), "'");
					map.setCenter(new google.maps.LatLng(point1, point2), 14);
					point = new GLatLng(point1, point2);
					var icon = new GIcon();
					icon.image = "wp-content/themes/urban/images/marker_orange.png";
					icon.shadow = "wp-content/themes/urban/images/shadow.png";
					icon.iconSize = new GSize(20, 34);
					icon.iconAnchor = new GPoint(10, 34);
					icon.infoWindowAnchor = new GPoint(10, 1);
					current_marker = new GMarker(point, icon);
					map.addOverlay(current_marker);
					current_marker.openInfoWindowHtml("<div style=\"width:400px;height: 150px;\">" + the_title + "</div>");
					GEvent.addListener(current_marker, "click", function() 
														{
															current_marker.openInfoWindowHtml("<div style=\"width:400px;height: 150px;\">" + the_title + "</div>");
														});
				}*/
				
				//Localise l'adresse puis place les points les plus proches.
				function	get_nearest(id, path)
				{
					MyMapHide();
					var address = null;
					if (document.getElementById('the_adresse').value == "")
						address = document.getElementById('places').value;
					else
						address = document.getElementById('the_adresse').value;
					get = address;
					var	dist = document.getElementById('the_distance').value;
					jQuery("#adress").html(address + " - " + dist + "km a la ronde");
					jQuery("#loc").html("");
					if (loc != "0" && loc != "")
						all_ids = all_ids.replace(" " + loc + ",", "");
					var	to_search = all_ids.substr(0, all_ids.length - 1);
					if (all_ids != "")
						query = "and";
					else
					{
						to_search = id;
						query = "all";
					}
					if (loc != "0" && loc != "")
						document.getElementById(loc).style.visibility = 'hidden';
					loc = "0";
					geocoder = new GClientGeocoder();
					geocoder.getLatLng(address,
					function(point)
					{
						jQuery(document).ready(function() {
							jQuery("#map").html("<img style='display: block; text-align:center;' src='../../wp-content/themes/urban/images/load.gif' alt='load'/>");
							jQuery.get('../../' + path, {my_cat: to_search, query: query, action: "to_parse_adress", lat: point.lat(), lng: point.lng(), dist: dist }, function success(data) { jQuery("#adresse").html(data); initialize(); });
							jQuery.get('../../' + path, {my_cat: to_search, query: query, action: "to_display_adress", lat: point.lat(), lng: point.lng(), dist: dist }, function success(data) { jQuery("#disp_adresse").html(data); });
						});
					});
				}
				
				function	set_nearest(id, path)
				{
					document.getElementById('the_adresse').value = "";
					get_nearest(id, path);
				}
				
				//Cache le plan et affiche les éléments de recherche.
				function	MyMapHide()
				{
					if (document.getElementById('img').style.display != 'none')
						document.getElementById('img').style.display = 'none';
					if (document.getElementById('recherche').style.display != 'block')
						document.getElementById('recherche').style.display = 'block';
					if (document.getElementById('form').style.display != 'block')
						document.getElementById('form').style.display = 'block';
				}
				//if (document.getElementById('recherche').style.display != none)
					//google.setOnLoadCallback(initialize);
function affiche_bulle(id){
	var posx = 0;
	var posy = 0;
	var e = window.event;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}

	document.getElementById(id).style.display='block';
	

}