﻿function s(w){
	var b = t(document.getElementById('imageTab'));
	document.getElementById('th'+w).style.display = 'inline';
	document.getElementById('th'+w).style.top = 5 + b + 'px';	
}

function h(w){
	document.getElementById('th'+w).style.display = 'none';	
}

function t(e) {
	var t = e.offsetTop;
	var p = e.offsetParent;
	while (p != null){
		t += p.offsetTop;
		p = p.offsetParent;
	}
	return t;
}


function x(){
	window.setTimeout('z(0)',4000);	
}


function z(h){
	var b = document.getElementById('popUpTitle').style;
	if(h && h == 1){
		b.display = 'inline';
	} else {
		b.display = 'none';
	}
}


// source http://www.movable-type.co.uk/scripts/latlong.html
function dist(lat1,lon1,lat2,lon2){
	var R = 6371; // 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 parseInt(1000*d)/1000+'km';
}

function bearing(lat1, lon1, lat2, lon2) {
  lat1 = lat1.toRad(); lat2 = lat2.toRad();
  var dLon = (lon2-lon1).toRad();

  var y = Math.sin(dLon) * Math.cos(lat2);
  var x = Math.cos(lat1)*Math.sin(lat2) -   Math.sin(lat1)*Math.cos(lat2)*Math.cos(dLon);
  return parseInt(100*Math.atan2(y, x).toBrng())/100+'°';
}

Number.prototype.toRad = function() {  // convert degrees to radians
	return this * Math.PI / 180;
}
Number.prototype.toDeg = function() {  // convert radians to degrees (signed)
	return this * 180 / Math.PI;
}

Number.prototype.toBrng = function() {  // convert radians to degrees (as bearing: 0...360)
	return (this.toDeg()+360) % 360;
}
