var counter = 0;
var points=Array();
var map;
var types = new Array();
		


   function wheelZoom(e) {
		 var mouseX, mouseY;
		 if(!e) e = window.event;
		 mouseX = (e.layerX) ? e.layerX : e.offsetX;
		 mouseY = (e.layerY) ? e.layerY : e.offsetY;
		 var c = (e.target) ? e.target : e.srcElement;
		 while(c) {
		  mouseX += c.offsetLeft;
		  mouseY += c.offsetTop;
		  c = c.offsetParent;
		  if(c == map.getContainer()) break;
		 }
		 // This is the appropriate point for the cursor at the moment of zooming in or out
		 
		 var point = map.fromContainerPixelToLatLng(new GPoint(mouseX, mouseY));
		 // Prevent from scrolling the page when zooming the map
		 if(window.event) { e.returnValue = false; } // IE
		 if(e.cancelable) { e.preventDefault(); } // DOM-Standard
		 // Scroll to where the pointer is
		 if((e.detail || -e.wheelDelta) < 0) 
		 {
		  	map.zoomIn(point);
		  } 
		  else 
		  {
		 	 map.zoomOut(point);
		  }
	}
   
   function load(latlng) {
      if (GBrowserIsCompatible()) {
		
        map = new GMap2(document.getElementById("googlemap"), { size: new GSize(640,350),draggableCursor: 'auto', draggingCursor: 'move'});
        map.setCenter(latlng, 7);
		map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl(true));	
		map.setMapType(G_HYBRID_MAP);
		
		var Iti = new Circuit('Point', map);
		
	  }
	  
	    types.push( {name:'Classique', image: 'http://maps.google.com/mapfiles/kml/pal5/icon13.png', shadow:'http://maps.google.com/mapfiles/kml/pal5/icon13s.png'} );
		types.push( {name:'Dormir', image: 'http://maps.google.com/mapfiles/kml/pal2/icon28.png', shadow:'http://maps.google.com/mapfiles/kml/pal2/icon28s.png'} );
		types.push( {name:'Manger', image: 'http://maps.google.com/mapfiles/kml/pal2/icon40.png', shadow:'http://maps.google.com/mapfiles/kml/pal2/icon40s.png'} );
		types.push( {name:'Visiter', image: 'http://maps.google.com/mapfiles/kml/pal4/icon46.png', shadow:'http://maps.google.com/mapfiles/kml/pal4/icon46s.png'} );
		types.push( {name:'Point', image: '', shadow:''} );
	  
	  return Iti;
	  
    }
	
	function Circuit(ul, map)
	{
		this.map = map;
		
		
		
		this.draw = function()
		{			
			var polyline = new GPolyline(points, "#8CC229", 8, 0.75, {geodesic: false});
			this.map.addOverlay(polyline);
		}
		
		this.getStopPoint = function(ic, latlng, title, text, type)
		{
			var icon = new GIcon();
			icon.iconSize = new GSize(32, 32);
			icon.shadowSize = new GSize(59, 32);
			icon.iconAnchor = new GPoint(11, 31);
			icon.infoWindowAnchor = new GPoint(9, 2);
			icon.infoShadowAnchor = new GPoint(18, 25);
			
			for ( var i = 0 ; i < types.length ; i++ )
			{
				if (type == types[i].name)
				{
					icon.image = types[i].image;
					icon.shadow = types[i].shadow;
				}
			}
			var marker = new GMarker(latlng, {icon: icon, title: title});

			GEvent.addListener(marker, "click", function() {
           		 marker.openInfoWindowHtml("<div class=\"InfoWindow\" style=\"width:350px;\"><div style='font-weight: bold;'>" + title + "</div>" + text + '</div>');
      		});
			
			return marker;
		}

		this.createPoint = function(latlng,title,text, type)
		{
			points.push(latlng);
			var marker = this.getStopPoint('images/asterisk_orange.png', latlng, title, text, type);
			this.map.addOverlay(marker);
			
		}
	}
