
function  pintar_globitos(center1, zoom1) {
	var start = new Date().getTime();

	var map = new GMap2(document.getElementById("geomashup"));
	// Con centro en calle Princesa,2 Barcelona
	map.setCenter(center1, zoom1);
	map.addControl(new GLargeMapControl());
	GEvent.addListener(map, "zoomend", function() {
  //alert(map.getCenter()+" "+map.getZoom());
  //center = new GLatLng(41.41312313470301, 2.1454238891601562);
					 zoom = parseInt(map.getZoom());
					 center = map.getCenter();
});

GEvent.addListener(map, "moveend", function() {
  //alert(map.getCenter()+" "+map.getZoom());
  //center = new GLatLng(41.41312313470301, 2.1454238891601562);
					 zoom = parseInt(map.getZoom());
					 center = map.getCenter();
});
	// Create a base icon for all of our markers that specifies the
	// shadow, icon dimensions, etc.
	var baseIcon = new GIcon();	
	baseIcon.iconSize = new GSize(20, 21);
	baseIcon.shadowSize = new GSize(40, 20);
	baseIcon.iconAnchor = new GPoint(6, 20);
	baseIcon.infoWindowAnchor = new GPoint(5, 1);
	baseIcon.infoShadowAnchor = new GPoint(14, 24);

	// Creates a marker whose info window displays the letter corresponding
	// to the given index.
	function createMarker(point, index1,index2) {
	  // Create a lettered icon for this point using our icon class
	  var letteredIcon = new GIcon(baseIcon);
	  
		letteredIcon.image = "/wp-content/plugins/csdt_geomashup/images/"+categorias[index1][index2]+".png";
		letteredIcon.shadow = "/wp-content/plugins/csdt_geomashup/images/"+categorias[index1][index2]+"shadow.png";
	  
	  // Set up our GMarkerOptions object
	  markerOptions = { icon:letteredIcon };
	  var marker = new GMarker(point, markerOptions);

	  GEvent.addListener(marker, "click", function() {		
		marker.openInfoWindowHtml('<div style="height:90px; width:350px;"><a class="geomashup-address" href="'+permalinks[index1][index2]+'" target="_top">'+titulos[index1][index2]+'</a><p class="geomashup-excerpt">'+resumenes[index1][index2]+'... <a href="'+permalinks[index1][index2]+'" target="_top">'+csdt_geo_lang_read_more+'</a></p></div>',{maxWidth:350});
	  });
	  return marker;
	}
	
	
	
/*	
	var mgr = new MarkerManager(map);  
// Create marker array  
var markers = [];  
// Loop to create markers and adding them to the MarkerManager  
	for(j=0; j<niz.length; j++)
	{
		if(isValueInArray(niz,j))
		{
			for (i=0;i<latitudes[j].length;i++){	
	    	var marker = createMarker(new GLatLng(latitudes[j][i], longitudes[j][i]), j,i);  
	    	markers.push(marker);  
	  	}
  }
}
  
// Add the array to the MarkerManager  
mgr.addMarkers(markers,10);  
// Refresh the MarkerManager to make the markers appear on the map  
mgr.refresh();  

*/
	//pintar mi globito
	if(issingle == true)
	{
		map.addOverlay(createMarker(new GLatLng(latitudes[0][0], longitudes[0][0]), 0,0));
	}
	else
	{
		for(j=0; j<latitudes.length; j++)
		{
			if(isValueInArray(niz,j))
			{
				for (i=0;i<latitudes[j].length;i++)
				{
					map.addOverlay(createMarker(new GLatLng(latitudes[j][i], longitudes[j][i]), j,i));
				}
			}
		}
	}


}




function isValueInArray(arr, val) {
	inArray = false;
	for (a = 0; a < arr.length; a++)
		if (val == arr[a])
			inArray = true;
	return inArray;
}

window.onload = function(){
	if (GBrowserIsCompatible()) {
		if ((latitudes.length > 0) && (longitudes.length > 0)) {
			pintar_globitos(center, zoom);
		}
	}
};

$(document).ready(function() {
 
 niz.length = 0;
 
  
  
  
  for(i=0; i < niz_v.length; i++)
  {
  	if(niz_v[i] == 1)
  	{
  		niz.push(i);
  		break;
  	}
  }
  
  /*
  $('.catids').each(function(index) {
  	if(this.checked == true)
  	niz.push(this.value);
  });  
 
$('.catids').click(function() {
  
  niz.length = 0;
  
  $('.catids').each(function(index) {
  	if(this.checked == true)
  	niz.push(this.value);
  });
	pintar_globitos(center, zoom);
  //alert(niz.length);
});
*/

$('a').click(function() {
  
  //niz.length = 0;
  
  for(i=0; i < niz_v.length; i++)
  {
  	if(niz_v[i] == this.rel)
  	{
  		
  		if(isValueInArray(niz, i))
  		{
  			for(b=0; b < niz.length; b++)
  			{
  				if(niz[b] == i)
  				{
  					//alert(i);
  					niz.splice(b,1);
  					break;
  				}
  			}
  			//alert("nista");
  		}
  		else
  		{	
  		niz.push(i);
  		}
  		
  		break;
  	}
  	
  }
  //alert(niz);
	pintar_globitos(center, zoom);
  
});

});
