$(document).ready(function () {
	
	
	// Creamos el Icono de sportinca.
		$.gm.newIcon("sportinca", {
	 			image : "http://ikhuerta.dreamhosters.com/sportinca/images/logop.gif",
	 			iconSize : "30,27",
	 			iconAnchor : "5,10"
	 	});
	 
	 	
		// Variable que contiene el punto
	 	var P = new GLatLng(39.70843298477434,2.925313711166382) 
		
	 	// Creamos el mapa.
		$("#map").createMap({
			center : new GLatLng(39.71103382658153,2.9235434532165527) ,
			zoom : 15,
			dobleClickZoom : true,
			continuosZoom: true, 
			viewControls:true,
			viewType : true,
			dragMap : true
		});
		
		$("#map").append("<div id='leyenda'><p><span class='rojo'></span> Camino de Ida</p><p><span class='azul'></span>Camino de vuelta</p></div>")
		
		$.gm.maps[0].enableDoubleClickZoom();
		$.gm.maps[0].setMapType(G_HYBRID_MAP);
		// Cuando el mapa esté listo...
		$("#map").map().ready( function () { 
			// creamos la marca.
			var greenIcon = new GIcon(G_DEFAULT_ICON);
        	greenIcon.image = "http://gmaps-samples.googlecode.com/svn/trunk/markers/green/blank.png";
			markerOptions = { icon:greenIcon };
		    var marca = new GMarker(P,markerOptions);
		    $("#map").map().addOverlay(marca);
			
			GEvent.addListener(marca, "click", function() {
            	marca.openInfoWindowHtml("<strong>Club Sport Inca</strong><br/><br/>Carretera de Sineu, Km: 1,200.");
          	});

			
			$("#map").map().addOverlay(new GPolyline([
  		  			 new GLatLng(39.71343457773332,2.921783924102783),
  		  			 new GLatLng(39.713360299302536,2.9219448566436768),
  		  			 new GLatLng(39.71337680562739,2.9222774505615234),
  		  			 new GLatLng(39.71339331194832,2.9223525524139404),
  		  			 new GLatLng(39.71336855246546,2.9224705696105957),
  		  			 new GLatLng(39.713360299302536,2.92261004447937),
  		  			 new GLatLng(39.71327776761896,2.922835350036621),
  		  			 new GLatLng(39.71290637382091,2.9231679439544678),
  		  			// Giro - 
					 new GLatLng(39.71228737971396,2.9233932495117188),
  		 			 new GLatLng(39.710677969041505,2.9221808910369873),
  		 			 new GLatLng(39.71013323692449,2.922835350036621),
  		 			 new GLatLng(39.70825965574532,2.924755811691284),
  		 			 new GLatLng(39.70828441706184,2.9251420497894287)

			], "#ff0000", 3 ,0.8));
			
			$("#map").map().addOverlay(new GPolyline([
  		  			new GLatLng(39.70823341704184,2.9251420497894287),
  		 			new GLatLng(39.70820865572532,2.924755811691284),
					new GLatLng(39.71008223690449,2.922835350036621),
					new GLatLng(39.710577969041505,2.9221808910369873),
					new GLatLng(39.71126396394074,2.9216015338897705),
					new GLatLng(39.712295633005255,2.92111873626709),
					new GLatLng(39.71286510771989,2.9204535484313965),
					new GLatLng(39.713352046138624,2.921215295791626),
					new GLatLng(39.71346759034356,2.9215264320373535),
					new GLatLng(39.71343457773332,2.921783924102783)
			], "#0000FF", 3, 0.8));
		
			
		});
});