﻿// JScript File
var map;

function Init()
{
	//ResizeLayout();
	//window.onresize = ResizeLayout;
	load();
	ShowInfo();
}

function ShowInfo()
{
	// Download the data in data.xml and load it on the map. The format we
	//	expect is:	
	// <markers>
	//   <marker name="roma" lat="41.5614" lng="12.2855"/>
	//   <marker name="perugia" lat="41.0000" lng="12.0000"/>
	// </markers>
	GDownloadUrl("res/xml/comunistellati.xml", function(data, responseCode) 
	{
		// Create our "tiny" marker icon
		var icon = new GIcon();
		icon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
		icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
		icon.iconSize = new GSize(12, 20);
		icon.shadowSize = new GSize(22, 20);
		icon.iconAnchor = new GPoint(6, 20);
		icon.infoWindowAnchor = new GPoint(5, 1);

		var xml = GXml.parse(data);
		var markers = xml.documentElement.getElementsByTagName("marker");
		for(var i = 0; i < markers.length; i++) 
		{
			var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
                            parseFloat(markers[i].getAttribute("lng")));
         var name = markers[i].getAttribute("name")

			map.addOverlay(createMarker(point,name,icon));
		}
	});
}

function createMarker(point, name,icon) {
  var marker = new GMarker(point,icon);
  GEvent.addListener(marker, "click", function() {
    marker.openInfoWindowHtml(name);
  });
  return marker;
}

function load() 
{
	if (GBrowserIsCompatible()) 
	{
		map = new GMap2(document.getElementById('map'));
      map.setCenter(new GLatLng(42.086965,12.211648), 6,G_SATELLITE_MAP);
      map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
   }
}

function ResizeLayout()
{
	var frameWidth,frameHeight;

	if (self.innerWidth)
	{
		frameWidth = self.innerWidth;
		frameHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientWidth)
	{
		frameWidth = document.documentElement.clientWidth;
		frameHeight = document.documentElement.clientHeight;
	}
	else if (document.body)
	{
		frameWidth = document.body.clientWidth;
		frameHeight = document.body.clientHeight;
	}

	var objMap = document.getElementById("map");
	var objTxt = document.getElementById("txt");
	var NewWidth = frameWidth-410;
	var NewHeight = frameHeight-150;

	objMap.style.width = NewWidth + "px";
	objMap.style.height = NewHeight + "px";
	objTxt.style.height = NewHeight + "px";
}


