function showHide(showTab)
{
	var section = Array('video', 'profile', 'map');
	for(var i=0; i < section.length; i++ )
	{
		$('nav-'+section[i]).style.display = 'none';		// hide the old nav bar
		$('results-'+section[i]).style.display = 'none';	// hide the old results
	}	

	$('nav-'+showTab).style.display = 'block';	// show results
	$('results-'+showTab).style.display = 'block';	
}


function showHideMap(show,hide,lati,longi,destAddr,firstdivtitle,firstdivcontent)
{
	if (show == 'map')
	{
		var section = Array('video', 'profile', 'map');
		for(var i=0; i < section.length; i++ )
		{
			$('nav-'+section[i]).style.display = 'none';		// hide the old nav bar
			$('results-'+section[i]).style.display = 'none';	// hide the old results
		}
		
		$('nav-map').style.display = 'block';	// show results
		$('results-map').style.display = 'block';
		
		displayMap(lati,longi,destAddr,firstdivtitle,firstdivcontent);
	}
}

//<![CDATA[

    function displayMap(lt,lng,destAddr,firstdivtitle,firstdivcontent)
    {
		if (GBrowserIsCompatible()) 
      	{
	        var map = new GMap2(document.getElementById("map"));
	        map.setCenter(new GLatLng(lt,lng),13);
	        map.addControl(new GSmallMapControl());
	        map.addControl(new GMapTypeControl());
	        map.addControl(new GOverviewMapControl());
	        
	        // Our info window content
			var infoTabs = 
			[			
				new GInfoWindowTab('Directions', '<form action=\'#\' onsubmit=\'setDirections(this.from.value,"'+destAddr+'");return false;\'><div style="margin-top:20px;text-align:center;">From:<input type=\'text\' size=\'25\' id=\'fromAddress\' name=\'from\' value=\'\'/><br><small><i>Street Address,&nbsp;&nbsp;&nbsp;Zip Code</i></small><br><input name=\'submit\' type=\'submit\' value=\'Get Directions!\' /></form></div>')
			];
	
			// 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);
			var marker = new GMarker(map.getCenter(), icon);
			GEvent.addListener(marker, "click", function() 
			{
			 	marker.openInfoWindowTabsHtml(infoTabs,{maxWidth:300,maxheight:200});
			});
			map.addOverlay(marker);
			//marker.openInfoWindowTabsHtml(infoTabs);
    	}
    }

    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');
        }
        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/><br/>Please click the 'Back to Map' button on the left and try again.</strong><br/><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';
		}
	}
}
    //]]>

