function Line( map, marker, end, speed, finishFunction ) {
  this.map = map;
  this.marker = marker;
  this.start = this.marker.getPoint();
  this.end = end;
  this.speed = speed;
  this.finishFunction = finishFunction;
  this.iterations = 0;
  this.continueMoving = true;

  this.run = function run() {
    this.currentCenter = this.start;
    this.initCalc();
    //this.endMarker = new GMarker( this.end );
    //this.map.addOverlay( this.endMarker );
    //this.endMarker.openInfoWindow( document.createTextNode( this.end ) );
    this.move();
  };

  this.pauseButton = function pauseButton() {
    if ( this.continueMoving ) {
      this.continueMoving = false;
    } else {
      this.continueMoving = true;
      this.move();
    }
  }

  this.move = function move() {
    this.calc();
    this.nextPoint();
    if ( this.iterations % 5 == 0 ) {
      this.marker.setPoint( this.currentCenter );
    }
    map.panTo( this.currentCenter );

    if ( this.continueMoving ) {
      var self = this;
      setTimeout( function() { self.move(); }, 200 );
    } else if ( this.finished ) {
      //this.map.removeOverlay( this.endMarker );
      this.finishFunction();
    }
  };

  this.nextPoint = function nextPoint() {
    this.iterations++;
    if ( this.hypotenuse < this.distancePerMove ) {
      this.currentCenter = this.end;
      this.marker.setPoint( this.currentCenter );
      this.continueMoving = false;
      this.finished = true;
    } else {
      this.currentCenter = new GLatLng(
        this.currentCenter.lat() + ((this.verDir * this.vertical * this.speed) / this.hypotenuse),
        this.currentCenter.lng() + ((this.horDir * this.horizontal * this.speed) / this.hypotenuse)
      );
    }
  }

  this.findDirection = function findDirection( startCoord, endCoord ) {
    if ( endCoord >= startCoord ) {
      return 1;
    } else {
      return -1;
    }
  }

  this.initCalc = function initCalc() {
    this.verDir = this.findDirection( this.start.lat(), this.end.lat() );
    this.horDir = this.findDirection( this.start.lng(), this.end.lng() );
    this.distancePerMove = this.end.distanceFrom( new GLatLng( this.end.lat() + this.speed, this.end.lng() ) );
  }

  this.calc = function calc() {
    this.horizontal = this.currentCenter.distanceFrom( new GLatLng( this.currentCenter.lat(), this.end.lng() ) );
    this.vertical = this.currentCenter.distanceFrom( new GLatLng( this.end.lat(), this.currentCenter.lng() ) );
    this.hypotenuse = this.currentCenter.distanceFrom( this.end );
  };
}

