function UsefulManager(map){
	this.map=map;
	this.leftbound=null;
	this.rightbound=null;
	this.upperbound=null;
	this.lowerbound=null;
	this.markers=Array();
	
	//==>Check to make sure that Array.pop() is available
	if(!Array.prototype.pop){
		Array.prototype.pop=function(){
			var result=this[this.length-1];
			delete(this[this.length-1]);
			this.length=this.length-1;
			return result;
		}
	}
}
	
//==>This function adds an array of markers to the map
UsefulManager.prototype.addMarkers=function(markerList){
	if(markerList.length>0){
		if(this.markers.length>0){
			this.markers=this.markers.concat(markerList);
		} else {
			this.markers=markerList;
		}
		for(var i in this.markers){
			var tmp=this.markers[i].getPoint();
			if(this.leftbound==null){
				//Initialize bounds
				this.leftbound=tmp.lng();
				this.rightbound=this.leftbound;
				this.upperbound=tmp.lat();
				this.lowerbound=this.upperbound;
			} else {
				//check bounds
				if(tmp.lng()<this.leftbound){
					this.leftbound=tmp.lng();
				} else {
					if(tmp.lng()>this.rightbound){
						this.rightbound=tmp.lng();
					}
				}

				if(tmp.lat()>this.upperbound){
					this.upperbound=tmp.lat();
				} else {
					if(tmp.lat()<this.lowerbound){
						this.lowerbound=tmp.lat();
					}
				}
			}
			//add marker to map
			this.map.addOverlay(this.markers[i]);
		}
	}
}

//==>Add markers to the managed array, but do not add them to the map
UsefulManager.prototype.manageMarkers=function(markerList){
	if(markerList.length>0){
		if(this.markers.length>0){
			this.markers=this.markers.concat(markerList);
		} else {
			this.markers=markerList;
		}
		for(var i in this.markers){
			var tmp=this.markers[i].getPoint();
			if(this.leftbound==null){
				//Initialize bounds
				this.leftbound=tmp.lng();
				this.rightbound=this.leftbound;
				this.upperbound=tmp.lat();
				this.lowerbound=this.upperbound;
			} else {
				//check bounds
				if(tmp.lng()<this.leftbound){
					this.leftbound=tmp.lng();
				} else {
					if(tmp.lng()>this.rightbound){
						this.rightbound=tmp.lng();
					}
				}

				if(tmp.lat()>this.upperbound){
					this.upperbound=tmp.lat();
				} else {
					if(tmp.lat()<this.lowerbound){
						this.lowerbound=tmp.lat();
					}
				}
			}
		}
	}
}

//==>This function removes all markers managed by this instance
UsefulManager.prototype.clearMarkers=function(){
	if(this.markers.length>0){
		while(this.markers.length>0){
			var mark=this.markers.pop();
			GEvent.clearListeners(mark,'click');
			this.map.removeOverlay(mark);
			delete mark;
		}
		delete this.markers;
		this.markers=Array();
	}
	delete this.leftbound;
	delete this.rightbound;
	delete this.upperbound;
	delete this.lowerbound;
	
	this.leftbound=null;
	this.rightbound=null;
	this.upperbound=null;
	this.lowerbound=null;
	this.map.closeInfoWindow();
}

//==>Replaces markers managed by this instance with the specified list
UsefulManager.prototype.replaceMarkers=function(markerList){
	this.clearMarkers();
	this.addMarkers(markerList);
}

//==>Adjust the map to view all of the markers
UsefulManager.prototype.viewAll=function(ctr){
	var sw=new GLatLng(this.lowerbound,this.leftbound);
	var ne=new GLatLng(this.upperbound,this.rightbound);
	var bnd=new GLatLngBounds(sw,ne);
	if(ctr!=null){
		if(!bnd.contains(ctr)){
			bnd.extend(ctr);
		}
	}

	ctr=bnd.getCenter();
	var zoom=this.map.getBoundsZoomLevel(bnd);
	this.map.setCenter(ctr,zoom);
}

//==>Retrieve the zoom level 
UsefulManager.prototype.getZoom=function(ctr){
	var sw=new GLatLng(this.lowerbound,this.leftbound);
	var ne=new GLatLng(this.upperbound,this.rightbound);
	var bnd=new GLatLngBounds(sw,ne);
	if(ctr!=null){
		if(!bnd.contains(ctr)){
			bnd.extend(ctr);
		}
	}
	return this.map.getBoundsZoomLevel(bnd);
}
