
    //<![CDATA[

    var map;
    var gdir;
    var geocoder = null;
    var addressMarker;
    var my_route ;
var marker_tab = [] ;
    function load() {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map_canvas"));
        map.disableDoubleClickZoom() ;
        var point_club =new GLatLng( 43.830665, 5.836937 ) ;       
        var marker_club = new GMarker( point_club , { title: "aviron manosque cliquer pour plus d infos" } ) ;
        map.setCenter( point_club , 13);
        map.addOverlay( marker_club ) ;

        GEvent.addListener(marker_club, "click", function() {
        marker_club.openInfoWindowHtml( 'Local aviron <br/>Lac des Vannades<br/> tel Pr&eacute;sident 04 92 72 00 11 <br/> tel entraineur 06 03 44 46 22  <br/> <a href=\"mailto:avironmanosque@gmail.com\"  >avironmanosque@gmail.com<\/a><br/><a href=\"www.aviron-club-manosque.org\"  >www.aviron-club-manosque.org<\/a><br/>'  );
  });

  //    gdir = new GDirections(map, document.getElementById("directions") );
 //         gdir = new GDirections(map);
   gdir = new GDirections();


        var point_pv = new GLatLng( 43.8342, 5.7898163 ) ;
        var marker_pv = new GMarker( point_pv ) ; 
       map.addOverlay( marker_pv ) ;
        GEvent.addListener(marker_pv, "click", function() {
        marker_pv.openInfoWindowHtml( 'Pr&eacute;sident Valancony Pierre  <br/>236 mont&eacute;e des vraies richesses <br/> tel  04 92 72 00 11 <br/>  <a href=\"mailto:pierre.valancony@aliceadsl.fr\"  >pierre.valancony@aliceadsl.fr<\/a><br/>'  );
  });

        var point_gr = new GLatLng( 43.829662, 5.787412 ) ;
        var marker_gr = new GMarker( point_gr , { title: "Gare routiere" } ) ;
       map.addOverlay( marker_gr ) ;

        var point_gs = new GLatLng( 43.823520, 5.793152 ) ;
        var marker_gs = new GMarker( point_gs , { title: "Gare SNCF" } ) ;
       map.addOverlay( marker_gs ) ;

        var point_mm = new GLatLng( 43.833490, 5.78234 ) ;
        var marker_mm = new GMarker( point_mm , { title: "Mairie Manosque" } ) ;
       map.addOverlay( marker_mm ) ;

        var point_pa = new GLatLng( 43.806628, 5.814301 ) ;
        var marker_pa = new GMarker( point_pa , { title: "Peage autoroute Manosque" } ) ;
       map.addOverlay( marker_pa ) ;

        var mapControl = new GMapTypeControl();
        map.addControl(mapControl);
       map.addControl(new GLargeMapControl());
        map.addControl(new GOverviewMapControl(  ));


      }

    function setDirections(fromAddress, toAddress, locale) {
      gdir.load("from: " + fromAddress + " to: " + toAddress,
                { "locale": locale });
    }


    function handleErrors(){
	   if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	     alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
	   else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
	     alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
	   else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
	     alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);	     
	   else if (gdir.getStatus().code == G_GEO_BAD_KEY)
	     alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);
	   else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
	     alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
	   else alert("An unknown error occurred."); 	   
     } 

      function onGDirectionsLoad(){ 
                   my_route = " my route  : "+gdir.getNumRoutes() ;
      }

       var marker_clic ;
       var marker_first ;
       var marker_last ;
       GEvent.addListener(map,"dblclick", function(overlay,  latlng) {   
           if( marker_clic != null ) map.removeOverlay(  marker_clic ) ;
          var point_clic = new GLatLng( latlng ) ;
          marker_clic = new GMarker( latlng, { draggable: true } ) ; 
          var latlng_clic = marker_clic.getLatLng() ;
          var latlng_clic_coord = latlng_clic.lat()+","+latlng_clic.lng() ;

         GEvent.addListener(gdir, "error", handleErrors);
         gdir.load( "from: " + latlng_clic_coord+ " to: " + "parking aviron club@43.833202, 5.84126",{getSteps:true,getPolyline:true,"locale": "fr_FR"} ) ;  
       var poly = gdir.getPolyline() ;
       GEvent.addListener(gdir,"load", function() {
       if(  marker_first != null ) map.removeOverlay(  marker_first ) ;
       if(  marker_last != null ) map.removeOverlay(  marker_last ) ;
       if( poly != null ) map.removeOverlay(  poly ) ;
          my_route = " titi  route  : "+gdir.getNumRoutes() ;
         var my_html = " Pour voir laroute  "+" pouf "+" route  : "+gdir.getNumRoutes()+" route "+gdir.getNumGeocodes()+" Geocodes  : "+gdir.getRoute(0).getNumSteps()+" steps " ; 
          var route = gdir.getRoute(0);
          marker_first = new GMarker(route.getStep(0).getLatLng() , { draggable: true } ) ;
        var point_last = route.getEndLatLng() ;
         marker_last =  new GMarker( point_last, { draggable: true } ) ; 

          map.addOverlay(  marker_first ) ;
          map.addOverlay(  marker_last ) ;
         map.addOverlay( gdir.getPolyline() ) ;
         gdir.getPolyline().setStrokeStyle({color:"black"}) ;
         customPanel(map,"map",gdir,document.getElementById("directions")) ;


        var poly2 = gdir.getPolyline() ;
        GEvent.addListener(marker_first,"dragend", function() {
        if( poly2 != null ) map.removeOverlay(  poly2 ) ;
        var dragend_coord = this.getLatLng().lat()+","+this.getLatLng().lng() ;
         gdir.load( "from: " + dragend_coord+ " to: " + "parking@43.833202, 5.84126",{getSteps:true,getPolyline:true,"locale": "fr_FR"} ) ;  
        customPanel(map,"map_canvas",gdir,document.getElementById("directions"))  ; 

//        this.showMapBlowup() ;
        });
       }) ;



// debut customPanel
      function customPanel(map,mapname,dirn,div) {
        var html = "";
      
        // ===== local functions =====

        // === waypoint banner ===
        function waypoint(point, type, address) {
          var target = '"' + mapname+".showMapBlowup(new GLatLng("+point.toUrlValue(6)+"))"  +'"';
          html += '<table style="border: 1px solid silver; margin: 10px 0px; background-color: rgb(238, 238, 238); border-collapse: collapse; color: rgb(0, 0, 0);">';
          html += '  <tr style="cursor: pointer;" onclick='+target+'>';
          html += '    <td style="padding: 4px 15px 0px 5px; vertical-align: middle; width: 20px;">';
          html += '      <img src="http://www.google.com/intl/en_ALL/mapfiles/icon-dd-' +type+ '-trans.png">'
          html += '    </td>';
          html += '    <td style="vertical-align: middle; width: 100%;">';
          html +=        address;
          html += '    </td>';
          html += '  </tr>';
          html += '</table>';
        }

        // === route distance ===
        function routeDistance(dist) {
          html += '<div style="text-align: right; padding-bottom: 0.3em;">' + dist + '</div>';
        }      

        // === step detail ===
        function detail(point, num, description, dist) {
          var target = '"' + mapname+".showMapBlowup(new GLatLng("+point.toUrlValue(6)+"))"  +'"';
          html += '<table style="margin: 0px; padding: 0px; border-collapse: collapse;">';
          html += '  <tr style="cursor: pointer;" onclick='+target+'>';
          html += '    <td style="border-top: 1px solid rgb(205, 205, 205); margin: 0px; padding: 0.3em 3px; vertical-align: top; text-align: right;">';
          html += '      <a href="javascript:void(0)"> '+num+'. </a>';
          html += '    </td>';
          html += '    <td style="border-top: 1px solid rgb(205, 205, 205); margin: 0px; padding: 0.3em 3px; vertical-align: top; width: 100%;">';
          html +=        description;
          html += '    </td>';
          html += '    <td style="border-top: 1px solid rgb(205, 205, 205); margin: 0px; padding: 0.3em 3px 0.3em 0.5em; vertical-align: top; text-align: right;">';
          html +=        dist;
          html += '    </td>';
          html += '  </tr>';
          html += '</table>';
        }

        // === Copyright tag ===
        function copyright(text) {
          html += '<div style="font-size: 0.86em;">' + text + "</div>";
        }
        

        // === read through the GRoutes and GSteps ===

        for (var i=0; i<dirn.getNumRoutes(); i++) {
          if (i==0) {
            var type="play";
          } else {
            var type="pause";
          }
          var route = dirn.getRoute(i);
          var geocode = route.getStartGeocode();
          var point = route.getStep(0).getLatLng();
          // === Waypoint at the start of each GRoute
          waypoint(point, type, geocode.address);
          routeDistance(route.getDistance().html+" (environ "+route.getDuration().html+")");

          for (var j=0; j<route.getNumSteps(); j++) {
            var step = route.getStep(j);
            // === detail lines for each step ===
            detail(step.getLatLng(), j+1, step.getDescriptionHtml(), step.getDistance().html);
          }
        }
        
        // === the final destination waypoint ===   
        var geocode = route.getEndGeocode();
        var point = route.getEndLatLng();
        waypoint(point, "stop", geocode.address);
                 
        // === the copyright text ===
        copyright(dirn.getCopyrightsHtml());

        // === drop the whole thing into the target div
        div.innerHTML = html;

      } 
//fin custom
        });





}




    //]]>
