﻿function zoom (map, coordinate, zoom_level, desc_zoom) {

    map.panTo(coordinate);
    document.getElementById("elab").innerHTML = "Riposizionamento satellite in corso ...";

    window.setTimeout(function() {
          map.setCenter(coordinate);
		  map.setZoom(zoom_level);
          document.getElementById("footer").innerHTML = desc_zoom;
          document.getElementById("elab").innerHTML = "Zooming ...";
        }, 3000);
        
    window.setTimeout(function() {

          document.getElementById("elab").innerHTML = "";
        }, 6000);
    window.clearTimeout();
    }  
	
	
function TextualZoomInControl(controlDiv, map, infowindow,home_marker) {

  // 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.textDecoration = "underline";
  controlUI.style.color = "#0000cc";
  controlUI.style.backgroundColor = "white";
  controlUI.style.padding = "5px";
  controlUI.style.font = "small Arial";
  controlUI.style.border = "1px solid black";
  controlUI.style.marginBottom = "6px";
  controlUI.style.textAlign = "center";
  controlUI.style.width = "6em";
  controlUI.style.cursor = "pointer";
  controlUI.style.fontWeight ="bold";
  controlUI.style.borderStyle = 'solid';
  controlUI.style.borderWidth = '2px';
  controlUI.style.textAlign = 'center';
  controlUI.title = 'Clicca per ZOOM +';
  controlDiv.appendChild(controlUI);

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

  // Setup the click event listeners:
  google.maps.event.addDomListener(controlUI, 'click', function() {
        levzoom = levzoom + 1;
        switch (levzoom) {
            case 1: new zoom (map, berlin, 4, desc_zoom_1);break;
            case 2: new zoom (map, roma, 6, desc_zoom_2);break;
            case 3: new zoom (map, venezia, 7, desc_zoom_3);break;
            case 4: new zoom (map, treviso, 9, desc_zoom_4);break;
            case 5: new zoom (map, home, 15, desc_zoom_5);infowindow.open(map,home_marker);break;
            default: alert('Raggiunto il livello MAX di zoom! Clicca su "ZOOM OUT"');levzoom=5;break;
        };
  });
}

function TextualZoomOutControl(controlDiv, map, infowindow,home_marker) {

  // 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.textDecoration = "underline";
  controlUI.style.color = "#0000cc";
  controlUI.style.backgroundColor = "white";
  controlUI.style.padding = "5px";
  controlUI.style.font = "small Arial";
  controlUI.style.border = "1px solid black";
  controlUI.style.marginBottom = "6px";
  controlUI.style.textAlign = "center";
  controlUI.style.width = "6em";
  controlUI.style.cursor = "pointer";
  controlUI.style.fontWeight ="bold";
  controlUI.style.borderStyle = 'solid';
  controlUI.style.borderWidth = '2px';
  controlUI.style.textAlign = 'center';
  controlUI.title = 'Clicca per ZOOM -';
  controlDiv.appendChild(controlUI);

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

  // Setup the click event listeners:
  google.maps.event.addDomListener(controlUI, 'click', function() {
        levzoom = levzoom - 1;
        switch (levzoom) {
            case 1: new zoom (map, berlin, 4, desc_zoom_1);break;
            case 2: new zoom (map, roma, 6, desc_zoom_2);break;
            case 3: new zoom (map, venezia, 7, desc_zoom_3);break;
            case 4: new zoom (map, treviso, 9, desc_zoom_4);break;
            case 5: new zoom (map, home, 15, desc_zoom_5);infowindow.open(map,home_marker);break;
            default: alert('Raggiunto il livello MIN di zoom! Clicca su "ZOOM IN"');levzoom=1;break;
        };
  });
}	
	
function ResetZoomControl(controlDiv, map) {

  // 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.textDecoration = "underline";
  controlUI.style.color = "#0000cc";
  controlUI.style.backgroundColor = "YELLOW";
  controlUI.style.padding = "5px";
  controlUI.style.font = "small Arial";
  controlUI.style.border = "1px solid black";
  controlUI.style.marginBottom = "6px";
  controlUI.style.textAlign = "center";
  controlUI.style.width = "6em";
  controlUI.style.cursor = "pointer";
  controlUI.style.fontWeight ="bold";
  controlUI.style.borderStyle = 'solid';
  controlUI.style.borderWidth = '2px';
  controlUI.style.textAlign = 'center';
  controlUI.title = 'Clicca per RESET dello ZOOM';
  controlDiv.appendChild(controlUI);

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

  // Setup the click event listeners:
  google.maps.event.addDomListener(controlUI, 'click', function() {
            new zoom (map, berlin, 4, desc_zoom_1);
  });
}

function PercorsoControl(controlDiv, map) {

  // 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.textDecoration = "underline";
  controlUI.style.color = "#0000cc";
  controlUI.style.backgroundColor = "YELLOW";
  controlUI.style.padding = "5px";
  controlUI.style.font = "small Arial";
  controlUI.style.border = "1px solid black";
  controlUI.style.marginBottom = "6px";
  controlUI.style.textAlign = "center";
  controlUI.style.width = "6em";
  controlUI.style.cursor = "pointer";
  controlUI.style.fontWeight ="bold";
  controlUI.style.borderStyle = 'solid';
  controlUI.style.borderWidth = '2px';
  controlUI.style.textAlign = 'center';
  controlUI.title = 'Clicca per indicazioni stradali';
  controlDiv.appendChild(controlUI);

  // Set CSS for the control interior
  var controlText = document.createElement('DIV');
  controlText.style.fontFamily = 'Arial,sans-serif';
  controlText.style.paddingLeft = '4px';
  controlText.style.paddingRight = '4px';
  controlText.style.textAlign = "center";
  controlText.innerHTML = 'Calcola Percorso...';
  controlUI.appendChild(controlText);

  // Setup the click event listeners:
  google.maps.event.addDomListener(controlUI, 'click', function() {
            newwindow=window.open();
			newwindow.location.href="http://www.google.com/maps?source=uds&daddr=Via+Madonna+delle%20grazie+%2C+Cison+di%20+Valmarino%2C+Treviso+%2C+31030+%4045.9638%2C12.142&iwstate1=dir:to";
  });
}	

    function initialize() {
      

        desc_zoom_1="Zoom: EUROPA";
        desc_zoom_2="Zoom: EUROPA >> ITALIA";
        desc_zoom_3="Zoom: EUROPA >> ITALIA >> VENETO";
        desc_zoom_4="Zoom: EUROPA >> ITALIA >> VENETO >> TREVISO";
        desc_zoom_5="Zoom: EUROPA >> ITALIA >> VENETO >> TREVISO >> CISON DI VALMARINO (Home S.r.l.)";
        
		document.getElementById("footer").innerHTML = desc_zoom_1;
		        
        berlin = new google.maps.LatLng(52.518611, 13.408333);
        roma = new google.maps.LatLng(41.910833, 12.481667);
        venezia = new google.maps.LatLng(45.434167, 12.338889);
        treviso = new google.maps.LatLng(45.666667, 12.250000);
        home = new google.maps.LatLng(45.9638, 12.142);
        levzoom=1;
		
		var mapOptions = {
           zoom: 4,
           center: berlin,
		   disableDefaultUI: true,
           scaleControl: true,
		   mapTypeControl: true,
           mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
           navigationControl: false,
           mapTypeId: google.maps.MapTypeId.ROADMAP
        };
		
    var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions); 
    



	
	var contentString = '<b><em>Home S.r.l.</em>'+
	                       '<br>Cucine Componibili</b><br>'+
						   'Via III settembre, 2<br>31030 Cison di Valmarino (Treviso)<br><br><br>'+
						   'Indicazioni: <a target=_blank href="http://www.google.com/maps?source=uds&daddr=Via+Madonna+delle%20grazie+%2C+Cison+di%20+Valmarino%2C+Treviso+%2C+31030+%4045.9638%2C12.142&iwstate1=dir:to">'+
						   '<span class="map"> A qui</span></a>';
        
    var infowindow = new google.maps.InfoWindow({
        content: contentString
    });
    
	var image = 'Home.png';
    var home_marker = new google.maps.Marker({
        position: home,
        map: map,
        title: 'Home S.r.l.: Clicca qui per conoscere dove siamo!',
		icon: image
    });
    google.maps.event.addListener(home_marker, 'click', function() {
      infowindow.open(map,home_marker);
    });
	
	google.maps.event.addListener(map, 'drag', function() {
      document.getElementById("elab").innerHTML = "Riposizionamento satellite in corso ...";
    });
	
    google.maps.event.addListener(map, 'dragend', function() {
      document.getElementById("elab").innerHTML = "";
    });
	
   // pulsante ZOOM +
   var ZoomInDiv = document.createElement('DIV');
   var ZoomIN = new TextualZoomInControl(ZoomInDiv, map, infowindow, home_marker);
   ZoomInDiv.index = 1;
   map.controls[google.maps.ControlPosition.TOP_LEFT].push(ZoomInDiv);
   
   // pulsante RESET ZOOM 
   var ZoomResetDiv = document.createElement('DIV');
   var ZoomReset = new ResetZoomControl(ZoomResetDiv, map);
   ZoomResetDiv.index = 1;
   map.controls[google.maps.ControlPosition.LEFT].push(ZoomResetDiv);

   
   // pulsante ZOOM -
   var ZoomOutDiv = document.createElement('DIV');
   var ZoomOUT = new TextualZoomOutControl(ZoomOutDiv, map, infowindow, home_marker);
   ZoomOutDiv.index = 1;
   map.controls[google.maps.ControlPosition.LEFT].push(ZoomOutDiv);
   
   // pulsante INDICAZIONI STRADALI
   var PercorsoDiv = document.createElement('DIV');
   var Percorso = new PercorsoControl(PercorsoDiv, map);
   PercorsoDiv.index = 1;
   map.controls[google.maps.ControlPosition.RIGHT].push(PercorsoDiv);

    }
