/**
 * Class used for representing a neighborhhod
 */
function Neighborhood(map, boroughName, neigborhoodName, polygons)
{
    this.map = map;
    this.boroughName = boroughName;
    this.neigborhoodName = neigborhoodName;
    this.polygons = polygons;
    this.center = this.getCenter(this.polygons);
}

/**
 * Adds an overlay to the map showing the neighborhood's boundary
 */
Neighborhood.prototype.addOverlay = function()
{
    for (var i = 0; i < this.polygons.length; i++)
    {
        this.map.addOverlay(this.polygons[i].overlay);
    }
}

/**
 * Removes the neighborhood boundary from the parent map
 */
Neighborhood.prototype.removeOverlay = function()
{
    for (var i = 0; i < this.polygons.length; i++)
    {
        this.map.removeOverlay(this.polygons[i].overlay);
    }
}

/**
 * Returns the neighborhood's center coordinate (lat/long) by calculating the center of the polygon defining its boundary
 */
Neighborhood.prototype.getCenter = function(polygons)
{
    var cLat = 0;
    var cLng = 0;
    for (var i = 0; i < polygons.length; i++)
    {
        cLat = polygons[i].centroid.lat();
        cLng = polygons[i].centroid.lng();
    }
    cLat = cLat / polygons.length;
    cLng = cLng / polygons.length;

    return new GLatLng(cLat, cLng);
}

/**
 * Returns true if the provided coordinates (lat/long) fall within the neighborhood's boundaries
 */
Neighborhood.prototype.contains = function(coordinates)
{
    for (var i = 0; i < this.polygons.length; i++)
    {
        if (this.polygons[i].contains(coordinates))
            return true;
    }

    return false;
}

