var directionsPanel = $("direction_text");
var directions;

// Apparently, we need to wait for the directions to come back from google with the summary
function populateSummary() {
  setTimeout(function() {
    $("route_summary").innerHTML = directions.getSummaryHtml();
  }, 1500)
  setTimeout(markerAToFront, 6000);
}

function loadDirections(_directions) {
  directions = new GDirections(map, directionsPanel);
  directions.loadFromWaypoints(_directions);
  populateSummary();
}

function markerAToFront() {
  var images = $("direction_text").select("img");
  images.last().src = images.first().src;
  
  images = [];
  $$("img.gmnoprint").each(function(img) {
    if (img.src.match(/marker_green\w\.png/)) images.push(img);
  });
  images.last().src = images.first().src;
}