$(function()
{
 $('#location').tabs();    
 var map = new GMap2(document.getElementById('mapa'));
 
 //atributos de los maps en cusco
 var puntos={
              cusco:new GLatLng(-13.517259067068661,-71.97847366333008),
              lima:new GLatLng(-12.114546548194129,-77.02948093414307),
              nazca:new GLatLng(-14.827496278114957,-74.94074821472168),
              mapi:new GLatLng(-13.154074476023668,-72.52326250076294),
              puno:new GLatLng(-15.832822,-70.028293),
              arequipa:new GLatLng(-16.39529,-71.533163)
              };
              
 map.setCenter(puntos.cusco, 15);
 map.setUIToDefault();
 var miIcono = new GIcon(G_DEFAULT_ICON);
 miIcono.image = "./imagenes/icon/icon_pirwa.png";
 miIcono.iconSize=new GSize(20,33);
 
 var markers={};
 var points={
              colonial:new GLatLng(-13.5180522183775,-71.98204100131989),
	      corregidor:new GLatLng(-13.516305613097275,-71.97949290275574),
	      suecia:new GLatLng(-13.515600777932079,-71.97905838489532),
	      sanblas: new GLatLng(-13.513629175622071,-71.9762796163559),
	      prada:new GLatLng(-12.116894877891111,-77.02866554260254),
	      inclan:new GLatLng(-12.1149542555347,-77.03127264976501),
              nazca: new GLatLng(-14.824250,-74.937115),
              mapi:new GLatLng(-13.153833490864024,-72.52300500869751),
              puno:new GLatLng(-15.832822, -70.028293),
              byb:new GLatLng(-16.392279,-71.53261),
              hostel:new GLatLng(-16.392078,-71.533592)
              };
              
 $.each(points,function(key,val)
 {
              var marker=new GMarker(val,miIcono);
              map.addOverlay(marker);
              markers[key]=marker;
 });
  $("#map_msg").appendTo(map.getPane(G_MAP_FLOAT_SHADOW_PANE));              
  $.each(markers,function(i,marker){
    GEvent.addListener(marker, "click", function(){
      displayPoint(marker, i);
    });
  });    
  $("#location span").click(function(){
    $("#map_msg").hide();
	mostrar($(this).attr('id'));		
    map.panTo(puntos[this.id]);
  }); 
  function ocultar(){
	  $("#tab-cusco").hide();
	  $("#tab-lima").hide();
	  $("#tab-nazca").hide();
	  $("#tab-arequipa").hide();
	  $("#tab-puno").hide();
	  $("#tab-mapi").hide();
  }
  function mostrar(nombre){
	  ocultar();
	  switch(nombre){
		  case "cusco":{$("#tab-cusco").show();break;}
		  case "lima":{$("#tab-lima").show();break;}
		  case "nazca":{$("#tab-nazca").show();break;}
		  case "arequipa":{$("#tab-arequipa").show();break;}
		  case "puno":{$("#tab-puno").show();break;}
		  case "mapi":{$("#tab-mapi").show();break;}
		  }
  }
  function displayPoint(marker, key){
    $("#map_msg").hide().empty();    
    var moveEnd = GEvent.addListener(map, "moveend", function(){
      var markerOffset = map.fromLatLngToDivPixel(marker.getLatLng());
			var cont=$("div."+key).html();
      $("#map_msg").html(cont)
	      .css({ top:markerOffset.y, left:markerOffset.x })
                  .show(500);  
      GEvent.removeListener(moveEnd);  
    }); 
    var pto=new GLatLng(points[key].lat(),points[key].lng()+0.005);
    map.panTo(pto);
  } 
});

