//<![CDATA[

    function displayMap(lt,lng,destAddr,firstdivtitle,firstdivcontent)
    {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));
        map.setCenter(new GLatLng(lt,lng),11);
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        map.addControl(new GOverviewMapControl());
        
        // Our info window content
		var infoTabs = 
		[
			new GInfoWindowTab(firstdivtitle,firstdivcontent), 
			new GInfoWindowTab('Directions', '<form action=\'#\' onsubmit=\'setDirections(this.from.value,"'+destAddr+'");return false;\'><table class="mapform" width=\'300px\'><tr><td align=\'center\'>From:</td></tr><tr><td><input type=\'text\' size=\'50\' id=\'fromAddress\' name=\'from\' value=\'\'/><br><small><I>StreetAddress&nbsp;&nbsp;&nbsp;Zip</I></small></td></tr><tr><td align=\'center\'><input name=\'submit\' type=\'submit\' value=\'Get Directions!\' /></td></tr></table></form>')
		];

	// Place a custom marker in the center of the map
//	var icon = new GIcon();
//	icon.image =  "http://images.harmonhomes.com/img/11/design/clean-hh_II/pages/listing-detail/map/map_marker_image.gif";
//	icon.shadow = "http://images.harmonhomes.com/img/11/design/clean-hh_II/pages/listing-detail/map/map_marker_shadow.gif";
//	icon.iconAnchor = new GPoint(7,50);
//	icon.infoWindowAnchor = new GPoint(30,7)
//	icon.iconSize = new GSize(35,50);
//	icon.shadowSize = new GSize(45,50);

//		http://groups.google.com/group/Google-Maps-API/browse_thread/thread/89fca71d820dc77f


	var marker = new GMarker(map.getCenter());
	GEvent.addListener(marker, "click", function() 
	{
	 	marker.openInfoWindowTabsHtml(infoTabs,{maxWidth:200});
	});
	map.addOverlay(marker);
	marker.openInfoWindowTabsHtml(infoTabs,{maxWidth:300});
    }
    }

    function setDirections(fromAddr,destAddr)
    {
// A BackButtonControl is a GControl that displays textual "Back to Map" button
		function BackButtonControl()
		{
		}
		BackButtonControl.prototype = new GControl();
		
		// Creates a  DIV for the button and place it in a container
		// DIV which is returned as our control element. We add the control to
		// to the map container and return the element for the map class to
		// position properly.
		BackButtonControl.prototype.initialize = function(map)
		{
		  var container = document.createElement("div");
		
		  var backButton = document.createElement("div");
		  this.setButtonStyle_(backButton);
		  container.appendChild(backButton);
		  backButton.appendChild(document.createTextNode("Back to Map"));
		  GEvent.addDomListener(backButton, "click", function() {
		   mapGoBack();
		  });
		
		  map.getContainer().appendChild(container);
		  return container;
		}
		
		// By default, the control will appear in the top left corner of the
		// map with 7 pixels of padding.
		BackButtonControl.prototype.getDefaultPosition = function()
		{
		  return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(7, 7));
		}
		
		// Sets the proper CSS for the given button element.
		BackButtonControl.prototype.setButtonStyle_ = function(button)
		{
		  button.style.textDecoration = "underline";
		  button.style.color = "#000000";
		  button.style.backgroundColor = "white";
		  button.style.font = "small Arial";
		  button.style.border = "1px solid black";
		  button.style.padding = "3px";
		  button.style.marginBottom = "3px";
		  button.style.textAlign = "center";
		  button.style.width = "6em";
		  button.style.cursor = "pointer";
		}

    	
    	
    	
    	
    	toggle('map','map2');
    	var map2 = new GMap2(document.getElementById("map2"));
    	map2.addControl(new BackButtonControl());
        var directionsPanel = document.getElementById("dirs");
       if (directionsPanel.style.display == 'none')
        {
        	toggle('dirs');
        	document.getElementById("map2").style.marginTop = '-55px';
        }
        var directions = new GDirections(map2, directionsPanel);
        directions.load("from: " + fromAddr + " to: " + destAddr);
        GEvent.addListener(directions, "error", function() 
		{
			if(directionsPanel.style.display == 'none')
			{
				toggle('dirs');
			}
		 	directionsPanel.innerHTML = "<br/><br/><strong>I'm sorry, but we were unable to locate the address you entered.<br/>Please click the 'Back to Map' button on the left and try again.</strong><br/>You may enter your address in many formats, including:<br/><br/><I>123 Elm St. 23456<br/>123 Elm Street, Norfolk, VA 23518<br/>Norfolk, VA</I>";
		});
//		GEvent.addListener(directions, "addoverlay", function() 
//		{
//			if(document.getElementById('dirstop').style.display == 'none')
//			{
//				toggle('dirstop');
//			}
//		});
    }

    
function mapGoBack()
{
	document.getElementById('dirs').innerHTML = '';
	document.getElementById('map2').innerHTML = '';
	toggle('map2','map','dirs');
//	document.getElementById('dirstop').style.display = 'none';
}

function toggle()
{
	for(var i=0;i<toggle.arguments.length;i++)
	{
		if (toggle.arguments[i] == '')
		{
			continue;
		}
		elm = document.getElementById(toggle.arguments[i]);
		if (elm.style.display == "none")
		{
			elm.style.display = "";
		}
		else
		{
			elm.style.display = 'none';
		}
	}
}
    //]]>