//**************************************************************************************
// Takes an array of points and works out the total distance
function calculateDistance (points) {
	if (points.length < 2)
		return 0;

	var dist = 0.0;

	for (var i = 0; i < points.length - 1; i++) {
		dist += distance_between_points(points[i], points[i + 1]);
	}

	return dist;
}

// Utility function for converting degrees to radians
Math.deg2rad = function ( x ) {
        return x * (Math.PI / 180.0);
}

// Distance in metres
var EARTH_RADIUS = 6367000;

var total_distance = 0;

var MILES = {
	label : "miles",
	f : function (distance) {
			return distance / 1609.344;
	}
}

// Calculates the distance (in metres) between 2 points.
function distance_between_points ( p1, p2 ) {
        var a = Math.deg2rad( 90 - p1.y);
        var b = Math.deg2rad( 90 - p2.y);
        var theta = Math.deg2rad( p2.x - p1.x);
        var c = Math.acos( Math.cos(a) * Math.cos(b) + Math.sin(a) * Math.sin(b) * Math
.cos(theta));

        return c * EARTH_RADIUS;
}

function subClearMap()
{
 map.clearOverlays();
}
//**************************************************************************************
