/*  distance.js  */

/*	1. Great Wall of China: 40.354166, 116.006944
	2. Rio de Janeiro, Brazil: -22.903539,-43.209587
	3. Machu Picchu, Peru: -13.163957,-72.545993
	4. Chichen Itza, Yucatan Peninsula, Mexico: 20.682859,-88.57255
	5. The Roman Colosseum, Rome, Italy: 41.8901861, 12.4923133
	6. Taj Mahal, Agra, India: 27.172774,78.041655
	7. Petra, Jordan: 30.328878,35.442581
*/

var lat2, lon2;


/** Converts numeric degrees to radians */
if (typeof(Number.prototype.toRad) === "undefined") {
	Number.prototype.toRad = function() {
		return this * Math.PI / 180;
	}
}

function getDistance(num){
	switch(num)
	{
	case 1:
		lat2 = 40.354166;
		lon2 = 116.006944;
		break;
	case 2:
		lat2 = -22.903539;
		lon2 = -43.209587;
		break;
	case 3:
		lat2 = -13.163957;
		lon2 = -72.545993;
		break;
	case 4:
		lat2 = 20.682859;
		lon2 = -88.57255;
		break;
	case 5:
		lat2 = 41.8901861;
		lon2 = 12.4923133;
		break;
	case 6:
		lat2 = 27.172774;
		lon2 = 78.041655;
		break;
	case 7:
		lat2 = 30.328878;
		lon2 = 35.442581;
		break;
	}

	// Haversine formula: JavaScript version
	var R = 6371; // radius of the earth in km
	var dLat = (lat2-lat1).toRad();
	var dLon = (lon2-lon1).toRad(); 
	var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
			Math.cos(lat1.toRad()) * Math.cos(lat2.toRad()) * 
			Math.sin(dLon/2) * Math.sin(dLon/2); 
	var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); 
	var d = R * c;
	return Math.round(d);
}