﻿var liteweb_map = 
{
	_mapObject: null,
	markers: [],
	currentMarker: null,
	init: function(div)
	{
		try
		{
			if (GBrowserIsCompatible())
			{
				liteweb_map._mapObject = new GMap2(document.getElementById(div));
			}
			else
			{
				alert("Browser not compatible for maps");
			}
			var map = liteweb_map._mapObject;
			//map.removeMapType(G_SATELLITE_MAP);
			//map.addMapType(G_PHYSICAL_MAP);
			
			
			map.setCenter(new GLatLng(40.44, 12.65), 1);
			//map.addControl(new GLargeMapControl());
			map.addControl(new GLargeMapControl());
		
			map.enableScrollWheelZoom();
			map.enableDoubleClickZoom();
			
			GEvent.addListener(map, "click", function(overlay, latlng) {
			});
			GEvent.addListener(map, "moveend", function(overlay, latlng){
			});
			
		var crossLayer = new GTileLayer(new GCopyrightCollection(""), 0, 15);
        crossLayer.getTileUrl =  function(tile, zoom) {
          return "./include/tile_crosshairs.png";
        }
        crossLayer.isPng = function() {return true;}

        // Create a new map type incorporating the tile layer
        var layerTerCross = [ G_PHYSICAL_MAP.getTileLayers()[0],
                              crossLayer ];
        var mtTerCross = new GMapType(layerTerCross,
                                      G_PHYSICAL_MAP.getProjection(), "Ter+");

        map.addMapType(G_PHYSICAL_MAP);

        var mapControl = new GHierarchicalMapTypeControl();
        
        // Set up map type menu relationships
        mapControl.clearRelationships();
        mapControl.addRelationship(G_SATELLITE_MAP, G_HYBRID_MAP, "Labels", false);
  
        // Add control after you've specified the relationships
        map.addControl(mapControl);

		map.setMapType(G_HYBRID_MAP)
		}
		catch(e){
			alert("could not load map script: " + e.description);
		}
	},
	getLat: function(){
		return liteweb_map._mapObject.getCenter().lat();
	},
	getLng: function(){
		return liteweb_map._mapObject.getCenter().lng();
	},
	getZoom: function(){
		return liteweb_map._mapObject.getZoom();
	},
	setCenter: function(center, zoom){
		var map = liteweb_map._mapObject;
		map.setCenter(center, zoom);
	},
	addMarker: function(ln, lg, description, showInfo){
		var center = new GLatLng(ln, lg);
		var map = liteweb_map._mapObject;
		var marker = new GMarker(center, {title: description});
		GEvent.addListener(marker, "click", function() {
			marker.openInfoWindowHtml(description);
		});
		map.addOverlay(marker);
		if(showInfo === true)
			marker.openInfoWindowHtml(description);
		return center;
	}
}