/*
Copyright 2005-2007 James Tolley - http://www.bitperfect.com | http://www.gmaptools.com
All rights reserved.
This software is released under the LGPL. (http://www.opensource.org/licenses/lgpl-license.php)
	
Usage:

//load the script:
<script src="js/getMarkers0.1.js">

//setup the method for a given map:
setupGetMarkers(map);
*/

function setupGetMarkers(map) {
	if(typeof(map.getMarkers) == 'function')
		return;

	setupGetOverlays(map);
	map.getMarkers = function() {
		var o = this.getOverlays();
		var m = [];
		for(var i = 0; i < o.length; i++)
			if(typeof(o[i].getIcon) == 'function')
				m.push(o[i]);
		return m;
	};

	map.getPolylines = function() {
		var o = this.getOverlays();
		var m = [];
		for(var i = 0; i < o.length; i++)
			if(typeof(o[i].getVertex) == 'function')
				m.push(o[i]);
		return m;
	};

  // id is the id given to this marker, accessed as overlay._id
  // if field is present, then the first marker passing "marker.getUserData()[field] == id" is returned
  // if attr is present, then it's used instead of getUserData like so: "marker[attr][field] == id"
  map.getMarkerById = function(id,field,attr){
    var o = this.getMarkers();
    for (var i = 0; i < o.length; i++) {
      if (arguments.length > 1) {
        if (arguments.length > 2) {
          if (o[i][attr] && o[i][attr][field] == id)
            return o[i];
        }
        else {
          if (o[i].getUserData()[field] == id)
            return o[i];
        }
      }
      else { // find it by the id
        if (o[i]._id == id)
          return o[i];
      }
    }
  };
}
setupGetMarkers.version = 0.11;
