var map = null;
var geocoder = null;
var marker = null;

function initialize(location){
  if(GBrowserIsCompatible()){
    map = new GMap2(document.getElementById("map"));
    map.setUIToDefault();
    geocoder = new GClientGeocoder();
    showAddress(location);
  }
}
function showAddress(address){
  if(geocoder){
    geocoder.getLatLng(
      address,
      function(point){
        if(!point){
          alert(address + " no encontrado");
        }else{
          map.setCenter(point, 15);
          marker = new GMarker(point, {draggable: true});
          GEvent.addListener(marker, "dragend", function() {
          	point = marker.getLatLng();
	          updateCoords(point);
	        });
          map.addOverlay(marker);
          updateCoords(point);
          marker.openInfoWindowHtml("<h1>Zuberance</h1><br />" + address);
        }
      }
    );
  }
}
function updateCoords(coords){
	$("#latitud").val(coords.lat());
	$("#longitud").val(coords.lng());
}
function close(){
	parent.TPL_FillLatLng($("input#latitud").val(),$("input#longitud").val());
	parent.jQuery.fn.colorbox.close();
}


$(document).ready(function(){
	initialize('628 El Camino Real, San Carlos, CA, 94070');

	$("form#contact").validate();
	$("form#contact #submit_btn").click(function(){
		$("form#contact").submit();
		$("label.error").hide();
		return false;
	});
});



