/*
	Oggetto Mappa
*/
function MapObj(id, lat, lng)
{
	this.id = id;
	this.lat = lat;
	this.lng = lng;
	this.map = "";
	this.markers = new Array();
	this.zoom = 5;
	this.panCtrl = false;
	this.typeCtrl = false;
}

MapObj.prototype.setZoom = function (zoom)
{
	if (!isNaN(zoom))
	{
		this.zoom = zoom;
	}
}
MapObj.prototype.addPanControl = function ()
{
	this.panCtrl = true;
}
MapObj.prototype.addTypeControl = function ()
{
	this.typeCtrl = true;
}

MapObj.prototype.addMarker = function (lat, lng, txt)
{
	var index = this.markers.push( new GMarker( new GLatLng(lat, lng) ) );
	index = index - 1;
	if (txt != "") 
	{
		GEvent.bind(this.markers[index], "click", this.markers[index], GEvent.callbackArgs(this.markers[index], this.markers[index].openInfoWindowHtml, txt));
	}
}

function MapsObj()
{
	this.maps = new Array();
}

MapsObj.prototype.addMap = function(id, lat, lng)
{
	currMap = new MapObj(id, lat, lng);
	this.maps.push(currMap);
	return currMap;
}


MapsObj.prototype.carica = function()
{
	var currMap;
	if (this.maps.length > 0)
	{
		if (GBrowserIsCompatible()) 
		{
			//for (index in this.maps)
			for (var i = 0, len = this.maps.length ; i < len ; i++ )
			{
				currMap = this.maps[i];
				currMap.map = new GMap2(document.getElementById(currMap.id));
				currMap.map.setCenter(new GLatLng(currMap.lat, currMap.lng), currMap.zoom);
				if (currMap.panCtrl) { currMap.map.addControl( new GSmallMapControl() ); }
				if (currMap.typeCtrl) { currMap.map.addControl( new GMapTypeControl() ); }
				
				//for (m in currMap.markers)
				for (var m = 0, mlen = currMap.markers.length ; m < mlen ; m++ )
				{
					currMap.map.addOverlay(currMap.markers[m]);
				}
			}	
		}
	}
}

var allMaps = new MapsObj();

if (window.addEventListener)
{
	window.addEventListener("load", function() { allMaps.carica(); }, false)
}
else if (window.attachEvent) { 
	window.attachEvent("onload", function() { allMaps.carica(); }); 
}

//window.onload= function() { allMaps.carica(); }

