//<![CDATA[

var map = null;
var geocoder = null;
var firstTime = true;

$(document).ready( function() { 
		
	$("#state").change( function() { 
		
		//retrieve value of state selected from drop down menu
		var i = $(this).val();
		
		//on first click of drop down menu remove fake map and load real map
		if (firstTime && i!='') {
			$("#map").html("");
			initMap();
			firstTime = false;
		}
		
		//load up marker and info bubble for correct state
		if (i!='') { 
			clearMap();
			var arrLatLng = $("#d_"+i).attr("title").split("|");
			var html = $("#d_"+i).html();
			pinAddress(arrLatLng[0], arrLatLng[1], html);
		};

	});

	$("#reset").click( function() {
		$("#map").html('<img src="/gfx/map.gif" alt="Map" />');
		firstTime = true;
	});

});

/* ---------------------------------------------------------------------------- */

function clearMap() {
	map.clearOverlays();	
}

/* ---------------------------------------------------------------------------- */

function initMap() {	
	if (GBrowserIsCompatible()) {
		
		map = new GMap2(document.getElementById("map"));
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		
	}
}

/* ---------------------------------------------------------------------------- */


function pinAddress(lat, lng, address) {
	
	var loc = new GLatLng(lat, lng);
	var marker = new GMarker(loc);
	
	map.setCenter(loc, 4);
	map.addOverlay(marker);
	marker.openInfoWindowHtml(address);  
		
}
//]]>