var centerLatitude = 46.177847;
var centerLongitude = 13.228950;

var startZoom = 9;
var currZoom = startZoom;
var markersArray1 = new Array();
var markersArray2 = new Array();
var markersArray2 = new Array();
var map;


var new_icon = new GIcon();  
 new_icon.image = "logorosso2.png";
 new_icon.size = new GSize(30,30);
 new_icon.iconAnchor = new GPoint(8,9);  
 new_icon.infoWindowAnchor = new GPoint(7,7);  
 var opt ; 
 opt = {icon:new_icon};  
 //opt.icon = new_icon;  

 var new_icon2 = new GIcon();  
 new_icon2.image = "stemma4.png";
 new_icon2.size = new GSize(30,30);
 new_icon2.iconAnchor = new GPoint(8,9);  
 new_icon2.infoWindowAnchor = new GPoint(7,7);  
 var opt ; 
 opt2 = {icon:new_icon2};  
 //opt.icon = new_icon;  






function init()
{
   if (GBrowserIsCompatible()) 
   {

	if(document.getElementById("map")!=null){
      map = new GMap2(document.getElementById("map"));
      
      map.addControl(new GLargeMapControl());
	  
	  
	      
            map.addControl(new GScaleControl());
            //GSmallMapControl
            //GLargeMapControl
            //GSmallZoomControl
            //GLargeMapControl3D 
            //GSmallZoomControl3D() 
			//GScaleControl() 	
			//GMapTypeControl() 	
			//GMenuMapTypeControl() 	
			map.addControl(new GHierarchicalMapTypeControl()); 	
			//map.addControl(new GOverviewMapControl()); 	
			//map.addControl(new GNavLabelControl() );
			map.addMapType(G_PHYSICAL_MAP) ; 
	  
	  
	  
	  
	  
	  
      var location = new GLatLng(centerLatitude, centerLongitude);
      map.setCenter(location, startZoom);
	  map.enableScrollWheelZoom();
	  
	  
	  
	  geoXml = new GGeoXml("http://www.provincia.udine.it/musei/PublishingImages/musei_map.kml");
    map.addControl(new GLargeMapControl());
    map.setCenter(new GLatLng(46.177847, 13.229999), 9); 
    map.addControl(new GLargeMapControl());
    map.addOverlay(geoXml);
    }
 }

}


function createMarker()
{

	if (document.mapForm.controllo[0].checked){
	
	
///marker 1 via Santa Lucia, 7 - Gemona del Friuli
   var location1 = new GLatLng(46.272113, 13.130957);
   var marker1 = new GMarker(location1,opt);
   GEvent.addListener(marker1, "mouseover", function() { //click, mouseover
             marker1.openInfoWindowHtml("<img id='aaa' src='stemma3.png'/><br/><b>Centro per l'Impiego</b><br/>via Santa Lucia, 7 - Gemona del Friuli");
              });
   map.addOverlay(marker1);
   markersArray1.push(marker1);
  
  
  ///marker 2 via Manzoni, 2 - Codroipo
   var location2 = new GLatLng(45.963475, 12.981363);
   var marker2 = new GMarker(location2,opt);
   GEvent.addListener(marker2, "mouseover", function() { //click, mouseover
             marker2.openInfoWindowHtml("<img id='aaa' src='stemma3.png'/><br/><b>Centro per l'Impiego</b><br/>via Manzoni, 2 - Codroipo");
              });
   map.addOverlay(marker2);
   markersArray1.push(marker2);
  ////
   
   
   ////marker 3 stretta San Martino, 4 - Cividale del Friuli
   var location3 = new GLatLng(46.091732, 13.432588);
   var marker3 = new GMarker(location3,opt);
   GEvent.addListener(marker3, "mouseover", function() { //click, mouseover
             marker3.openInfoWindowHtml("<img id='aaa' src='stemma3.png'/><br/><b>Centro per l'Impiego</b><br/>stretta San Martino, 4 - Cividale del Friuli");
              });
   map.addOverlay(marker3); 
   markersArray1.push(marker3);
   //////fine marker 3
	
   ////marker 4 via Ramazzotti, 16 - Cervignano del Friuli
   var location4 = new GLatLng(45.827760, 13.339726);
   var marker4 = new GMarker(location4,opt);
   GEvent.addListener(marker4, "mouseover", function() { //click, mouseover
             marker4.openInfoWindowHtml("<img id='aaa' src='stemma3.png'/><br/><b>Centro per l'Impiego</b><br/>via Ramazzotti, 16 - Cervignano del Friuli");
              });
   map.addOverlay(marker4); 
   markersArray1.push(marker4);
   //////fine marker 4
	
	   ////marker 5 via Manzoni, 48 - Latisana
   var location5 = new GLatLng(45.781269, 12.996346);
   var marker5 = new GMarker(location5,opt);
   GEvent.addListener(marker5, "mouseover", function() { //click, mouseover
             marker5.openInfoWindowHtml("<img id='aaa' src='stemma3.png'/><br/><b>Centro per l'Impiego</b><br/>via Manzoni, 48 - Latisana");
              });
   map.addOverlay(marker5); 
   markersArray1.push(marker5);
   //////fine marker 5
   
      ////marker 6 piazza Garibaldi, 1 - Pontebba
   var location6 = new GLatLng(46.506453, 13.304253);
   var marker6 = new GMarker(location6,opt);
   GEvent.addListener(marker6, "mouseover", function() { //click, mouseover
             marker6.openInfoWindowHtml("<img id='aaa' src='stemma3.png'/><br/><b>Centro per l'Impiego</b><br/>piazza Garibaldi, 1 - Pontebba");
              });
   map.addOverlay(marker6); 
   markersArray1.push(marker6);
   //////fine marker 6
   
      ////marker 7 via Udine, 2 - San Daniele del Friuli
   var location7 = new GLatLng(46.156287, 13.009284);
   var marker7 = new GMarker(location7,opt);
   GEvent.addListener(marker7, "mouseover", function() { //click, mouseover
             marker7.openInfoWindowHtml("<img id='aaa' src='stemma3.png'/><br/><b>Centro per l'Impiego</b><br/>via Udine, 2 - San Daniele del Friuli");
              });
   map.addOverlay(marker7); 
   markersArray1.push(marker7);
    //////fine marker 7
    
    ////marker 8 viale Matteotti, 33 - Tarcento
   var location8 = new GLatLng(46.214981, 13.215991);
   var marker8 = new GMarker(location8,opt);
   GEvent.addListener(marker8, "mouseover", function() { //click, mouseover
             marker8.openInfoWindowHtml("<img id='aaa' src='stemma3.png'/><br/><b>Centro per l'Impiego</b><br/>viale Matteotti, 33 - Tarcento");
              });
   map.addOverlay(marker8); 
   markersArray1.push(marker8);
    //////fine marker 8
    
        ////marker 9 Via Matteotti, 19 - Tolmezzo
   var location9 = new GLatLng(46.407850, 13.012874);
   var marker9 = new GMarker(location9,opt);
   GEvent.addListener(marker9, "mouseover", function() { //click, mouseover
             marker9.openInfoWindowHtml("<img id='aaa' src='stemma3.png'/><br/><b>Centro per l'Impiego</b><br/>Via Matteotti, 19 - Tolmezzo");
              });
   map.addOverlay(marker9); 
   markersArray1.push(marker9);
    //////fine marker 9
   
     ////marker 10 viale Duodo, 3 - Udine
   var location10 = new GLatLng(46.057847, 13.228950);
   var marker10 = new GMarker(location10,opt);
   GEvent.addListener(marker10, "mouseover", function() { //click, mouseover
             marker10.openInfoWindowHtml("<img id='aaa' src='stemma3.png'/><br/><b>Centro per l'Impiego</b><br/>viale Duodo, 3 - Udine");
              });
   map.addOverlay(marker10); 
   markersArray1.push(marker10);
    //////fine marker 10
   
   
   
   
   
   
   
   }else{removeAllMarkers1();}
  
}

function createMarker2()
{

if (document.mapForm.controllo[1].checked){
   var latitude = 46.063256;
   var longitude = 13.240457;
    var location = new GLatLng(latitude, longitude);
   var marker = new GMarker(location,opt2);
   map.addOverlay(marker);
   markersArray2.push(marker)
   
   var latitude2 = 46.129360;
   var longitude2 = 13.486376;
    var location2 = new GLatLng(latitude2, longitude2);
   var marker2 = new GMarker(location2,opt2);
   map.addOverlay(marker2);
   markersArray2.push(marker2)
   
      var latitude3 = 46.272667;
   var longitude3 = 13.130665;
    var location3 = new GLatLng(latitude3, longitude2);
   var marker3 = new GMarker(location3,opt2);
   map.addOverlay(marker3);
   markersArray2.push(marker3)
   
  }else{removeAllMarkers2();}
  // map.setCenter(location, map.getZoom());
}

function renderMarkerList()
{
   var divContents = "";
   var currMarker;
   
   
   for (var i = 0; i < markersArray.length; i++) 
   {
      currMarker = markersArray[i];
      divContents += "Marker " + i + " (" + currMarker.getLatLng().lat() + "," + currMarker.getLatLng().lng() + ") ";
      divContents += "<a href=\"#\" onClick=\"goToMarker("+ i +");\">Go there</a> <a href=\"#\" onClick=\"removeMarker("+ i +");\">Remove</a><br/>";
   }
   
   
   
   document.getElementById('currentMarkersDiv').innerHTML = divContents;
}



function goToMarker(idx)
{
   if( idx >= 0 && idx < markersArray.length )
   {
      var location = markersArray[idx].getLatLng();
      map.setCenter(location, map.getZoom());
   }
}



function removeMarker(idx)
{
   if( idx >= 0 && idx < markersArray.length )
   {
      // remove marker from map and array
      map.removeOverlay(markersArray[idx]);
      markersArray.splice(idx,1);
      
      renderMarkerList();
   }
   
}




function removeAllMarkers1()
{
   for (var i = 0; i < markersArray1.length; i++) 
   {
      map.removeOverlay(markersArray1[i]);
   }
   
   markersArray1 = new Array();
   
}

function removeAllMarkers2()
{
   for (var i = 0; i < markersArray2.length; i++) 
   {
      map.removeOverlay(markersArray2[i]);
   }
   
   markersArray2 = new Array();
   
}

function removeAllMarkers3()
{
   for (var i = 0; i < markersArray3.length; i++) 
   {
      map.removeOverlay(markersArray3[i]);
   }
   
   markersArray3 = new Array();
   
}






// function to trim string
function trim(word)
{
   while (word.substring(0,1) == ' ')
      word = word.substring(1, word.length);

   while (word.substring(word.length-1, word.length) == ' ')
      word = word.substring(0,word.length-1);
      
   return word;
}



var edifici=[
          
            
             new GLatLng(46.063029,13.240457),
             new GLatLng(46.062582,13.240328),
             new GLatLng(46.061436,13.239491),
             new GLatLng(46.060185,13.238332),
             new GLatLng(46.059495,13.237066),
             new GLatLng(46.059323,13.234524),
             new GLatLng(46.059353,13.233515),
             new GLatLng(46.058073,13.234749)
            
            
            ];
            var poly = new GPolyline(edifici, '#ff0000', 5, 0.7);  


var strada=[



new GLatLng(46.063524,13.239641),
new GLatLng(46.062601,13.240929),
new GLatLng(46.061708,13.241916),
new GLatLng(46.060248,13.243461),
new GLatLng(46.059385,13.244619),
new GLatLng(46.058223,13.245478),
new GLatLng(46.056973,13.246078),
new GLatLng(46.055454,13.246851)

];
 var poly2 = new GPolyline(strada, '#0000ff', 5, 0.7); 


function createStrade()
{




if (document.mapForm.controllo[2].checked){
     var location = new GLatLng(centerLatitude, centerLongitude);
      map.setCenter(location,12);
document.getElementById('contenuti').innerHTML = "<br/>Strade della Provincia di Udine:<br/><br/>rosso: SP 88 - Strada di Prova<br/>blu: SP 82 - Strada del Friuli";
        	map.addOverlay(poly);
        	map.addOverlay(poly2);

   markersArray3.push(poly);
  }else{
  
  map.removeOverlay(poly);
  map.removeOverlay(poly2);
  document.getElementById('contenuti').innerHTML ="";
  var location = new GLatLng(centerLatitude, centerLongitude);
  map.setCenter(location,9);
  
  
  }
  // map.setCenter(location, map.getZoom());
}

var geoXml;

function createPunti()
{
if (document.mapForm.controllo[3].checked){

 geoXml = new GGeoXml("http://www.provincia.udine.it/musei/PublishingImages/musei_map.kml");
    map.addControl(new GLargeMapControl());
    map.setCenter(new GLatLng(46.177847, 13.229999), 9); 
    map.addControl(new GLargeMapControl());
    map.addOverlay(geoXml);

}





}


window.onload = init;
window.onunload = GUnload;


