var address = "66 Old Princes Highway, Beaconsfield, Victoria 3807";

var geocoder;
var directions;
var firstload = 0;
var arrResults;
var marker;
var infowindow;
var map;
var directionDisplay;
var directionsService;

function initialize() {
	directionsService = new google.maps.DirectionsService();
	directionsDisplay = new google.maps.DirectionsRenderer();
	var myOptions = {
		zoom: 16,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	};
	
	map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);		
	
	geocoder = new google.maps.Geocoder();
	geocoder.geocode({'address':address},function (results, status)	{
		if (status == google.maps.GeocoderStatus.OK) {
			map.setCenter(results[0].geometry.location);
			marker = new google.maps.Marker({
				map: map, 
				animation: google.maps.Animation.DROP,
				position: results[0].geometry.location
			});
			google.maps.event.addListener(marker, 'click', toggleBounce);
			var contentString = "<div id='overlay' style='height:150px;width:250px;'><font style='font-weight:bold;font-size:14px;'>Database By Design</font><br><br>Office 1, Level 1<br>70 Old Princes Highway<br>Beaconsfield VIC 3807<br><br><span id='dirtohere' style='font-size:12px;'>Get Directions To: <a href=javascript:ShowToHere(0); >Database By Design</a></span><div id='tohere' style='visibility:hidden;font-size:small;line-height:normal;'><input id='txttohere' type='text' style='border:1px #000000 inset;width:80%;vertical-align:top;'/><div style='display:inline;margin:0.5em 0 0 0.1em;padding:0;'><input type='button' style='border:2px #000000 outset;width:15%;' id='btntohere' onclick='fnToHere()' value='Go'></div><div><a href=javascript:ShowToHere(1); style='color:#7777CC;font-size:0.85em;'>&laquo; Back</a></div></div></div>";
			infowindow = new google.maps.InfoWindow({
				content: contentString
			});
			infowindow.open(map,marker);
			directionsDisplay.setMap(map);
		}	
		else {
			alert("Geocode was not successful for the following reason: " + status);
		}
	});
}
function toggleBounce() {
  if (marker.getAnimation() != null) {
    marker.setAnimation(null);
	infowindow.open(map,marker);
  } else {
    marker.setAnimation(google.maps.Animation.BOUNCE);
	infowindow.close();
  }
}
function ShowToHere(intVar)	{
	if (intVar == 0)	{
		document.getElementById("tohere").style.visibility = "visible";
		document.getElementById("dirtohere").innerHTML = "Get Directions To: <font style=\'font-weight:bold;\'>Database By Design</font>";
	}
	else if (intVar == 1)	{
		document.getElementById("tohere").style.visibility = "hidden";
		document.getElementById("dirtohere").innerHTML = "Get Directions To: <a href=javascript:ShowToHere(0); >Database By Design</a>";
	}
}
function fnToHere()	{
	if (firstload == 0)	{
		firstload = 1;
	}
	var txtAdd = document.getElementById("txttohere").value;
	if (txtAdd != "")	{
		calcRoute();
		infowindow.close();
		document.getElementById("tohere").style.visibility = "hidden";
		document.getElementById("dirtohere").innerHTML = "Get Directions To: <a href=javascript:ShowToHere(0); >Database By Design</a>";
	}	
}
function calcRoute() {
  var start = document.getElementById("txttohere").value;
  var end = "70 Old Princes Highway, Beaconsfield, Victoria 3807";
  var request = {
    origin:start, 
    destination:end,
    travelMode: google.maps.DirectionsTravelMode.DRIVING
  };
  directionsService.route(request, function(result, status) {
    if (status == google.maps.DirectionsStatus.OK) {
      directionsDisplay.setDirections(result);
    }
  });
}


















