_mSvgEnabled = true; _mSvgForced = true;
var iconCA = new GIcon(); 
iconCA.image = '/images/map/ca.png';
//iconRed.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';
iconCA.iconSize = new GSize(36, 50);
//iconRed.shadowSize = new GSize(22, 20);
iconCA.iconAnchor = new GPoint(18,50);
iconCA.infoWindowAnchor = new GPoint(29,5);

var iconOpti = new GIcon(); 
iconOpti.image = '/images/map/opti.png';
//iconOpti.shadow = '/images/map/ombre.png';
//iconOpti.shadowSize = new GSize(100,50);
iconOpti.iconSize = new GSize(36, 50);
iconOpti.iconAnchor = new GPoint(18, 50);
iconOpti.infoWindowAnchor = new GPoint(29,5);

var iconLaser = new GIcon(); 
iconLaser.image = '/images/map/laser.png';
iconLaser.iconSize = new GSize(36, 50);
iconLaser.iconAnchor = new GPoint(18,50);
iconLaser.infoWindowAnchor = new GPoint(29,5);

var icon470 = new GIcon(); 
icon470.image = '/images/map/470.png';
icon470.iconSize = new GSize(36, 50);
icon470.iconAnchor = new GPoint(18,50);
icon470.infoWindowAnchor = new GPoint(29,5);

var iconPlanche = new GIcon(); 
iconPlanche.image = '/images/map/planche.png';
iconPlanche.iconSize = new GSize(36, 50);
iconPlanche.iconAnchor = new GPoint(18,50);
iconPlanche.infoWindowAnchor = new GPoint(29,5);

var iconBr = new GIcon(); 
iconBr.image = '/images/br.png';
iconBr.iconSize = new GSize(50, 40);
iconBr.iconAnchor = new GPoint(40, 30);
iconBr.infoWindowAnchor = new GPoint(20, 1);

var customIcons = [];
customIcons[100] = iconBr;		//Base
customIcons[1] = iconOpti;		//competition
customIcons[2] = iconOpti;
customIcons[3] = iconLaser;	//groupe
customIcons[4] = icon470;
customIcons[5] = iconPlanche;

function load() {
  if (GBrowserIsCompatible()) {
		placeMarker(type,markers);
  }
}

function placeMarker(type,m,cat){
	var map = new GMap2(document.getElementById("map"));
	if(type == 1){
		var dist = document.getElementById("distance");
		var titre = document.getElementsByTagName("h1");
		dist.innerHTML = "Distance parcourue par chaque comp&eacute;titeur : "+Math.round(m[0]['dist'])+" km";

		if(cat == '1') titre[0].innerHTML = ":: Comp&eacute;titions : Opti D&eacute;partemental ::";
		if(cat == '2') titre[0].innerHTML = ":: Comp&eacute;titions : Opti Ligue ::";
		if(cat == '3') titre[0].innerHTML = ":: Comp&eacute;titions : Laser ::";
		if(cat == '4') titre[0].innerHTML = ":: Comp&eacute;titions : 470 ::";
		if(cat == '5') titre[0].innerHTML = ":: Comp&eacute;titions : Planche &agrave; voile ::";
		
	}
	map.addControl(new GSmallMapControl());
	map.setCenter(new GLatLng(m[0]['center_lat'], m[0]['center_lon']), 5, G_NORMAL_MAP);
	
	var bds = new GLatLngBounds(new GLatLng(m[0]['min_lat'], m[0]['min_lon']), new GLatLng(m[0]['max_lat'], m[0]['max_lon']));
	map.setZoom(map.getBoundsZoomLevel(bds));
	for(var i in m)
	{
		if(IsNumeric(i) && (i!=0)){
			if(m[i].palette == undefined){
				var adresse = m[i].address;
				var commentaire = m[i].commentaire;
				//var type = m[i].type;
				var remarque = m[i].remarque;
				var point = new GLatLng(parseFloat(m[i].lat),
											  parseFloat(m[i].lng));
				var marker = createMarker(point, adresse, commentaire, type, remarque);
				map.addOverlay(marker);
			}else{
				if(type == 1) map.addControl(new Palette(m[i].palette));
			}
		}
	}	
	//visibilite('navmap');
}

function switchCat(type,cat){
	//alert(cat);
	//GDownloadUrl("http://192.168.0.2/map/tabJS/"+type+"/"+cat, function(data) {
	//GDownloadUrl("http://localhost/map/tabJS/"+type+"/"+cat, function(data) {
	GDownloadUrl("http://www.bassin-rond.net/map/tabJS/"+type+"/"+cat, function(data) {
		placeMarker(type,eval(data),cat);
	});
}

function createMarker(point, adresse, commentaire, type, remarque) {
	var infoTabs = [];
	
	if(remarque.length > 2){
		remarque[0].commentaire = '<div style="width:'+remarque.length*88+'px">' + remarque[0].commentaire + '</div>';
	}

	for(var j in remarque){
		var t = new GInfoWindowTab(remarque[j].date, "<h1 style=\"width:250px\", >"+unescape(remarque[j].titre)+"</h1>"+remarque[j].commentaire);
		infoTabs[infoTabs.length] = t;
	}
	if(type == 1){
  		var marker = new GMarker(point,{icon:customIcons[remarque[0].categorie],title:adresse});
	}else{
		if(remarque[0].categorie == 100){
		//if(type == 0){
			var marker = new GMarker(point,{icon:iconBr,title:adresse});
		}else{
			var marker = new GMarker(point,{icon:iconCA,title:adresse});
		}
	}
  GEvent.addListener(marker, 'click', function() {
	marker.openInfoWindowTabsHtml(infoTabs);
  });
  return marker;
}

function Palette(html) {
  	this.html_ = html;
}
Palette.prototype = new GControl();

// Creates the DIV representing this rectangle.
Palette.prototype.initialize = function(map) {
  	var div = document.createElement("div");
  	div.innerHTML = this.html_;
	map.getContainer().appendChild(div);
	
  	this.map_ = map;
  	this.div_ = div;

	return div;
}

Palette.prototype.getDefaultPosition = function() {
  return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(0, 0));
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;   
   }
