// A function to create the marker and set up the event window
function createMarker(point,name,html,icon) {
  if (icon) {
  var marker = new GMarker(point,icon);
  }
  else {
  var marker = new GMarker(point);
  }
  // === store the name so that the tooltip function can use it ===
  marker.tooltip = '<div class="tooltip">'+name+'</div>';
  GEvent.addListener(marker, "click", function() {
    marker.openInfoWindowHtml(html);
  });
  gmarkers[i] = marker;
  htmls[i] = html;
  i++;
  //map.addOverlay(marker);

  //  ======  The new marker "mouseover" and "mouseout" listeners  ======
/*
  GEvent.addListener(marker,"mouseover", function() {
    showTooltip(marker);
  });        
  GEvent.addListener(marker,"mouseout", function() {
tooltip.style.visibility="hidden"
  });   
*/
  return marker;     
}

// A ControlesZoomPersonalizados is a GControl that displays textual "Zoom In"
// and "Zoom Out" buttons (as opposed to the iconic buttons used in
// Google Maps).
function ControlesZoomPersonalizados() {
}
ControlesZoomPersonalizados.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.
ControlesZoomPersonalizados.prototype.initialize = function(map) {
	var container = document.createElement("div");
	var containerZoom = document.createElement("div");
	this.setContainerZoomStyle_(containerZoom);
	container.appendChild(containerZoom);
	//-----------------------------------------
	//ZOOM MAS 
	var zoomInDiv = document.createElement("div");
	
	this.setButtonStyle_(zoomInDiv);
	containerZoom.appendChild(zoomInDiv);
	
	//zoomInDiv.appendChild(document.createTextNode("+ Cerca"));
	zoomInDiv.innerHTML="<img class='control_com' src='mes_mapa_trans.png'/>";
	
	//Captura el evento click para esta capa
	GEvent.addDomListener(zoomInDiv, "click", function() {
		map.zoomIn();
	});

	//-----------------------------------------
	//ZOOM MENYS 
	var zoomOutDiv = document.createElement("div");
	this.setButtonStyle_(zoomOutDiv);

	containerZoom.appendChild(zoomOutDiv);
	//zoomOutDiv.appendChild(document.createTextNode("+ lejos"));
	zoomOutDiv.innerHTML="<img class='control_com' src='menys_mapa_trans.png'/>";
	//Captura el evento click para esta capa
	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.
ControlesZoomPersonalizados.prototype.getDefaultPosition = function() {
	return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(7, 7));
}


// Sets the proper CSS for the given button element.
ControlesZoomPersonalizados.prototype.setButtonStyle_ = function(button) {
	//button.style.textDecoration = "underline";
	//button.style.color = "#0000cc";
	//button.style.backgroundColor = "white";
	//button.style.font = "small Arial";
	//button.style.border = "1px solid black";
	button.style.padding = "2px";
	button.style.marginBottom = "3px";
	//button.style.textAlign = "center";
	//button.style.width = "6em";
	button.style.cursor = "pointer";

}

// Sets the proper CSS for the container zoom element.
ControlesZoomPersonalizados.prototype.setContainerZoomStyle_ = function(capa) {
	//capa.style.textDecoration = "underline";
	//capa.style.color = "#0000cc";
	//capa.style.backgroundColor = "white";
	//capa.style.font = "small Arial";
	//capa.style.border = "2px solid blue";
	capa.style.padding = "2px";
	capa.style.marginBottom = "3px";
	//capa.style.textAlign = "center";
	//capa.style.width = "6em";
	capa.style.cursor = "pointer";
	
}




/***************************************************************/

// A ControlesZoomPersonalizados is a GControl that displays textual "Zoom In"
// and "Zoom Out" buttons (as opposed to the iconic buttons used in
// Google Maps).
function ControlesMapPersonalizados() {
}
ControlesMapPersonalizados.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.
ControlesMapPersonalizados.prototype.initialize = function(map) {

	
	var container = document.createElement("div");	
	var containerMap = document.createElement("div");
	
	this.setContainerMapStyle_(containerMap);


	container.appendChild(containerMap);



	
	//MAP NORMAL
	var zoomHybridDiv = document.createElement("div");
	this.setButtonStyle_(zoomHybridDiv);
	containerMap.appendChild(zoomHybridDiv);
	//zoomOutDiv.appendChild(document.createTextNode("+ lejos"));
	zoomHybridDiv.innerHTML="<img class='control_com' src='mapa_carreteres.png'/>";
	GEvent.addDomListener(zoomHybridDiv, "click", function() {
	map.setMapType(G_NORMAL_MAP);
	});

	
	//MAP SATELLITE
	var zoomHybridDiv = document.createElement("div");
	this.setButtonStyle_(zoomHybridDiv);
	containerMap.appendChild(zoomHybridDiv);
	//zoomOutDiv.appendChild(document.createTextNode("+ lejos"));
	zoomHybridDiv.innerHTML="<img class='control_com' src='mapa_geo.png'/>";
	GEvent.addDomListener(zoomHybridDiv, "click", function() {
	map.setMapType(G_SATELLITE_MAP);
	});

	//MAP HYBRID 
	var zoomHybridDiv = document.createElement("div");
	this.setButtonStyle_(zoomHybridDiv);
	containerMap.appendChild(zoomHybridDiv);
	//zoomOutDiv.appendChild(document.createTextNode("+ lejos"));
	zoomHybridDiv.innerHTML="<img class='control_com' src='mapa_combined.png'/>";
	GEvent.addDomListener(zoomHybridDiv, "click", function() {
	map.setMapType(G_HYBRID_MAP);
	});
	
	map.getContainer().appendChild(container);


	//MAP malla
	var zoomHybridDiv = document.createElement("div");
	containerMap.appendChild(zoomHybridDiv);
	
	var navegador = navigator.appName;
	
	if (navegador == "Microsoft Internet Explorer")
	{
			
		zoomHybridDiv.innerHTML="<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><a href='http://www.lamalla.net'target='_blank' ><img style ='border:0px;' class='control_com' src='malla_mapa.jpg'/></a><br/><br/><a href='http://www.xtvl.org/' target='_blank'><img style ='border:0px;' class='control_com' src='xtvl_mapa.jpg'/></a>";
		
	}
	else
	{
		zoomHybridDiv.innerHTML="<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><a href='http://www.lamalla.net' onclick='return popitup(\"http://www.lamalla.net\",\"www.lamalla.net\")' ><img style ='border:0px;' class='control_com' src='malla_mapa.jpg'/></a><br/><br/><a href='http://www.xtvl.org/' onclick='return popitup(\"http://www.xtvl.org\",\"www.xtvl.org\")'><img style ='border:0px;' class='control_com' src='xtvl_mapa.jpg'/></a>";
	}
	
	
//	onclick=\"return popitup(\'<%=rs("emi_url_directe")%>\',\'<%=clean(rs("emi_nom"))%>_directe\')\"
	
	
	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.
ControlesMapPersonalizados.prototype.getDefaultPosition = function() {
	return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(0, 7));
}


// Sets the proper CSS for the given button element.
ControlesMapPersonalizados.prototype.setButtonStyle_ = function(button) {
	//button.style.textDecoration = "underline";
	//button.style.color = "#0000cc";
	//button.style.backgroundColor = "white";
	//button.style.font = "small Arial";
	//button.style.border = "1px solid black";
	button.style.padding = "2px";
	button.style.marginBottom = "3px";
	//button.style.textAlign = "center";
	//button.style.width = "6em";
	button.style.cursor = "pointer";

}



// Sets the proper CSS for the container map element.
ControlesMapPersonalizados.prototype.setContainerMapStyle_ = function(capa) {
	//capa.style.textDecoration = "underline";
	//capa.style.color = "#0000cc";
	//capa.style.backgroundColor = "white";
	//capa.style.font = "small Arial";
	//capa.style.border = "2px solid red";
	capa.style.padding = "2px";
	capa.style.marginBottom = "3px";
	//capa.style.textAlign = "center";
	//capa.style.width = "6em";
	capa.style.cursor = "pointer";
	capa.style.float = "right";
}


function correctPNG()  
{  
     var arVersion = navigator.appVersion.split("MSIE")  
     var version = parseFloat(arVersion[1])  
     if ((version >= 5.5) && (document.body.filters))  
     {  
        for(var i=0; i<document.images.length; i++)  
        {  
           var img = document.images[i]  
           var imgName = img.src.toUpperCase()  
				 	 if (img.className == 'control_com') {
	           if ( imgName.substring(imgName.length-3, imgName.length) == "PNG")  
	           {  
	              var imgID = (img.id) ? "id='" + img.id + "' " : ""  
	              var imgClass = (img.className) ? "class='" + img.className + "' " : ""  
	              var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "  
	              var imgStyle = "display:inline-block;" + img.style.cssText  
	              if (img.align == "left") imgStyle = "float:left;" + imgStyle  
	              if (img.align == "right") imgStyle = "float:right;" + imgStyle  
	              if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle  
	              var strNewHTML = "<span " + imgID + imgClass + imgTitle  
	              + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"  
	              + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"  
	              + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"  
	              img.outerHTML = strNewHTML  
	              i = i-1  
	           }  
					}
        }  
     }      
}
