    //<![CDATA[

	// to see: http://gmaps-utility-library.googlecode.com/svn/trunk/markermanager/release/examples/google_northamerica_offices.html

	// used to keep already loaded icons
	var icons = {};
	var g_itnr_icon = null;
	var map;
	var userPosition = null;
	var totalDistance = new Number(0);
	var g_infoWnd = null;
	var markersArray = [];
	var myMarkerImage = new google.maps.MarkerImage('http://www.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png');
	var myShadowImage = new google.maps.MarkerImage('http://guesmob-com.googlecode.com/files/new-marker-shadow.png',
	      new google.maps.Size(58, 45),
	      new google.maps.Point(0,0),
	      new google.maps.Point(19,44));

                
	function FindPlace(marker)
	{
		if (!marker)
			return null;
			
        for (var j in PlushPositionPlaces)
		{
			var place = PlushPositionPlaces[j];
			
			if (marker.pet == place["name"])
			{
				var returnObj = new Object;
				
				if ((marker.getPosition().lat() == place["posn"][0]) && (marker.getPosition().lng() == place["posn"][1]))
				{
					returnObj.place = place;
					returnObj.location = place["posn"][2];
					return returnObj;
				}
				
				for (var k in place["itnr"])
				{
					if ((marker.getPosition().lat() == place["itnr"][k][0]) && (marker.getPosition().lng() == place["itnr"][k][1]))
					{
						returnObj.place = place;
						returnObj.location = place["itnr"][k][2];
						return returnObj;
					}
				}
			}
		}
		
		return null;
	}
	
    function getIcon(imageLink)
	{
		var icon = null;
		if (imageLink)
		{
			var size = 32;
			icon = new google.maps.MarkerImage(
				"pets/"+imageLink,  // url
				new google.maps.Size(size, size)  // size
			); 
		}
		return icon;
    }
	
	function getItnrIcon()
	{
		if (g_itnr_icon == null)
		{
			var size = 6;
			icon = google.maps.MarkerImage(
				"marker.png",   // url
				new google.maps.Size(size, size)  // size
			);
			
			g_itnr_icon = icon;
		}
		
		return g_itnr_icon;
	}
	
	function zoomOnMarker()
	{
		map.setCenter(this.getPosition(), map.getZoom() + 5);
	}

	function GetInfoWnd()
	{
		if (g_infoWnd != null)
			return g_infoWnd;
		
		g_infoWnd = new google.maps.InfoWindow();
		return g_infoWnd;
	}
	
	function showMarkerInfo()
	{
		var placeObj = FindPlace(this);
		var place = placeObj.place;
		var location = placeObj.location;
		if (place)
		{
			var title = place["name"];
			var imageUrl = "pets/"+place["icon"];
			var description = location;
			//var imagefile = place["name"] + ".png";
			var bubbleContent = "<div style='width:250px'><b><img src=\""+imageUrl+"\" width='32' height='32' />" + title + "</b><br/><br/>" + description + "</div>";
			
			infowindow = GetInfoWnd();
			infowindow.close();
			infowindow.setOptions(
      			{ content: bubbleContent,
        			size: new google.maps.Size(30,30)});
  			infowindow.open(map, this);
		}
	}

    function setupPlushMarkers(map)
	{
		// map.clearOverlays();
		
        for (j = 0; j < PlushPositionPlaces.length; j++)
		{
			var place = PlushPositionPlaces[j];
			
			if (place["name"] == PlushName || PlushName.toLowerCase() == "all")
			{
				var icon = getIcon(place["icon"]);
				var title = place["desc"];
				var itnrArray = new google.maps.MVCArray();
				var color = place["colr"];
				
				var posn = new google.maps.LatLng(place["posn"][0], place["posn"][1]);

				for (jeanmichel = 0; jeanmichel < place["itnr"].length; jeanmichel++)
	            		{
					// insert into itinerary
					var itnr_pos = new google.maps.LatLng(place["itnr"][jeanmichel][0], place["itnr"][jeanmichel][1]); 
	         		   	itnrArray.push(itnr_pos);

					var marker = new google.maps.Marker( {
	                                        position: itnr_pos,
	                                        map: map,
	                                        title: place["name"] + ' in ' + place["itnr"][jeanmichel][2] + ' [' + (jeanmichel+1) + '/' + (place["itnr"].length+1) + ']'
						});

					marker.pet = place["name"];
		                        google.maps.event.addListener(marker, "dblclick", zoomOnMarker);
		                        google.maps.event.addListener(marker, "click", showMarkerInfo);
				}
				// we now set our current position (end of trip)
				itnrArray.push(posn);
				var polyOptions = {
						geodesic: true,
						map: map,
						path: itnrArray,
						strokeColor: color,
						strokeOpacity: 0.7
						};
				var polyline = new google.maps.Polyline(polyOptions);

				var marker = new google.maps.Marker( {
						position: posn,
						map: map,
						title: title, 
						icon: icon,
						zIndex: 10000 // should be on top
					});
				marker.pet = place["name"];

				google.maps.event.addListener(marker, "dblclick", zoomOnMarker);
				google.maps.event.addListener(marker, "click", showMarkerInfo);
			}
        }
    }
	
    function setupPlushPostsMarkers(map)
	{
		// map.clearOverlays();
		
        for (j = 0; j < PlushPositionPlaces.length; j++)
		{
			var place = PlushPositionPlaces[j];

			// do not show if no position
			if (place["posn"][0] == 0 && place["posn"][1] == 0)
				continue;
			
			var color = place["colr"];
			
			// add itinerary
			for (jeanmichel = 0; jeanmichel < place["itnr"].length; jeanmichel++)
			{
				var itnr_posn = new google.maps.LatLng(place["itnr"][jeanmichel][0], place["itnr"][jeanmichel][1]);
				var marker = new google.maps.Marker( {
						position: itnr_posn,
						map: map,
						title: place["name"] + ' in ' + place["itnr"][jeanmichel][2]});
				marker.pet = place["name"];
				google.maps.event.addListener(marker, "dblclick", zoomOnMarker);
				google.maps.event.addListener(marker, "click", showMarkerInfo);
			}
			
			// add current position
			var posn = new google.maps.LatLng(place["posn"][0], place["posn"][1]);
			var marker = new google.maps.Marker( {
					position: posn,
					map: map,
					title: place["name"] + ' in ' + place["posn"][2]});
			marker.pet = place["name"];
			google.maps.event.addListener(marker, "dblclick", zoomOnMarker);
			google.maps.event.addListener(marker, "click", showMarkerInfo);
        }
    }

	function setupPicturesMarkers(results)
	{
		//Move an existing Marker
		if (markersArray[iCurrentImage])
		{
			markersArray[iCurrentImage].setPosition(results[0].geometry.location);
		}
		else
		{
			var title = "Picture " + iCurrentImage;
			markersArray[iCurrentImage] = new google.maps.Marker({position: results[0].geometry.location, map:map, title:title});
		}
	}
	
	function showLocation(posn)
	{
		// map.clearOverlays();
	
		var marker = new google.maps.Marker(
			{ position: posn, 
			  map: map,
			  title: "Your location."} );
		
		// add the marker to the map
		map.addOverlay(marker);
		
		google.maps.event.addListener(marker, "click", zoomOnMarker);
		
		userPosition = posn;
		
		//map.setCenter(posn, 3 /* zoom */);
		
		enablePlaceSubmitButton(true);
		
		return;
	}
	
	function enablePlaceSubmitButton(bEnable)
	{
		var		button = document.getElementById("place_submit");
		var 	form = document.getElementById("location_form");

		var address = form.address.value;
		var city = form.city.value;
		
		if ((address != "") || (city != ""))
		{
			form.address.disabled = bEnable;
			form.city.disabled = bEnable;
			
			button.disabled = !bEnable;
		}
		else
		{
			button.disabled = true;
		}

		return;
	}
	
	function clearForm()
	{
		enablePlaceSubmitButton(false);
		var form = document.getElementById("location_form");
		
		form.address.value = "";
		form.city.value = "";
		
		userPosition = null;
		
		locatePlace(form);
		
		return false;
	}
	
	function locatePlace(form)
	{
		var address = form.address.value;
		var city = form.city.value;
		var country = form.country.value;
		
		enablePlaceSubmitButton(false);
		map.clearOverlays();
		
		if (country == "")
		{
			return false;
		}
		
		var clientDecoder = new GClientGeocoder();
		
		clientDecoder.getLatLng(address + " " + city + " " + country, showLocation);
		
		// important: do not change to true: we don't want to submit
		return false;
	}
	
	function initLocationForm()
	{
		var form = document.getElementById("location_form");
		
		form.country.disabled = true;
		
		locatePlace(form);
		
		enablePlaceSubmitButton(false);
		
		return true;
	}
	
	function sendPlace()
	{
		var form = document.getElementById("location_form");
		
		var address = form.address.value;
		var city = form.city.value;
		var country = form.country.value;
		
		if (userPosition != null)
		{
			//userPosition : contains the  GLatLng of the given address.
			alert("Address: " + address + " " + city + " " + country + "  (" + userPosition.lat() + " , " + userPosition.lng() + ").");
		}
		
		return false;
	}

	var iCurrentImage = 0;
	
	function findlocation_callback(results, status)
	{
		if (status != google.maps.GeocoderStatus.OK)
			return;

		document.getElementById("latitude" + iCurrentImage).value = results[0].geometry.location.lat();
		document.getElementById("longitude" + iCurrentImage).value = results[0].geometry.location.lng();
		
		//Add picture location
		if (document.getElementById("map"))
			setupPicturesMarkers(results);
		return;
	}
	
	function adduserlocation_callback(results, status)
	{
		//Check status
		if (status != google.maps.GeocoderStatus.OK)
			return;
		//Check we do have a map
		if (!document.getElementById("map"))
			return;
		//Add user location marker
		var marker = new google.maps.Marker({position: results[0].geometry.location, map:map, icon:myMarkerImage, shadow:myShadowImage, title:"You are here"});
	}
	
	function findlocation(iImage)
	{
		var country = document.getElementById("loc_country").value;
		var city = document.getElementById("city" + iImage).value;
		var address = document.getElementById("address" + iImage).value;
		
		if (address == "Address")
			address = "";
		if (city == "City")
			city = "";

		iCurrentImage = iImage;
		
		var geocoder = new google.maps.Geocoder();
		geocoder.geocode( { 'address': address + ", " + city + ", " + country}, findlocation_callback);
		//var clientDecoder = new GClientGeocoder();
		//clientDecoder.getLatLng(address + ", " + city + ", " + country, findlocation_callback);
	}
	
	//Map used to visualize the pictures geolocation
	function loadPicLocator()
	{
		//Do not load map if no map
		if (!document.getElementById("map"))
			return;
		
		var myLatlng = new google.maps.LatLng(30, 4);
		var myOptions = {
  			zoom: 1,
  			center: myLatlng,
			mapTypeId: google.maps.MapTypeId.ROADMAP,
			navigationControl: true,
  			mapTypeControl: true,
  			scaleControl: true,
			scrollwheel: true
		};
		//Creates the pic locator map
		map = new google.maps.Map(document.getElementById("map"), myOptions);
		
		//Locate on the map where the user is
		var country = document.getElementById("loc_country").value;
	   	var geocoder = new google.maps.Geocoder();
		geocoder.geocode( { 'address': ", , " + country}, adduserlocation_callback);
	}
	
    function load(bShowPetPosition)
	{
		// http://code.google.com/apis/maps/documentation/javascript/controls.html
		var myLatlng = new google.maps.LatLng(30, 4);
		var myOptions = {
  			zoom: 1,
  			center: myLatlng,
			mapTypeId: google.maps.MapTypeId.ROADMAP,
			navigationControl: true,
  			mapTypeControl: true,
  			scaleControl: true,
			scrollwheel: true
		};
		
       map = new google.maps.Map(document.getElementById("map"), myOptions);
		//  WHOLE MAP
        // 30 /* latitude  */, 4 /* longitude */, 1 /* zoom */
		
		// EUROPE ONLY
		// 53 /* latitude  */, 20 /* longitude */, 3 /* zoom */
		
		// london position:  (51.50, -0.12)
	
		if (bShowPetPosition)
			setupPlushMarkers(map);
		else
		{
			initLocationForm();
		}
    }

    function loadMapWithMarkers()
	{
		// http://code.google.com/apis/maps/documentation/javascript/controls.html
		var myLatlng = new google.maps.LatLng(30, 4);
		var myOptions = {
  			zoom: 1,
  			center: myLatlng,
			mapTypeId: google.maps.MapTypeId.ROADMAP,
			navigationControl: true,
  			mapTypeControl: true,
  			scaleControl: true,
			scrollwheel: false
		};
		
       map = new google.maps.Map(document.getElementById("map"), myOptions);
		//  WHOLE MAP
        // 30 /* latitude  */, 4 /* longitude */, 1 /* zoom */
		
		// EUROPE ONLY
		// 53 /* latitude  */, 20 /* longitude */, 3 /* zoom */
		
		// london position:  (51.50, -0.12)
	
		setupPlushPostsMarkers(map);
    }

    //]]>

