function AMarkerManager(map){
	//properties
	this._map = arguments[0];

	this._itemMarkerManager= new MarkerManager(arguments[0], {borderPadding:UI_BORDERPADDING});		    //manager to display item markers
	this._countryMarkerManager = new MarkerManager(arguments[0], {borderPadding:UI_BORDERPADDING});		//manager to display country markers

	this._itemMarkerArray = new Array();			//array to keep track of bookable markers
	this._countryMarkerArray = new Array();			//array to keep track of country markers

	this._lastGeneratedId = 0;						//id generator
}

AMarkerManager.prototype.clearItemMarkers = function(){
	this._itemMarkerManager.clearMarkers();
	this._itemMarkerArray = new Array();
}

AMarkerManager.prototype.clearItemMarkersByType = function(type){
	for (i in this._itemMarkerArray){
		if (this._itemMarkerArray[i]._type == type){
			this._itemMarkerManager.removeMarker(this._itemMarkerArray[i]);
			var removed = this._itemMarkerArray.splice(i, 1);
		}
	}	
}

AMarkerManager.prototype.clearInvisibleItemMarkers = function(){
	for (i in this._itemMarkerArray){
		if (!map.getBounds().contains(this._itemMarkerArray[i].getPoint())){
			this._itemMarkerManager.removeMarker(this._itemMarkerArray[i]);
			var removed = this._itemMarkerArray.splice(i, 1);
		}
	}
}

//Function to add a marker to the manager. 
AMarkerManager.prototype.addMarker = function(marker, type){
	marker._type = type;
	
	switch(type){
		case MARKER_TYPE_CAMPING_BOOKABLE:
			this._addMarkerToItemManager(arguments[0], type);
		break;

		case MARKER_TYPE_CAMPING_NONBOOKABLE:
			this._addMarkerToItemManager(arguments[0], type);
		break;

		case MARKER_TYPE_BEDANDBREAKFAST_RESERVABLE:
			this._addMarkerToItemManager(arguments[0], type);
		break;

		case MARKER_TYPE_BEDANDBREAKFAST_NONRESERVABLE:
			this._addMarkerToItemManager(arguments[0], type);
		break;

		case MARKER_TYPE_COUNTRY:
			this._addMarkerToCountryManager(arguments[0]);		
		break;
		
		default:
			alert("Error: Marker is of unknown type and has been discarded");
		break;
	}
}

//Function to get array of markers (of a certain type);
AMarkerManager.prototype.getItemMarkerArray = function (){
	return this._itemMarkerArray;
}

AMarkerManager.prototype.getCountryMarkerArray = function(){
	return this._countryMarkerArray;
}

AMarkerManager.prototype.getMarkerById = function(markerId){
	var type = parseFloat((""+markerId).substr(0,1));
	var foundMarker = null;
	
	switch (type){
		case MARKER_TYPE_CAMPING_BOOKABLE:
			foundMarker = this._getMarkerByIdFromArray(markerId, this._itemMarkerArray);
		break;

		case MARKER_TYPE_CAMPING_NONBOOKABLE:
			foundMarker = this._getMarkerByIdFromArray(markerId, this._itemMarkerArray);
		break;

		case MARKER_TYPE_BEDANDBREAKFAST_RESERVABLE:
			foundMarker = this._getMarkerByIdFromArray(markerId, this._itemMarkerArray);
		break;

		case MARKER_TYPE_BEDANDBREAKFAST_NONRESERVABLE:
			foundMarker = this._getMarkerByIdFromArray(markerId, this._itemMarkerArray);
		break;

		case MARKER_TYPE_COUNTRY:	
			foundMarker = this._getMarkerByIdFromArray(markerId, this._countryMarkerArray);
		break;
	}

	return foundMarker;
}

//Function to get a marker by its id property from an array
AMarkerManager.prototype._getMarkerByIdFromArray = function(id, markerArray){
	var foundMarker = null;	
	
	for (i in markerArray){
		if (markerArray[i].id == id){
			foundMarker = markerArray[i];
		}
	}

	return foundMarker;
}

//Function to generate a marker id
AMarkerManager.prototype._generateMarkerId = function(){
	return this._lastGeneratedId++;
}

//Function to assign an id to a marker
AMarkerManager.prototype._setMarkerId = function(type, marker){
	marker.id = type + "" + this._generateMarkerId();
}

//Function to add a marker to the manager
AMarkerManager.prototype._addMarkerToItemManager = function(marker, type){
	//assign marker an id
	this._setMarkerId(type, arguments[0]);

	//add marker to the array
	this._itemMarkerArray.push(arguments[0]);

    //add marker to the manager
    if (marker._type == MARKER_TYPE_CAMPING_BOOKABLE){
    	this._itemMarkerManager.addMarker(arguments[0],CAMPING_BOOKABLE_MINZOOM,CAMPING_BOOKABLE_MAXZOOM);
    } else if (marker.type= MARKER_TYPE_CAMPING_NONBOOKABLE){
    	this._itemMarkerManager.addMarker(arguments[0],CAMPING_NONBOOKABLE_MINZOOM,CAMPING_NONBOOKABLE_MAXZOOM);
    } else if (marker._type == MARKER_TYPE_BEDANDBREAKFAST_RESERVABLE){
    	this._itemMarkerManager.addMarker(arguments[0],BEDANDBREAKFAST_RESERVABLE_MINZOOM,BEDANDBREAKFAST_RESERVABLE_MAXZOOM);
    } else if (marker.type= MARKER_TYPE_BEDANDBREAKFAST_NONRESERVABLE){
    	this._itemMarkerManager.addMarker(arguments[0],BEDANDBREAKFAST_NONRESERVABLE_MINZOOM,BEDANDBREAKFAST_NONRESERVABLE_MAXZOOM);
    }	
}

//Function to add a marker to the country manager
AMarkerManager.prototype._addMarkerToCountryManager = function(marker){
	//assign marker an id
	this._setMarkerId(MARKER_TYPE_COUNTRY, arguments[0]);

	//add marker to the array
	this._countryMarkerArray.push(arguments[0]);

	//add marker to the manager
	this._countryMarkerManager.addMarker(arguments[0],COUNTRY_MINZOOM,COUNTRY_MAXZOOM);
}
//Function that opens the info window of an camping marker
AMarkerManager.prototype.showMarkerInfo = function(markerId){
        this.getMarkerById(markerId).showInfo();
}

//Function to highlight a camping marker
AMarkerManager.prototype.highlightMarker = function(markerId){
	//temporarily store the marker object
        var marker = this.getMarkerById(markerId);

        //make the marker explode, increasing its size
        this.explodeMarker(marker);
}

//Function to explode a marker, increasing its size
AMarkerManager.prototype.explodeMarker = function(marker, iconName){
        if (!marker.overMarker){
		//create an overlay
		var overlay = new GMarker(marker.getPoint(),new GIcon(marker.getIcon()));
		
		//enlarge the iconsize of the overlay's image
		var overlayWidth = parseFloat(marker.getIcon().iconSize.width) * 1.5;
		var overlayHeight = parseFloat(marker.getIcon().iconSize.height) * 1.5;
		overlay.getIcon().iconSize = new GSize(overlayWidth, overlayHeight);
			
		//add the overlay to the map
		this._map.addOverlay(overlay);

		//store the overlay in the marker for future reference (e.g. in case of removal)
		marker.overMarker = overlay;
	}
}

//Function to restore a camping marker to its original size
AMarkerManager.prototype.restoreMarker = function(markerId){
	//temporarily store the marker
	var marker = this.getMarkerById(markerId);

	//if the marker has an overlay, remove it!
	if (marker.overMarker){
		//remove the overlay from the map
		this._map.removeOverlay(marker.overMarker);

		//remove the reference to the overlay from the marker
		marker.overMarker = null;
	}
}

//Function that centers the map on a country and opens an info window for the selected country
AMarkerManager.prototype.centerMapOnMarker = function(markerId){
	//temporarily store the marker and its position
	var marker = markerManager.getMarkerById(markerId);

	//get the point from the marker
	var point = marker.getPoint();

	//have the map center on the marker's coordinates (point)
	map.setCenter(point);
}