/*

    call setupGetOverlays(map) to add these methods to the map:
        map.getOverlays()
        map.removeOverlays(overlaysToRemove?) -- call this instead of clearOverlays()
        map.addOverlays(overlaysArray)

    overlays which are added to the map and have an _ignoreOverlay property are ignored by these methods
        this can be useful if you have overlays like a map singleton tooltip which you don't ever want to 
            manipulate with the rest of the overlays

0.1  - initial version
0.11 - removeOverlays()
          this calls removeOverlay for each overlay, and also optionally takes an array of
          overlays to remove instead of this.getOverlays()
       addOverlays(overlays)
       don't add the infoWindow to the overlays array

todo:
  test removeOverlays()
  test addOverlays()

*/
function setupGetOverlays(map) {
    if(typeof(map.getOverlays) == 'function')
        return;

    map.__overlays = {};
    map.__nextOverlayId = 1;

    GEvent.addListener(map,'addoverlay',function(o) {
        // it's the infoWindow
        if(typeof(o.getContentContainers) == 'function' || o._ignoreOverlay)
            return;

        if(typeof(o._id) == 'undefined')
            o._id = this.__nextOverlayId++;

        this.__overlays[o._id] = o;
	});

	GEvent.addListener(map,'removeoverlay',function(o) {
    if(typeof(o._id) == 'undefined')
      return;
    
		delete this.__overlays[o._id];
	});

	GEvent.addListener(map,'clearoverlays',function() {
		this.__overlays = {};
	});

	map.getOverlays = function() {
		var a = new Array();
		for(var prop in this.__overlays)
			a.push(this.__overlays[prop]);
		return a;
	};

  map.removeOverlays = function(o) {
    if(typeof(o) != 'object')
      o = this.getOverlays();
    for(var i = 0; i < o.length; i++)
      this.removeOverlay(o[i]);
  };

  map.addOverlays = function(o) {
    for(var i = 0; i < o.length; i++)
      this.addOverlay(o[i]);
  };
}
setupGetOverlays.version = 0.1;

