	// www.obares.com google api key: 
	/*     <script src="http://maps.google.com/maps?file=api&v=1&key ABQIAAAAMxoFb1RFV2TJrczF2v09ZRTyqfFO5YoODLF4EzRaH5RLaqcdQRTZA20oXgbStcwqzo4KyyRhV0uuSw" type="text/javascript"></script>
	*/

    //<![CDATA[

/**
* Function to emulate document.getElementById
*
* @param	string	Object ID
*
* @return	mixed	null if not found, object if found
*/
function fetch_object(idname)
{
	if (document.getElementById)
	{
		return document.getElementById(idname);
	}
	else if (document.all)
	{
		return document.all[idname];
	}
	else if (document.layers)
	{
		return document.layers[idname];
	}
	else
	{
		return null;
	}
}
var msgvis = false;
function test(id)
{

	e = fetch_object(id);
    if ( true || e.style.visibility == 'visible')
    {
	    var leftpx  = e.offsetLeft;
	    var toppx   = e.offsetTop;
	    var rightpx = e.offsetWidth;
        var heightpx = e.offsetHeight;
		var msg = id + ": " + toppx + ", " + leftpx + ", " + rightpx + ", " + heightpx;
		mel = fetch_object('msgbox');
		if( ! msgvis ){
			msgvis = true;
			mel.style.display = ""; // show msg box
		}
//		e.style.border = "1px solid #00F";
		e.style.backgroundColor = '#eee';// = '#f00';
		mel.innerHTML = msg;
		window.status = msg;
		//alert(msg);
	}
}

	// Create a marker whose info window displays the given number.
	function createMarker(point, text) {
	  var marker = new GMarker(point);
	  // Show this marker's index in the info window when it is clicked.
	  var html = "<div style=' font:Arial; font-size:9pt;'>" + text + "<\/div>";
	  GEvent.addListener(marker, 'click', function() {
		marker.openInfoWindowHtml(html);
	  });
	
	  return marker;
	}

	var apartments = new Array();
	var agents = new Array();
	
	var gp = new GPoint(-94.04296875, 43.58039085560784);
	MyZoomTo = gp;	// make it global on purpose
	
    var map = new GMap(document.getElementById("map"));
    var gMarkers =  new Array();
	var aptmap = null;
	var agentmap = null;

//	GLog.write("Google Maps Initd");	
	
	map.addControl(new GSmallMapControl());
	//map.addControl(new GLargeMapControl() );
	//map.addControl(new GMapTypeControl());
	
    //map.centerAndZoom(gp, 14);

	//map.addOverlay( createMarker(gp, "Some Point"));

	GEvent.addListener(map, 'click', function(overlay, point) {
	  if (overlay) {
		//map.openInfoWindow(gp,
		//		   document.createTextNode("Phoenicia, NY"));
	  } else if (point) {
		//alert(map.getCenterLatLng());
		//map.addOverlay(new GMarker(point));
	  }
	});

	// helper function to add a pub to the map
	function add_loc(x, y, popupid, mapvar, theicon) {
		//alert(popupid);
		if(theicon == null)
			theicon = bluePin;
		marker = new GMarker(new GPoint(x, y), theicon);
		marker.popupid = popupid; // register ID on object for later

		gMarkers.push(marker);

		if( mapvar == null )
			mapvar = map;
		// register an event handler to open the window on click
/*		marker.zoomer = function() {
			alert(marker);
			mapvar.showMapBlowup(marker.point, 2);
			};
*/
		GEvent.addListener(marker, 'click', marker_clicked);
		
		mapvar.addOverlay(marker);
	}
	
	// event handler; opens info window for marker
	function marker_clicked(marker) {
		// retrieve the element to show in the window
		element = document.getElementById(marker.popupid);
		// we can't pass this element in because it gets destroyed
		// once the window is closed, so we make a copy
		element = element.cloneNode(true); 
		
		element.className = "gmap-marker"; // change style of paragraph element

		// hide the "Map Location" anchor in the block
		anchors = element.getElementsByTagName('a');
		if( anchors )
			anchors[0].style.visibility = "hidden";
		element.style.display = "";		// switch display from off to on
		//element.innerHTML = "<span style='color:red;text-decoration:underline;font-size:12px;'>Apartment Listings</span><br />" + element.innerHTML;
		element.innerHTML += "<br /><a onClick='javascript:alert(\"No, Not yet!\");return false;'>Zoom In</a>";
		// then open the window
		//marker.map.showMapBlowup(marker.point, 2); // shows detailed map in popup
		marker.map.openInfoWindow(marker.point, element);
	}
	
	
	/**
	 * shop_apt_map()
	 */
	function show_apt_map(showHide){
		if( showHide == null )
			showHide="toggle";

		var el = document.getElementById("apt-map");
		if( el == null ){
			alert("apartment map element not found");
			return;
		}
		if( el.style.display == "" ){
			if( showHide == "hide" || showHide == "toggle"){
				el.style.display = "none";
				document.getElementById('apt-map-btn').innerHTML = "Show Map";
			}
		}else{
			if( showHide == "show" || showHide == "toggle"){
				el.style.display = "";
				
				if( aptmap == null ){
					aptmap = new GMap(el);
					aptmap.centerAndZoom(gp, MyZoomTo);
					for(var i=0; i<apartments.length; i++){
						var items = apartments[i].split(',');
						add_loc(items[0],items[1],eval("'" + items[2] + "'"), aptmap, redPin );
					}
					aptmap.addControl(new GLargeMapControl());
				}
				document.getElementById('apt-map-btn').innerHTML = "Hide Map";
			}
		}
	}

	function show_agents_map(showHide){
		if( showHide == null )
			showHide="toggle";
		var el = document.getElementById("agent-map");
		if( el == null ){
			alert("re agents map element not found");
			return;
		}
		if( el.style.display == "" ){
			if( showHide == "hide" || showHide == "toggle"){
				el.style.display = "none";
				document.getElementById('agent-map-btn').innerHTML = "Show Map";
			}
		}else{
			if( showHide == "show" || showHide == "toggle"){
				el.style.display = "";
				if( agentmap == null ){
					agentmap = new GMap(el);
					agentmap.centerAndZoom(gp, MyZoomTo);
					for(var i=0; i<agents.length; i++){
						var items = agents[i].split(',');
						add_loc(items[0],items[1],eval("'" + items[2] + "'"), agentmap, bluePin );
					}
					agentmap.addControl(new GLargeMapControl());				
				}
				document.getElementById('agent-map-btn').innerHTML = "Hide Map";
			}
		}
	}


	// Create a base icon for all of our markers that specifies the
	// shadow, icon dimensions, etc.
	var baseIcon = new GIcon();
	baseIcon.shadow = "http://www.obares.com/images/gmaps_markers/mm_20_shadow.png";
	baseIcon.iconSize = new GSize(12, 20);
	baseIcon.shadowSize = new GSize(22, 20);
	baseIcon.iconAnchor = new GPoint(6, 20);
	baseIcon.infoWindowAnchor = new GPoint(5, 1);
	baseIcon.infoShadowAnchor = new GPoint(18, 25);
	
	var bluePin = new GIcon(baseIcon);
	bluePin.image = "http://www.obares.com/images/gmaps_markers/mm_20_blue.png";
	var redPin = new GIcon(baseIcon);
	redPin.image = "http://www.obares.com/images/gmaps_markers/mm_20_red.png";
	var greenPin = new GIcon(baseIcon);
	greenPin.image = "http://www.obares.com/images/gmaps_markers/mm_20_green.png";
	var yellowPin = new GIcon(baseIcon);
	yellowPin.image = "http://www.obares.com/images/gmaps_markers/mm_20_yellow.png";
	var blackPin = new GIcon(baseIcon);
	blackPin.image = "http://www.obares.com/images/gmaps_markers/mm_20_black.png";

	function show_props(obj, objName) {
		var result = "";
		for (var i in obj) {
			result += objName + "." + i + " = " + obj[i] + "\n";
		}
		return result;
	}
	function findMarker(id){
		for (var i=0; i<gMarkers.length; i++) {
			if( gMarkers[i].popupid == id )
				return gMarkers[i];
		}
		return null;
	}
	
	function displayMarker(id, map){
		if( map == "apt" )
			show_apt_map("show");
		else{
			show_agents_map("show");
			//mapobj = fetch_object("agent-map");
			//rsrc  = fetch_object(id);
			//msg("Map Coords: " + mapobj.offsetTop + ", " + mapobj.offsetLeft);
			//mapobj.style.top = rsrc.offsetTop + 80 + "px"; //rsrc.offsetTop + rsrc.heightpx + 10;
			//mapobj.style.left = "10px";
		}
		var m = findMarker(id);
		if( m ){
			marker_clicked(m);
		}else{
			alert("Sorry, unable to finder resource ID " + id + " on the map.");
		}
	}
	
	function msg($str){
		fetch_object('msgbox').innerHTML = $str;
	}
	//]]>
