
	/**
	 * This class caches responses from AJAX
	 */
	ResponseCache = function(map)
	{
		//map
		this.map = map;

		//cache store
		this.store = [];

		//****trackers*****
		//these objects are responsible for tracking points on the map that have
		// been viewed, a last active point, and then all active points for a
		// particular level
		//later, we test to see if the last active or any previous active point
		// is contained within the current map bounds before making a request

		//tracks the last active point for each level
		this.lastActiveTracker = {};
		this.lastActiveTracker.property = null;
		this.lastActiveTracker.city = null;
		this.lastActiveTracker.region = null;
		this.lastActiveTracker.country = null;
		this.lastActiveTracker.district = null;

		this.lastActiveTracker.location = null;

		//tracks the list of all active points for each level
		this.activeTrackers = {};
		this.activeTrackers.property = [];
		this.activeTrackers.city = [];
		this.activeTrackers.district = [];
		this.activeTrackers.region = [];
		this.activeTrackers.country = [];

		this.activeTrackers.location = [];
		//****trackers*****

		//MochiKit.Base.bindMethods(this);
	}

	/**
	 * Put something in the cache
	 */
	ResponseCache.prototype.put = function(key, item, level)
	{
		//make sure the levels are init
		if (!this.store[level])
		{
			this.store[level] = [];
		}

		this.store[level][new String(key)] = item;
	}

	/**
	 * Get something from the cache
	 */
	ResponseCache.prototype.get = function(key, level)
	{
		//make sure the levels are init
		if (!this.store[level])
		{
			this.store[level] = [];
		}

		return this.store[level][new String(key)];
	}

	/**
	 * Invalidate the item in storage
	 */
	ResponseCache.prototype.invalidate = function(key, level)
	{
		//make sure the levels are init
		if (!this.store[level])
		{
			return;
		}

		this.store[key] = null;
	}

	/**
	 * Checks to see if we have loaded this map view previously for the given
	 * type.
	 * @param string type The type of current map view
	 * @return bool Returns true if we have viewed this map section before
	 */
	ResponseCache.prototype._hasLoadedViewBefore = function(type)
	{
		//get the current viewport
		var currentViewPort = this.map.getBounds();

		//check to see if lastActiveTracker is in current viewport
		//if it is, do nothing
		if (this.lastActiveTracker[type])
		{
			var activePoints = this.lastActiveTracker[type].split('_');
			var point = new GLatLng(activePoints[0], activePoints[1]);

			if (currentViewPort.contains(point))
			{
				return true;
			}
		}

		//if it isnt, check all previous activeTrackers, if any are
		// in the current viewport, do nothing
		for (var tracker in this.activeTrackers[type])
		{
			var trackerPoints = this.activeTrackers[type][tracker].split('_');
			var point = new GLatLng(trackerPoints[0], trackerPoints[1]);

			if (currentViewPort.contains(point))
			{
				this.lastActiveTracker[type] = this.activeTrackers[type][tracker];
				return true;
			}
		}

		//if there are currently no activeTrackers in the viewport,
		// make the call and store this activeTracker and mark as lastActive
		var latlng = this.map.getCenter();
		this.lastActiveTracker[type] = latlng.lat() + '_' + latlng.lng();
		this.activeTrackers[type].push(this.lastActiveTracker[type]);

		return false;
	}

	/**
	 * Returns the cached information for the current layer and viewport
	 * @param string currentLayer The const name of the current layer
	 * @return array The cache key and stored item (if the item exists)
	 */
	ResponseCache.prototype.getCachedInformation = function(currentLayer)
	{
		//init the storedKey var to a local var
		var cacheInformation = [];

		//if we have already loaded this view, get the item from the cache
		if (this._hasLoadedViewBefore(currentLayer))
		{
			//init the key
			cacheInformation['storedKey'] = currentLayer + "_" + this.lastActiveTracker[currentLayer];

			//create the would be cache response, and check the cache for a stored
			// response object
			cacheInformation['storedResponse'] = this.get(cacheInformation['storedKey'], this.map.getZoom());

			return cacheInformation;
		}

		//init the key
		cacheInformation['storedKey'] = currentLayer + "_" + this.lastActiveTracker[currentLayer];

		return cacheInformation;
	}

