 
var MapIconMaker = {};

MapIconMaker.createMarkerIcon = function(opts) {
  var width = opts.width || 32;
  var height = opts.height || 32;
  var primaryColor = opts.primaryColor || "#ff0000";
  var strokeColor = opts.strokeColor || "#000000";
  var cornerColor = opts.cornerColor || "#ffffff";
   
  var baseUrl = "http://chart.apis.google.com/chart?cht=mm";
  var iconUrl = baseUrl + "&chs=" + width + "x" + height + 
      "&chco=" + cornerColor.replace("#", "") + "," + primaryColor.replace("#", "") + "," + strokeColor.replace("#", "") + "&ext=.png";
  var icon = new GIcon(G_DEFAULT_ICON);
  icon.image = iconUrl;
  icon.iconSize = new GSize(width, height);
  icon.shadowSize = new GSize(Math.floor(width*1.6), height);
  icon.iconAnchor = new GPoint(width/2, height);
  icon.infoWindowAnchor = new GPoint(width/2, Math.floor(height/12));
  icon.printImage = iconUrl + "&chof=gif";
  icon.mozPrintImage = iconUrl + "&chf=bg,s,ECECD8" + "&chof=gif";
  var iconUrl = baseUrl + "&chs=" + width + "x" + height + 
      "&chco=" + cornerColor.replace("#", "") + "," + primaryColor.replace("#", "") + "," + strokeColor.replace("#", "");
  icon.transparent = iconUrl + "&chf=a,s,ffffff11&ext=.png";

  icon.imageMap = [
      width/2, height,
      (7/16)*width, (5/8)*height,
      (5/16)*width, (7/16)*height,
      (7/32)*width, (5/16)*height,
      (5/16)*width, (1/8)*height,
      (1/2)*width, 0,
      (11/16)*width, (1/8)*height,
      (25/32)*width, (5/16)*height,
      (11/16)*width, (7/16)*height,
      (9/16)*width, (5/8)*height
  ];
  for (var i = 0; i < icon.imageMap.length; i++) {
    icon.imageMap[i] = parseInt(icon.imageMap[i]);
  }

  return icon;
}
 
 var iconOptions = {};
  iconOptions.width = 20;
  iconOptions.height = 20;
 iconOptions.primaryColor = "#BA5124FF";
  iconOptions.cornerColor = "#CC7C1EFF";
  iconOptions.strokeColor = "#000000FF";

var iconBlue = MapIconMaker.createMarkerIcon(iconOptions);

/*---------------------------------------- creation de markers v2 ---------------------------------------------------------*/
/*function marker_content(marker,content) {
       var maxContentDiv = document.createElement('div');
        maxContentDiv.innerHTML = 'Chargement...'
        marker.openInfoWindowHtml("<table width=350px height=300px><tr height=300px><td height=300px><div align=left>Cliquer sur \"+\" pour agrandir la bulle, ou \"X\" pour la fermer</div><br />" + content + "</td></tr></table>",
            {maxContent: maxContentDiv, 
             maxTitle: ""});
        var iw = map.getInfoWindow();
        GEvent.addListener(iw, "maximizeclick", function() {
           maxContentDiv.innerHTML = content;
          });
            GEvent.addListener(iw, "restoreend", function() {
           });
           GEvent.addListener(iw, "closeclick", function() {
           });
      })

function createMarker2(point, name, address, type) {
      var marker = new GMarker(point, type);
      var html = address;
       GEvent.addListener(marker, 'click', marker_content(marker,html) );
      
       //--- infoalt
            var infoalt = new InfoAlt(marker,name,4);
            marker.infoalt = infoalt;
            map.addOverlay(infoalt);
            GEvent.addListener(marker,'mouseover',function(){
	        this.infoalt.show();
            //alert('survol');
            });
            GEvent.addListener(marker,'mouseout',function(){
	        this.infoalt.hide();
            });
        //FIN --- infoalt
      return marker;
    }
    */
/*--------------------------------------------------------------------------------------------*/

function createMarker(point, name, address, type) {
      var marker = new GMarker(point, type);
      /*var html = "<b>" + name + "</b> <br/>" + address;*/
      var html = address;
      var html1 = html + "<br /><a href=\"http://www.cotedor-tourisme.com/index.php?" + html.substring(63,(html.length-71)) + "\" target=_blank>Voir la fiche complète</a>";
      var html2 = "<iframe src=\"http://www.cotedor-tourisme.com/adt/minifiche.php?" + html.substring(63,(html.length-71)) + "\" width='98%' height='475px' scrolling='auto'  frameborder='0'></iframe><br /><a href=\"http://www.cotedor-tourisme.com/index.php?" + html.substring(63,(html.length-71)) + "\" target=_blank>Voir la fiche complète</a>";
    
      GEvent.addListener(marker, 'click', function() {
       var maxContentDiv = document.createElement('div');
        maxContentDiv.innerHTML = 'Chargement...'
        marker.openInfoWindowHtml("<table width=350px height=300px><tr height=300px><td height=300px><div align=left>Cliquer sur \"+\" pour agrandir la bulle, ou \"X\" pour la fermer</div><br />" + html1 + "</td></tr></table>",
            {maxContent: maxContentDiv, 
             maxTitle: ""});
        var iw = map.getInfoWindow();
        GEvent.addListener(iw, "maximizeclick", function() {
        //GDownloadUrl("http://www.cotedor-tourisme.com", function(data) {
        //maxContentDiv.innerHTML ="<table width=100% height=100%><tr height=100%><td height=100%>" + html + "</td></tr></table>";
        maxContentDiv.innerHTML = html2;
           //document.getElementById('navmap').style.display='none';
            //});
          });
            GEvent.addListener(iw, "restoreend", function() {
        //GDownloadUrl("http://www.cotedor-tourisme.com", function(data) {
        //alert('petit');
        //document.getElementById('navmap').style.display='';
            //});
          });
           GEvent.addListener(iw, "closeclick", function() {
        //GDownloadUrl("http://www.cotedor-tourisme.com", function(data) {
           //document.getElementById('navmap').style.display='';
            //});
          });
      });
      
       //--- infoalt
            var infoalt = new InfoAlt(marker,name,4);
            marker.infoalt = infoalt;
            map.addOverlay(infoalt);
            GEvent.addListener(marker,'mouseover',function(){
	        this.infoalt.show();
            //alert('survol');
            });
            GEvent.addListener(marker,'mouseout',function(){
	        this.infoalt.hide();
            });
        //FIN --- infoalt
      return marker;
    }
    
//--------------info Alt ----------------------------------


function InfoAlt(marker, text, padding){
	this.marker_ = marker;
	this.text_ =  text;
	this.padding_ = padding;
}

InfoAlt.prototype = new GOverlay();

InfoAlt.prototype.initialize = function(map){
	var div = document.createElement("div");
	div.appendChild(document.createTextNode(this.text_));
	div.className = 'InfoAlt';
	div.style.position = 'absolute';
	div.style.visibility = 'hidden';
	map.getPane(G_MAP_FLOAT_PANE).appendChild(div);
	this.map_ = map;
	this.div_ = div;
}

InfoAlt.prototype.remove = function(){
	this.div_.parentNode.removeChild(this.div_);
}

InfoAlt.prototype.copy = function(){
	return new InfoAlt(this.marker_,this.text_,this.padding_);
}

InfoAlt.prototype.redraw = function(force){
	if (!force) return;
	var markerPos = this.map_.fromLatLngToDivPixel(this.marker_.getPoint());
	var iconAnchor = this.marker_.getIcon().iconAnchor;
	var xPos = Math.round(markerPos.x - this.div_.clientWidth / 2);
    //var xPos = Math.round(markerPos.x - this.div_.clientWidth -100);
	var yPos = markerPos.y - iconAnchor.y - this.div_.clientHeight - this.padding_;
    //var yPos = markerPos.y - iconAnchor.y - this.div_.clientHeight - this.padding_ - 20;
	this.div_.style.top = yPos + 'px';
	this.div_.style.left = xPos + 'px';
}

InfoAlt.prototype.show = function(){
	document.getElementById('ggmap').style.display='';
	this.div_.style.visibility = 'visible';
    map.checkResize();
}

InfoAlt.prototype.hide = function(){
	document.getElementById('ggmap').style.display='none';
	this.div_.style.visibility = 'hidden';
    map.checkResize();
}


//--------------FIN info Alt ----------------------------------

 