var HoverGrid = Class.create();
HoverGrid.center = 0;
HoverGrid.top = -1;
HoverGrid.bottom = 1;
HoverGrid.left = -1;
HoverGrid.right = 1;

HoverGrid.prototype = {
  initialize: function(width, height) {
    this.width = width;
    this.height = height;
  },

  directionFrom: function(point) {
    var location = this._locationOf(point);
    if(location.equals(HoverGridLocation.deadCenter)) {
      return HoverGridLocation.rightOfCenter;
    }
    return location.transposed();
  },

  _locationOf: function(point) {
    return new HoverGridLocation(
      this._orientationOf(this.width, point.x),
      this._orientationOf(this.height, point.y)
    );
  },

  _orientationOf: function(whole, part) {
    var segment = (whole / 3);
    return parseInt(part / segment) - 1;
  }
};

var HoverGridLocation = Class.create();
HoverGridLocation.prototype = {
  initialize: function(x, y) {
    this.x = x;
    this.y = y;
  },

  transposed: function() {
    return new HoverGridLocation(
      this.x * -1,
      this.y * -1
    );
  },

  toHash: function() {
    return {x: this.x, y: this.y};
  },

  equals: function(other) {
    return this.x == other.x && this.y == other.y;
  }
};

HoverGridLocation.deadCenter = new HoverGridLocation(HoverGrid.center, HoverGrid.center);
HoverGridLocation.rightOfCenter = new HoverGridLocation(HoverGrid.right, HoverGrid.center);