function tryGeo() {
	prepareGeolocation();
	doGeo();
	return false;
}
function doGeo() {
	if (navigator.geolocation) {
		navigator.geolocation.getCurrentPosition(positionSuccess, positionError);
	} else {
		positionError(-1);
	}
}
function positionError(err) {
	var msg;
	switch(err.code) {
		case err.UNKNOWN_ERROR:
			msg = "Unable to find your location";
			break;
		case err.PERMISSION_DENINED:
			msg = "Permission denied in finding your location";
			break;
		case err.POSITION_UNAVAILABLE:
			msg = "Your location is currently unknown";
			break;
		case err.BREAK:
			msg = "Attempt to find location took too long";
			break;
		default:
			msg = "Location detection not supported in browser";
	}
	alert(msg);
}
function positionSuccess(position) {
	// Centre the map on the new location
	var coords = position.coords || position.coordinate || position;
	var baseDomain = getBaseDomain();
	window.location = 'http://www'+baseDomain+'/properties.mobi?lat='+coords.latitude+'&lng='+coords.longitude+'&per_page=20&radius=50&sort=distance-up&around=true';
}
function getBaseDomain() {
	var arr = window.location.hostname.split('.');
	if (arr.length == 3) {
		return '.' + arr[1] + '.' + arr[2];
	} else if (arr.length == 4) {
		return '.' + arr[1] + '.' + arr[2] + '.' + arr[3];
	} else if (arr.length == 2) {
		return '.' + arr[0] + '.' + arr[1];
	}
}
