// Route Planner button on map:
function DirectionsControl(controlDiv) {

  // Set CSS styles for the DIV containing the control
  // Setting padding to 5 px will offset the control
  // from the edge of the map
  controlDiv.style.padding = '5px';

  // Set CSS for the control border
  var controlUI = document.createElement('DIV');
  controlUI.style.backgroundColor = 'white';
  controlUI.style.borderStyle = 'solid';
  controlUI.style.borderWidth = '2px';
  controlUI.style.cursor = 'pointer';
  controlUI.style.textAlign = 'center';
  controlUI.title = 'Click to open Route Planner';
  controlDiv.appendChild(controlUI);

  // Set CSS for the control interior
  var controlText = document.createElement('DIV');
  controlText.style.fontFamily = 'Arial,sans-serif';
  controlText.style.fontSize = '12px';
  controlText.style.paddingLeft = '4px';
  controlText.style.paddingRight = '4px';
  controlText.innerHTML = '<b>Route Planner</b>';
  controlUI.appendChild(controlText);

  // Setup the click event listeners: simply set the map to directions_center
  google.maps.event.addDomListener(controlUI, 'click', function() {
	window.open('http://maps.google.com/?q=Frazione%20Piccolino,%2042,%2039030%20San%20Martino%20In%20Badia,%20Italia&f=d','','scrollbars=no,menubar=no,height=600,width=1000,resizable=yes,toolbar=no,location=no,status=no');
  });

}

// Home button on map:
function HomeControl(controlDiv, map, home_center) {

  // Set CSS styles for the DIV containing the control
  // Setting padding to 5 px will offset the control
  // from the edge of the map
  controlDiv.style.padding = '5px';

  // Set CSS for the control border
  var controlUI = document.createElement('DIV');
  controlUI.style.backgroundColor = 'white';
  controlUI.style.borderStyle = 'solid';
  controlUI.style.borderWidth = '2px';
  controlUI.style.cursor = 'pointer';
  controlUI.style.textAlign = 'center';
  controlUI.title = 'Click to set the map to Home';
  controlDiv.appendChild(controlUI);

  // Set CSS for the control interior
  var controlText = document.createElement('DIV');
  controlText.style.fontFamily = 'Arial,sans-serif';
  controlText.style.fontSize = '12px';
  controlText.style.paddingLeft = '4px';
  controlText.style.paddingRight = '4px';
  controlText.innerHTML = '<b>Home</b>';
  controlUI.appendChild(controlText);

  // Setup the click event listeners: simply set the map to home_center
  google.maps.event.addDomListener(controlUI, 'click', function() {
    map.setCenter(home_center)
	});

}

// Initialize the Google Maps Javascript API asynchronously:
function initializeGoogleMapsApi() {
    var myLatlng = new google.maps.LatLng(46.68859,11.894769);
    var myOptions = {
      zoom: 14,
      center: myLatlng,
      mapTypeControl: true,
	  panControl: true,
      mapTypeControlOptions: {
        style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
      },
      zoomControl: true,
      zoomControlOptions: {
        style: google.maps.ZoomControlStyle.SMALL
      },
      mapTypeId: google.maps.MapTypeId.SATELLITE
    }
	
    var map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);
	
	// Create the DIV to hold the control and
	// call the HomeControl() constructor passing
	// in this DIV.
	var homeControlDiv = document.createElement('DIV');
	var homeControl = new HomeControl(homeControlDiv, map, myLatlng);
	homeControlDiv.index = 1;
	map.controls[google.maps.ControlPosition.TOP_RIGHT].push(homeControlDiv);

	// Create the DIV to hold the control and
	// call the DirectionsControl() constructor passing
	// in this DIV.
	var directionsControlDiv = document.createElement('DIV');
	var directionsControl = new DirectionsControl(directionsControlDiv);
	directionsControlDiv.index = 1;
	map.controls[google.maps.ControlPosition.TOP_RIGHT].push(directionsControlDiv);
	
	var contentString = '<div id="maps_content">'+
        '<!--<h1 id="firstHeading" class="firstHeading">Ostaria Posta</h1>-->'+
        '<div id="mapsBodyContent">'+
        '<p>Ostaria Posta ***<br />Picolin 42<br />I-39030 San Martin de Tor<br />T +39 0474 52 31 28<br />F +39 0474 52 34 22</p>'+
        '</div>'+
        '</div>';
        
    var infowindow = new google.maps.InfoWindow({
        content: contentString
    });

    var marker = new google.maps.Marker({
        position: myLatlng,
        map: map,
        title: 'Uluru (Ayers Rock)'
    });
    google.maps.event.addListener(marker, 'click', function() {
      infowindow.open(map,marker);
    });
}

// Load the Google Maps Javascript API asynchronously:
function loadGoogleMapsApiAsynchronously() {
	var script = document.createElement("script");
	script.type = "text/javascript";
	// Note: Google Maps API keys are only required when using the JavaScript Maps API V2 and the Maps API for Flash. (http://code.google.com/apis/maps/faq.html)
	// script.src = "http://maps.googleapis.com/maps/api/js?key=ABQIAAAAZ_E59VZGYNw28q1mx0hHzBT2NjbyXon_yb-JQIwtTJUxqAeEkxQ8A9Y5yXG-_PjAtsPmguXyrrhudA&sensor=false&callback=initializeGoogleMapsApi";
	script.src = "http://maps.googleapis.com/maps/api/js?sensor=false&callback=initializeGoogleMapsApi";
	document.body.appendChild(script);
}

