/**
 * @author Mikhail Kozlov &copy; Shoreline Properties, Inc
 */
	var map = null;
	var geocoder = null;
	var addr = null;
	var temp;
    $("document").ready(function(){
		$(".ToHere").live("click", function(){
			toHere($(this).attr("title"));
			$("#gDirections").css("height","300px");
		});
	});
	function initialize() {
      if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("mapGoogle"));
        map.setCenter(new GLatLng(38.391526, -75.069712), 13);
        map.setUIToDefault();
      }
    }
	function showAddress(address,name,lat,long){
		point = new GLatLng(lat, long);
		var marker = new GMarker(point);
		map.setCenter(new GLatLng(38.391526, -75.069712), 13);					
		map.addOverlay(marker);
		addr = address.replace("<br />", "+");
		var links ="<div id=\"gDirections\" style=\"height:100px\"><br />Get directions: <a href=\"javascript:void(0);\" title=\""+name+"\" class=\"ToHere\" >To here</a> - <a href=\"javascript:fromHere('"+name+"')\">From here</a></div>";
		marker.openInfoWindowHtml("<h3>" + name + "</h3>" + address + "<br />" + links);
		GEvent.addListener(marker, "click", function(){
			marker.openInfoWindowHtml("<h3>" + name + "</h3>" + address + "<br />" + links);
		});
	}
	
	function toHere(name){
		$("form","#gDirections").remove();
		$("#gDirections br").remove();
		$("#gDirections b").replaceWith(temp);
		temp = $("#gDirections a:first");
		$("#gDirections a:first").replaceWith("<b>To here</b>");
 		$("#gDirections").append('<form action="/directions/"><input type="hidden" name="name" id="name" value="'+name+'" /><input type="hidden" name="daddr" id="daddr" value="'+addr+'" /><small>Start address</small><br /><input type="text" id="saddr" name="saddr"/><input type="submit" value="Go" /><br /><small><a href="javascript:dirCancel()"><< Back</a></small></form>');
	}
	function fromHere(name){
		$("form","#gDirections").remove();
		$("#gDirections br").remove();
		$("#gDirections b").replaceWith(temp);
		temp = $("#gDirections a:last");
		$("#gDirections a:last").replaceWith("<b>From here</b>");
		$("#gDirections").append('<form action="/directions/"><input type="hidden" name="name" id="name" value="'+name+'" /><input type="hidden" name="saddr" id="saddr" value="'+addr+'" /><small>End address</small><br /><input type="text" id="daddr" name="daddr"/><input type="submit" value="Go" /><br /><small><a href="javascript:dirCancel()"><< Back</a></small></form>');
	}
	function dirCancel(){
		$("#gDirections").prepend("<br />");
		$("#gDirections b").replaceWith(temp);
		temp=null;
		$("form","#gDirections").remove();
	}	
