// JavaScript Document
//<![CDATA[


var Ico_hotel = new GIcon();
Ico_hotel.image = "i/ico1.png";
Ico_hotel.iconSize = new GSize(29, 26);
Ico_hotel.iconAnchor = new GPoint(6, 12);
Ico_hotel.infoWindowAnchor = new GPoint(12, 17);    

var Ico_well = new GIcon();
Ico_well.image = "i/ico2.png";
Ico_well.iconSize = new GSize(29, 26);
Ico_well.iconAnchor = new GPoint(6, 12);
Ico_well.infoWindowAnchor = new GPoint(12, 17);    

var Ico_med = new GIcon();
Ico_med.image = "i/ico3.png";
Ico_med.iconSize = new GSize(29, 26);
Ico_med.iconAnchor = new GPoint(6, 12);
Ico_med.infoWindowAnchor = new GPoint(12, 17);    

var Ico_con = new GIcon();
Ico_con.image = "i/ico_contact.png";
Ico_con.iconSize = new GSize(64, 57);
Ico_con.iconAnchor = new GPoint(6, 12);
Ico_con.infoWindowAnchor = new GPoint(12, 17);    

//var map_lat = -15.600929;
//var map_lng = 27.9547;
//var map_zoom = 10;


var map;
var clusterer;
var codHTML;





function cargaXml(id_poblacion,id_zona,pagi_query_string,inicial, cantidad,tipo,id) {

if (id_poblacion==1){
	var searchUrl = 'inc/contacto.xml';	
}else{
	var searchUrl = 'inc/maps.php?lng=es&hotel=' + id + ' ';
}

	GDownloadUrl(searchUrl, function(data) {
								  
    var xml = GXml.parse(data);
	var markers = xml.getElementsByTagName("marker");


    var markers = xml.documentElement.getElementsByTagName('marker');
    map.clearOverlays();

     var bounds = new GLatLngBounds();
    for (var i = 0; i < markers.length; i++) { 
	
      var nombre = markers[i].getAttribute('nombre');
      var zona = markers[i].getAttribute('zona');
      var id = parseFloat(markers[i].getAttribute('id'));
	  var tipo = parseFloat(markers[i].getAttribute('tipo'));
	  var imagen = markers[i].getAttribute('imagen');
	   var poblacion = markers[i].getAttribute('poblacion');
	  
      var point = new GLatLng(parseFloat(markers[i].getAttribute('lng')), parseFloat(markers[i].getAttribute('lat')));
	  
	 
	var codHTML = "";
	codHTML += "<table cellspacing=3 cellpadding=2><tr><td>&nbsp;";
	if (imagen != '')
	{
	codHTML += "<!--img class='borde' src='" + imagen + "' style='margin-right:5px' width=50-->";
	}
	codHTML +="</td><td valign=top>";
	codHTML += '<b>' + nombre + '</b>';
	codHTML +=zona +"<br>" + poblacion + " ";
	codHTML +="<br>";
	codHTML +="<br>";
	if (id_poblacion!=1){
	codHTML +="<a href=\"pg6.php?hotel=" + id +"\">+ info</a>";
	}
//	codHTML +="<a href=\"p" + (tipo + 1) +"_1.php?id=" + id + "&" + pagi_query_string + ">ver inmueble</a>";
	codHTML +="</td></tr></table>";
	
	if (tipo==0) icono=Ico_hotel;
	if (tipo==1) icono=Ico_well;
	if (tipo==2) icono=Ico_med;
	if (tipo==3) icono=Ico_con;

      var marker = createMarker(point, codHTML,icono);
      map.addOverlay(marker);
    //  bounds.extend(point);
    }
   // map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
  });
}

function createMarker(point, html,icono) {
  var marker = new GMarker(point,{icon:icono});
  GEvent.addListener(marker, 'click', function() {
    marker.openInfoWindowHtml(html);
  });
  return marker;
}


function load(map_lat, map_lng, map_zoom) {
      if (GBrowserIsCompatible()) {
        geocoder = new GClientGeocoder();
        map = new GMap2(document.getElementById('gmap'));
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        map.setCenter(new GLatLng(map_lng, map_lat), map_zoom);
		
      }
    }


    //]]>