var cm_baseIcon = new GIcon();
//cm_baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
cm_baseIcon.iconSize = new GSize(20, 34);
cm_baseIcon.shadowSize = new GSize(37, 34);
cm_baseIcon.iconAnchor = new GPoint(9, 34);
cm_baseIcon.infoWindowAnchor = new GPoint(9, 2);
cm_baseIcon.infoShadowAnchor = new GPoint(18, 25);

var bounds = new GLatLngBounds();
var map;
//var tabmarkers[]=new array;

createMap=function()
{
   if (GBrowserIsCompatible())
   {
        map = new GMap2(document.getElementById("carte"));
        map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());
        map.setCenter(new GLatLng( 43.907787,-79.359741), 2);
        createMarkers();
   }
}

reloadMap=function()
{
      map.clearOverlays();
      createMarkers();
}

createMarkers=function()
{

   var champgs=$("#crit_gs").val();
   var champse=$("#crit_se").val();
   var champch=$("#crit_ch").val();
   var carte  =$("#crit_carte").val();


   $.ajax({type: "GET",url: "modules/eAIVFC/carte.php?carte="+carte+"&champgs="+champgs+"&champse="+champse+"&champch="+champch,success: function(xml)
   {

      var points=$("villes",xml);
      var param=$("param",xml);
      $("centre",points).each(function(i)
      {
               var lat=$(this).attr('geolat');
               var lon=$(this).attr('geolon');

               if(lat != 0 && lon!=0)
               {
                  var point = new GLatLng(lat,lon);
                  var markerOpts = {};

                  var nIcon = new GIcon(cm_baseIcon);
                  nIcon.image = "http://aivfc.ktp-concept.fr/design/element/marker.png";
              nIcon.iconSize = new GSize (25, 30);
			  nIcon.iconAnchor = new GPoint(11,28);
			  nIcon.infoWindowAnchor = new GPoint(8,16);

                  markerOpts.icon = nIcon;
                  markerOpts.title   =  $(this).attr('nom');

                  var marker     =  new GMarker(point,markerOpts);
                  //tabmarkers[i]  =  marker;

                  var html="<h1 class='titrefichette'>"+$(this).attr('nom')+"</h1>"+$(this).attr('adresse')+"<br/>"+$(this).attr('cp')+" "+$(this).attr('ville')+"<br/><br/><strong>Tél :</strong> "+$(this).attr('tel')+"<br/><strong>Fax :</strong> "+$(this).attr('fax')+"<br/><strong>Email :</strong> "+$(this).attr('email')+"<br/><strong>Site :</strong> "+$(this).attr('siteweb')+"<br/><strong>Nom responsable :</strong> "+$(this).attr('nomresponsable')+"<br/><br/><strong>Capacité plus grande salle :</strong> "+$(this).attr('grandsalle')+" places<br/><strong>Surface exposition :</strong> "+$(this).attr('surfaceexpo')+" m2<br/><strong>Nbr total de chambres :</strong> "+$(this).attr('capacitehot')+"<br/><br/><a class='accesfiche' href='rubrique.php?page=fiche&ville="+$(this).attr('id')+"'>Accéder à la fiche</a>";
                  GEvent.addListener(marker, "click", function()
                  {
                     //alert(html);
                     this.openInfoWindowHtml(html)
                     /*var mlink=$("#lienfiche"+this.getTitle()).attr('href');
                     self.location.href=mlink;*/
                  }
                  );
                  /*
                  GEvent.addListener(marker, "mouseover", function()
                  {
                     //$("#ligne*").removeClass();
                     var ligne=$("#ligne"+this.getTitle());
                     ligne.toggleClass('red');
                  });
                  GEvent.addListener(marker, "mouseout", function()
                  {
                     //$("#ligne*").removeClass();
                     var ligne=$("#ligne"+this.getTitle());
                     ligne.removeClass();
                  });*/
                  map.addOverlay(marker);
                  bounds.extend(point);
               }
      });
      if(param.attr('zoom') != "")map.setZoom(parseInt(param.attr('zoom')));
      else map.setZoom(map.getBoundsZoomLevel(bounds));
      map.setCenter(bounds.getCenter());

   }})
}
