function initMap(map)
{
	map.setMapType(G_PHYSICAL_MAP);
	map.addControl(new GLargeMapControl());
	map.addMapType(G_PHYSICAL_MAP);
	map.addControl(new GMapTypeControl());

	G_SATELLITE_MAP.getMinimumResolution = function(){return 8};
	G_PHYSICAL_MAP.getMinimumResolution = function(){return 8};
	G_NORMAL_MAP.getMinimumResolution = function(){return 8};
	G_HYBRID_MAP.getMinimumResolution = function(){return 8};
	
	GEvent.addListener(map, "infowindowopen", function()
	{
		var infoWindow = map.getInfoWindow();
		var tmppoint = map.fromLatLngToContainerPixel(infoWindow.getPoint());
		map.panTo(map.fromContainerPixelToLatLng(tmppoint));
	});
}

function createIcon() {
	var icon = new GIcon(null, './images/arrow.png');
	icon.shadow = 'http://www.google.com/mapfiles/shadow50.png';
	icon.iconSize = new GSize(30, 42);
	icon.shadowSize = new GSize(30, 42);
	icon.iconAnchor = new GPoint(15, 42);
	icon.infoWindowAnchor = new GPoint(3, 41);
	icon.infoShadowAnchor = new GPoint(3, 41);
	return icon;
}

function onLoadCountry(widget)
{
	map = widget.gmap;
	map.disableInfoWindow();
	initMap(map);

	for(var i in widget.item.markers)
	{
		var label = new ELabel(widget.item.markers[i].gmarker.getLatLng(), 
								'<div><p style="font-weight:bold;font-size:14px">'+provinceCount[widget.item.markers[i].title]+'</p><p>'+widget.item.markers[i].title+'</p></div>', 
								'mapProvince" onclick="location.href=\''+provinceUrl[widget.item.markers[i].title]+'\'',
								new GSize(-43,1));
		map.addOverlay(label);
	}
}

var globalMap;
var networkArr = new Array();

function onLoadProv(widget)
{
	var map = widget.gmap;
	globalMap = map;
	initMap(map);
	
	if(networkLocations.length > 0) {
		var icon = createIcon();
		for(var i = 0; i < networkLocations.length; i++) {
			var object = networkLocations[i];

			var array = object['location'].split(';');
			var marker = new GMarker(new GLatLng(array[0], array[1]), {
				title: object['name'],
				icon: icon ? icon : G_DEFAULT_ICON,
				clickable: true,
				draggable: false
			});
			object['marker'] = marker;
			networkArr[object['id']] = object;
			marker.bindInfoWindowHtml(object['content']);
			map.addOverlay(marker);
		}
	}
}

function onLoadLocation(widget)
{
	var map = widget.gmap;
	globalMap = map;
	initMap(map);
	
	if(networkLocations.length > 0) {
		var icon = createIcon();
		for(var i = 0; i < networkLocations.length; i++) {
			var object = networkLocations[i];

			var array = object['location'].split(';');
			var marker = new GMarker(new GLatLng(array[0], array[1]), {
				title: object['name'],
				icon: icon ? icon : G_DEFAULT_ICON,
				clickable: false,
				draggable: false
			});
			object['marker'] = marker;
			networkArr[object['id']] = object;
			map.addOverlay(marker);
			map.setCenter(marker.getPoint());
		}
	}
}

function onLoadSearchResults(widget)
{
	var map = widget.gmap;
	globalMap = map;
	initMap(map);
	
	for(var i in widget.item.markers)
	{
		widget.item.markers[i].gmarker.hide();
	}
	
	if(networkLocations.length > 0) {
		var icon = createIcon();
		for(var i = 0; i < networkLocations.length; i++) {
			var object = networkLocations[i];

			var array = object['location'].split(';');
			var marker = new GMarker(new GLatLng(array[0], array[1]), {
				title: object['name'],
				icon: icon ? icon : G_DEFAULT_ICON,
				clickable: true,
				draggable: false
			});
			object['marker'] = marker;
			networkArr[object['id']] = object;
			marker.bindInfoWindowHtml(object['content']);
			map.addOverlay(marker);
		}
	}
}

function selectNetwork(i)
{
	var marker = networkArr[i]['marker'];
	globalMap.panTo(marker.getPoint());
	marker.openInfoWindowHtml(networkArr[i]['content']);
}