/**
 * is the map intialized
 */
var isMapInitialized = false;

/**
 * @class SearchResult
 * SearchResult is a class that encapsulates all of the information needed for a single
 * search result to be displayed on the search page including the activity object, a ponter
 * to the marker on the map, and the div id of the text entry in the search results list.
 */
var SearchResult = Class.create();
SearchResult.prototype = {
	initialize: function(activity, marker, listId) {
		this.activity = activity;
		this.marker = marker;
		this.listId = listId;
		
		this.isDrawn = false;
		
		this.resultsPage = 1;
	},
	
	setDrawn: function() {
		this.isDrawn = true;
	}
}


/**
 * @class MapSearch
 * MapSearch is the base class for any implementation of a map search.
 * Functions that are implemented here do not have any make any map specific 
 * calls.  
 */
var MapSearch = Class.create();
MapSearch.prototype = {
    /**
     * Instantiates an MapSearch object
     * @param {String} mapString The id of the map element on the page
     * @constructor 
     * @member MapSearch
     */
	initialize: function(mapString) {
        log("MapSearch:setupMap should be over-ridden by child class!");
	},
	
    /**
     * Sets up the map on the page.  Different implementations will do this differently 
     * this.map should point to the map object
     * @param {String} mapString The id of the map object on the page
     * @member MapSearch
     */
    setupMap: function(mapString) {
        log("MapSearch:setupMap should be over-ridden by child class!");
    },
    
    
    /**
     * Performs a search based on the given keyword and location.
     * @param {String} keyword The keyword to look for
     * @param {String} location The geographic location in which to search
     * @member MapSearch
     */
    performSearch: function(keyword, location) {
        log("MapSearch:performSearch should be over-ridden by child class!");    
    },

    /**
     * Clear all of the current search results and the map.  Should also clear the results hash.
     * @member MapSearch
     */      
    clearResults: function() {
        log("MapSearch:clearResults should be over-ridden by child class!");    
    },

    /**
     * Move the map to a new location.
     * @param {String} location
     * @member MapSearch
     */          
    moveToLocation: function(location) {
        log("MapSearch:moveToLocation should be over-ridden by child class!");        
    },

    /**
     * Get the map marker object for a current search result by activityId.
     * @param {Integer} activityId
     * @member MapSearch
     */
	getMarker: function(activityId) {
		var result = results[activityId];
		if(result) {
			return result.marker;
		} else {
			log("Marker doesn't exist.");
		}
	},

    /**
     * Get the activity object for a current search result by activityId.
     * @param {Integer} activityId
     * @member MapSearch
     */    	
	getActivity: function(activityId) {
		var result = results[activityId];
		if(result) {
			return result.activity;
		} else {
			log("Marker doesn't exist.");
		}
	},
	
    /**
     * Sets the results page currently being searched and updates the results.
     * @param {Integer} pageNumber
     * @member MapSearch
     */      
    setResultsPage: function(pageNumber) {
		this.resultsPage = pageNumber;
		this.updateResults();
	},

    /**
     * Increments the results page currently being search and updates the results.
     * @member MapSearch
     */  	
	nextPage: function() {
		this.setResultsPage(this.resultsPage + 1);
	},

    /**
     * Increments the results page currently being search and updates the results.
     * @member MapSearch
     */  	
	previousPage: function() {
		this.setResultsPage(this.resultsPage - 1);
	}
};

/**
 * The JS map controller calls this to let it know it's ready to go
 */
function mapInitialized() {
    isMapInitialized = true;
}