var map;
var icon0;
var newpoints = new Array();
 
function addLoadEvent(func) { 
	var oldonload = window.onload; 
	if (typeof window.onload != 'function'){ 
		window.onload = func
	} else { 
		window.onload = function() {
			oldonload();
			func();
		}
	}
}
 
addLoadEvent(loadMap);
addLoadEvent(addPoints);
 
function loadMap() {
	map = new GMap2(document.getElementById("map"));
	map.addControl(new GLargeMapControl());
	map.addControl(new GMapTypeControl());
	map.setCenter(new GLatLng( 38.846459529581786, -77.11522579193115), 15);
	map.setMapType(G_MAP_TYPE);
 
	icon0 = new GIcon();
	icon0.image = "http://www.google.com/mapfiles/marker.png";
	icon0.shadow = "http://www.google.com/mapfiles/shadow50.png";
	icon0.iconSize = new GSize(20, 34);
	icon0.shadowSize = new GSize(37, 34);
	icon0.iconAnchor = new GPoint(9, 34);
	icon0.infoWindowAnchor = new GPoint(9, 2);
	icon0.infoShadowAnchor = new GPoint(18, 25);

        icon1 = new GIcon();
        icon1.image = "http://www.google.com/mapfiles/marker.png";
        icon1.shadow = "http://www.google.com/mapfiles/shadow50.png";
        icon1.iconSize = new GSize(20, 34);
        icon1.shadowSize = new GSize(37, 34);
        icon1.iconAnchor = new GPoint(9, 34);
        icon1.infoWindowAnchor = new GPoint(9, 2);
        icon1.infoShadowAnchor = new GPoint(18, 25);

}
 
function addPoints() {
 
	newpoints[0] = new Array(38.846088, -77.115770, icon0, 'IRAC', 'Immigrant &amp; Refugee Appellate Center<br />3602 Forest Drive<br />Alexandria, Virginia 22302'); 
	newpoints[1] = new Array(38.846088, -77.115720, icon1, 'BIA', 'Immigrant &amp; Refugee Appellate Center<br />3602 Forest Drive<br />Alexandria, Virginia 22302'); 
 
	for(var i = 0; i < newpoints.length; i++) {
		var point = new GPoint(newpoints[i][1],newpoints[i][0]);
		var popuphtml = newpoints[i][4] ;
		var marker = createMarker(point,newpoints[i][2],popuphtml);
		map.addOverlay(marker);
	}
}
 
function createMarker(point, icon, popuphtml) {
	var popuphtml = "<div id=\"popup\">" + popuphtml + "<\/div>";
	var marker = new GMarker(point, icon);
	GEvent.addListener(marker, function() {
		marker.openInfoWindowHtml(popuphtml);
	});
	return marker;
}
