google.load("maps", "2.x");
google.setOnLoadCallback(gooInitialize);
var googleInitialized = false;

function gooInitialize(){

	mapsInit();
	chartInit();
	
	googleInitialized = true;
}



var map;
var bounds;
var ICON_DIR = "icons/";
	
var arrMarkers = new Array()
var arrListItems = new Array();

var g_arr = new Array();


var currentItemID;
//g_arr[0] = new Array();
//g_arr[0].line = line0;

var swlat, swlng, nelng, nelat;
var boundaries;

function mapsInit() {

	initMapIcons();
	map = new google.maps.Map2(document.getElementById("map"));
	bounds = new GLatLngBounds();
	map.addControl(new GSmallMapControl());		
//	map.addControl(new GMapTypeControl());	
	map.addMapType(G_PHYSICAL_MAP);
	map.setMapType(G_PHYSICAL_MAP);

	G_PHYSICAL_MAP.getMinimumResolution=function() {
	  return 3;
	
	};
	
	G_PHYSICAL_MAP.getMaximumResolution=function() {
	  return 7;
	
	}; 

	map.setCenter(new google.maps.LatLng(39.268552,-98.261719), 3);
	map.disableDoubleClickZoom();
	swlat = 55.3140
	swlng = -131.772;
	nelat = 55.3886;
	nelng= -131.6186;
		 
	boundaries = new GLatLngBounds(new GLatLng(swlat,swlng), new GLatLng(nelat,nelng));
	//centerAndZoomOnBounds(bounds);
	clickItem(0);
	
	fooResize();
	
	
	
}


function clickItem(id){
	map.clearOverlays();
	
	
	
}





function displayMarkersOnMap(arr){
	//pre: arr contains markers
	//post: markers added to map
	
	for(var id in arr){
		var m = arr[id];
		addMarkerToMap(m);
	}
	
	
}



function centerAndZoomOnBounds(bounds) { //function for centering map around all markers
	var center = bounds.getCenter();
	var newZoom = map.getBoundsZoomLevel(bounds);
	if (map.getZoom() != newZoom) {
	
		map.setCenter(center, newZoom);
	} else {
		map.panTo(center);
	}
} 




function createMarker(arr, lati, longi, id, text, iconi, param){
	//pre: m is an array that contains these things:
	//latitude, longitude
	//optional: icon
	//optional: text is what should be in the popup box
	//optional: extra parameters
	//post: A new marker added to the passed in arr
	
	
	iconi = !isEmpty(iconi) ? iconi : google.maps.G_DEFAULT_ICON;



	var pt = new google.maps.LatLng(lati, longi);
	var m = new GMarker( pt, iconi);
	m.id = id;//;lati+"_"+longi;
	m.txt = "<div class='popupWindow'>"+text+"</div>"; 
	
	function gotoPoint(){
	
		clickPoint(m.id);
	}
	

	GEvent.addListener(m, 'click', gotoPoint);	

	arr[m.id] = m;
	
	return m;
	
}

function addMarkerToMap(m){

	map.addOverlay(m);
	bounds.extend(m.getLatLng());	

}

function clickPoint(id){
	//what happens when you click on a marker or want to goto a marker
	
	
	var m = arrMarkers[id];
	map.panTo(m.getLatLng());
	
	if(!isEmpty(m.txt)){
		m.openInfoWindowHtml(m.txt);
	}
	
	//trace(id);
}




function resetMap(){

	
	arrMarkers = new Array();
	map.clearOverlays();
	
}
