 var directions;
 var directionsPanel;
     
function initialize() {
    if ($('map_canvas')==null){
    return;
    }
    var map = new GMap2(document.getElementById("map_canvas"));
//    directionsPanel = document.getElementById("directions");
     
//    initalizeDirection(map);
    addControls(map);
    var latitude = $('latitude').value;
    var longitude = $('longitude').value;
    map.setCenter(new GLatLng(latitude, longitude), 15);
    addMarkerPoint(map,latitude,longitude);
}
//Initalize the direction definer
function initalizeDirection(map){
    directions = new GDirections(map, directionsPanel);
    GEvent.addListener(directions, "error", handleErrors);
}
     
// bind a search control to the map, suppress result list
function searchBar(map){
    map.addControl(new google.maps.LocalSearch(), new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(10,20)));
} 
     
//Add necessary controls
function addControls(map){
    var mapTypeControl = new GMapTypeControl();
    map.addControl(mapTypeControl);
    var mapLargeControl = new GLargeMapControl();
    map.addControl(mapLargeControl);
}

//Add marker points
function addMarkerPoint(map,latitude,longitude){
    var point = new GLatLng(latitude, longitude);
    var marker = new GMarker(point, {draggable: false});

    map.addOverlay(marker);
}
     
function handleErrors(){
    if (directions.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
 alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + directions.getStatus().code);
    else if (directions.getStatus().code == G_GEO_SERVER_ERROR)
 alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + directions.getStatus().code);
     
    else if (directions.getStatus().code == G_GEO_MISSING_QUERY)
 alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + directions.getStatus().code);
     
    else if (directions.getStatus().code == G_GEO_BAD_KEY)
 alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + directions.getStatus().code);
     
    else if (directions.getStatus().code == G_GEO_BAD_REQUEST)
 alert("A directions request could not be successfully parsed.\n Error code: " + directions.getStatus().code);
     
    else alert("An unknown error occurred.");
     
}

