function Journey( map, firstPoint, legs ) {
  this.map = map;
  this.firstPoint = firstPoint;
  this.legs = legs;

  this.run = function run() {
    this.currentLeg = 0;
    this.marker = new GMarker( this.firstPoint );
    var self = this;
    this.map.addOverlay( this.marker );
    this.nextLeg();
  };

  this.pauseButton = function pauseButton() {
    this.leg.pauseButton();
  }

  this.nextLeg = function nextLeg() {
    if ( this.currentLeg < this.legs.length ) {
      var self = this;
      this.leg = new Leg(
        this.map,
        this.marker,
        this.legs[this.currentLeg]['points'],
        this.legs[this.currentLeg]['message'],
        function() { self.nextLeg(); }
      );
      this.leg.run();
      this.currentLeg++;
    } else {
    }
  }
}

function JourneyControl( journey ) {
  this.journey = journey;
}
JourneyControl.prototype = new GControl();

JourneyControl.prototype.initialize = function( map ) {
  var container = document.createElement( "div" );

  var pauseDiv = document.createElement( "div" );
  this.setButtonStyle_( pauseDiv );
  container.appendChild( pauseDiv );
  pauseDiv.appendChild( document.createTextNode( "Pause" ) );
  var self = this;
  GEvent.addDomListener( pauseDiv, "click", function() {
    self.journey.pauseButton();
  } );

  map.getContainer().appendChild( container );
  return container;
}

JourneyControl.prototype.getDefaultPosition = function() {
  return new GControlPosition( G_ANCHOR_TOP_RIGHT, new GSize( 7, 7 ) );
}

JourneyControl.prototype.setButtonStyle_ = function( button ) {
  button.style.textDecoration = "underline";
  button.style.color = "#0000cc";
  button.style.backgroundColor = "white";
  button.style.font = "small Arial";
  button.style.border = "1px solid black";
  button.style.padding = "2px";
  button.style.marginBottom = "3px";
  button.style.textAlign = "center";
  button.style.width = "6em";
  button.style.cursor = "pointer";
}

