/*
 * Extended functions for GMap2
 */


GLatLngBounds.prototype.getArea = function() { 
  var ne = this.getNorthEast();
  var sw = this.getSouthWest();
  var se = new GLatLng(sw.lat(),ne.lng());
  var nw = new GLatLng(ne.lat(),sw.lng());
  var p = new GPolygon([ne,se,sw,nw,ne]);
  return p.getArea();
};


GLatLngBounds.prototype.getOverlapBounds = function(that) { 
  if( !this.intersects(that) ) { 
    return null;
  }
  /* 
   * NB: invalid when crossing the dateline
   */
  var n = Math.min(this.getNorthEast().lat(),that.getNorthEast().lat());
  var e = Math.min(this.getNorthEast().lng(),that.getNorthEast().lng());
  var s = Math.max(this.getSouthWest().lat(),that.getSouthWest().lat());
  var w = Math.max(this.getSouthWest().lng(),that.getSouthWest().lng());
  return new GLatLngBounds(new GLatLng(s,w),new GLatLng(n,e));
};


GMap2.prototype.getContainerOffset = function() { 
  var cl = 0;
  var ct = 0;
  var obj = this.getContainer();

  if( obj.offsetParent ) { 
    while( obj.offsetParent ) { 
      cl += obj.offsetLeft;
      ct += obj.offsetTop;
      obj = obj.offsetParent;
    }
  } else if( obj.x || obj.y ) { 
    cl += obj.x;
    ct += obj.y;
  }
  return new GPoint(cl,ct);
};
