//<![CDATA[

//fonction creation onglet

function createMarker(point, icon, infos, eventlistener) {
	var marker = new GMarker(point, icon);
	GEvent.addListener(marker, eventlistener, function() {
		marker.openInfoWindowHtml("<div class='googleinfos'><table><tr><td>"+infos+"</td><tr></table></div>");
	});
	return marker;
}

//fin fonction creation onglet

//fonction bouton zoom perso

// A TextualZoomControl is a GControl that displays textual "Zoom In"
// and "Zoom Out" buttons (as opposed to the iconic buttons used in
// Google Maps).
function TextualZoomControl() {
}
TextualZoomControl.prototype = new GControl();

// Creates a one DIV for each of the buttons and places them in a container
// DIV which is returned as our control element. We add the control to
// to the map container and return the element for the map class to
// position properly.
TextualZoomControl.prototype.initialize = function(map) {
  var container = document.createElement("div");

  var zoomInDiv = document.createElement("div");
  this.setButtonStyle_(zoomInDiv);
  container.appendChild(zoomInDiv);
  zoomInDiv.appendChild(document.createTextNode("+"));
  GEvent.addDomListener(zoomInDiv, "click", function() {
    map.zoomIn();
  });

  var zoomOutDiv = document.createElement("div");
  this.setButtonStyle_(zoomOutDiv);
  container.appendChild(zoomOutDiv);
  zoomOutDiv.appendChild(document.createTextNode("-"));
  GEvent.addDomListener(zoomOutDiv, "click", function() {
    map.zoomOut();
  });

  map.getContainer().appendChild(container);
  return container;
}

// By default, the control will appear in the top left corner of the
// map with 7 pixels of padding.
TextualZoomControl.prototype.getDefaultPosition = function() {
  return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(7, 7));
}

// Sets the proper CSS for the given button element.
TextualZoomControl.prototype.setButtonStyle_ = function(button) {
  button.style.textDecoration = "none";
  button.style.color = "black";
  button.style.background = "#EDEDED";
  button.style.fontSize = "15pt";
  button.style.fontWeight = "bold";
  button.style.border = "1px solid black";
  button.style.padding = "2px";
  button.style.marginBottom = "3px";
  button.style.textAlign = "center";
  button.style.width = "1em";
  button.style.cursor = "pointer";
}

//fin fonction bouton zoom perso

//-------------------
//ouverture de la map
//-------------------

function create_jourjmap(gxmlfile,centerlat,centerlng,zoom,maptype) {

if (GBrowserIsCompatible()) {
// Creates map
var map = new GMap2(document.getElementById("map"));
geocoder = new GClientGeocoder(); //pour le geocoder
map_loaded();
//ajout controles

//map.addControl(new GLargeMapControl());//barre de zoom
map.addControl(new GMapTypeControl());//bouton type de map
map.addControl(new TextualZoomControl());//bouton controle zoom

//fin ajout controles

//placement de la map

map.setCenter(new GLatLng(centerlat, centerlng), zoom);
if(maptype=='map') {map.setMapType(G_NORMAL_MAP);}
else if(maptype=='sat') {map.setMapType(G_SATELLITE_MAP);}
else if (maptype=='hybrid') {map.setMapType(G_HYBRID_MAP);}

//fin placement de la map

//placement des icones

// Create our "tiny" marker icon
var icon = new GIcon();
//icon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
icon.shadow = "jourjmaps/marker-shadow.png";
//icon.iconSize = new GSize(12, 20);
icon.shadowSize = new GSize(22, 20);
//icon.iconAnchor = new GPoint(6, 20);
//icon.infoWindowAnchor = new GPoint(5, 1);

GDownloadUrl(gxmlfile, function(data, responseCode) {
if (data.length==0) {alert("Aucune réponse."); return false; }
var xml = GXml.parse(data);
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
  var latitude = parseFloat(markers[i].getElementsByTagName("point")[0].getAttribute("lat"));
  var longitude =  parseFloat(markers[i].getElementsByTagName("point")[0].getAttribute("lng"));
  var infos = markers[i].getElementsByTagName("infos")[0].firstChild.nodeValue;
  var point = new GLatLng(latitude,longitude);
  var categorie = markers[i].getElementsByTagName("point")[0].getAttribute("categorie");
  if(categorie=="gratuit")
  	{
	icon.image="jourjmaps/marker-gratuit.png";
	icon.iconSize = new GSize(12, 20);
	icon.iconAnchor = new GPoint(6, 20);
	icon.infoWindowAnchor = new GPoint(6,0);
	eventlistener="click";
	}
  else
  	{
	icon.image="jourjmaps/marker-payant.png";
	icon.iconSize = new GSize(15, 26);
	icon.iconAnchor = new GPoint(7, 26);
	icon.infoWindowAnchor = new GPoint(7, 0);
	eventlistener="mouseover";
	}
  //alert("latitude : " + latitude + " longitude : " + longitude);
  //var marker = new GMarker(point);
  //map.addOverlay(marker);
  
  map.addOverlay(createMarker(point,icon,infos,eventlistener));
}
});
}
}
//]]>

