function mercuryEphemeris(year, month, day, latitude, longitude) {

// This function will calculate orbital data for Mercury base of the
// date and location passed in.
// Latitude and longitude should be passed in radians.
	
	var dataArray = new Array();
	var h  = -0.833;
	
// Calculate the day number

	var d = calcDayNumber(year, month, day);
	
// Get the Sun's position.  It will be needed for Mercury's ephemeris.

	var sunData = new Array();
	sunData = sunEphemeris(year, month, day, latitude, longitude);
		
// Calculate the orbital parameters for the given day.

	var o = obliquity(d);
	var N = NMercury(d);
	var i = iMercury(d);
	var w = wMercury(d);
	var a = aMercury(d);
	var e = eMercury(d);
	var M = MMercury(d);
		
// Calculate the eclipse values.

	var L = LMercury(d);
	var E = Ecc(e, M);
	
	var x = a * (Math.cos(E) - e);
	var y = a * (Math.sin(E) * Math.sqrt(1.0 - Math.pow(e, 2)));
	var r = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
	var v = Math.atan2(y, x);
	v = normalize(v, 2 * Math.PI);
		
// Calculate the heliocentric ecliptical coordinates.

	var xHeEcl = r * (Math.cos(N) * Math.cos(v + w) - Math.sin(N) * Math.sin(v + w) * Math.cos(i));
	var yHeEcl = r * (Math.sin(N) * Math.cos(v + w) + Math.cos(N) * Math.sin(v + w) * Math.cos(i));
	var zHeEcl = r * Math.sin(v + w) * Math.sin(i);
	
// Calculate the heliocentric spherical coordinates.

	var lonHeEcl = Math.atan2(yHeEcl, xHeEcl);
	lonHeEcl = normalize(lonHeEcl, 2 * Math.PI);
	var latHeEcl = Math.atan2(zHeEcl, Math.sqrt( Math.pow(yHeEcl, 2) + Math.pow(xHeEcl, 2) ));
	latHeEcl = normalize(latHeEcl, 2 * Math.PI);
	var RHeEcl = Math.sqrt( Math.pow(xHeEcl, 2) + Math.pow(yHeEcl, 2) + Math.pow(zHeEcl, 2) );
	
// Calculate the geocentric ecliptical coordinates.

	var xGeoEcl = xHeEcl + sunData[0];
	var yGeoEcl = yHeEcl + sunData[1];
	var zGeoEcl = zHeEcl + sunData[2];


// Calculate the geocentric equitorial coordinates.

	var xGeoEqu = xGeoEcl;
	var yGeoEqu = yGeoEcl * Math.cos(o) - zGeoEcl * Math.sin(o);
	var zGeoEqu = yGeoEcl * Math.sin(o) + zGeoEcl * Math.cos(o);
	
// Calculate the right accension, declination and distance.

	var R   = Math.sqrt(Math.pow(xGeoEqu, 2) + Math.pow(yGeoEqu, 2) + Math.pow(zGeoEqu, 2));
	var RA  = Math.atan2(yGeoEqu, xGeoEqu);
	RA = normalize(RA, 2 * Math.PI);
	var Dec = Math.asin(zGeoEqu / R);
	Dec = normalize(Dec, 2 * Math.PI);
	
// Calculate the elongation, percent illumination, apparent diameter and magnitude.

	var elongation = Math.acos((Math.pow(sunData[5], 2) + Math.pow(R, 2) - Math.pow(RHeEcl, 2)) 
		/ (2 * sunData[5] * R));
	
	var FV = Math.pow(RHeEcl, 2) + Math.pow(R, 2) - Math.pow(sunData[5], 2);
	FV = FV / (2 * RHeEcl * R);
	FV = Math.acos(FV);
	
	var pctIllumination = (1 + Math.cos(FV)) / 2 * 100;
	
	var aprntDiameter = 6.74 / 60 / 60 / R;
	
	FV = radToDeg(FV);
	var magnitude = 5 * Math.log(RHeEcl * R) / Math.log(10);
	magnitude = -0.36 + magnitude + 0.027 * FV + 0.00000000000022 * Math.pow(FV, 6);

// Calculate the rise, south and set time.

	var L = LSun(d);
	var UTSouth = RA - L + Math.PI - longitude;
	UTSouth = UTSouth / degToRad(15.04107);
	UTSouth = normalize(UTSouth, 24);
	
	var LHA = (Math.sin(degToRad(h)) - Math.sin(latitude) * Math.sin(Dec)) /
		(Math.cos(latitude) * Math.cos(Dec));
	if (LHA <= -1) {
		UTRise = "Always Up"
		UTSet  = "Always Up"
		}
	else if (LHA >= 1) {
		UTRise = "Always Set"
		UTSet  = "Always Set"
		}
	else {
		LHA = Math.acos(LHA);
		LHA = LHA / degToRad(15.04107);
	
		var UTRise = UTSouth - LHA;
		UTRise = normalize(UTRise, 24);
		var UTSet  = UTSouth + LHA;
		UTSet = normalize(UTSet, 24);
		}
	
	dataArray[0]  = xGeoEcl;
	dataArray[1]  = yGeoEcl;
	dataArray[2]  = zGeoEcl;
	dataArray[3]  = RA;
	dataArray[4]  = Dec;
	dataArray[5]  = R;
	dataArray[6]  = elongation;
	dataArray[7]  = aprntDiameter;
	dataArray[8]  = magnitude;
	dataArray[9]  = pctIllumination;
	dataArray[10] = UTRise;
	dataArray[11] = UTSouth;
	dataArray[12] = UTSet;
	
	return dataArray;
			
	}
	
function aMercury(d) {

// Calculate the Mean Distance, a, for Mercury.  Input is the day number, d. 

	var a1 = 0.387098;
	var a2 = 0;
	var a  = 0;
	
	a = a1 + a2 * d;
	
	return a;
	}

function eMercury(d) {

// Calculate the Longitude of Perihelion, w, for Mercury.  Input is the day number, d.

	var e1 = 0.205635;
	var e2 = 0.000000000559;
	var e  = 0;
	
	e = e1 + e2 * d;
	
	return e;
	}

function NMercury(d) {

// Calculate the Logitude of Accending Node, N, for Mercury.  Input is the day number, d. 

	var N1 = 48.3313;
	var N2 = 0.0000324587;
	var N  = 0;
	
	N1 = degToRad(N1);
	N2 = degToRad(N2);	
	N  = N1 + N2 * d;
	N  = normalize(N, 2 * Math.PI);
	
	return N;
	}
	
function iMercury(d) {

// Calculate the Inclination, i, for Mercury.  Input is the day number, d. 

	var i1 = 7.0047;
	var i2 = 0.00000005;
	var i  = 0;
	
	i1 = degToRad(i1);
	i2 = degToRad(i2);	
	i  = i1 + i2 * d;
	i  = normalize(i, 2 * Math.PI);
	
	return i;
	}
	
function wMercury(d) {

// Calculate the Longitude of Perihelion, w, for Mercury.  Input is the day number, d.

	var w1 = 29.1241;
	var w2 = 0.0000101444;
	var w  = 0;
	
	w1 = degToRad(w1);
	w2 = degToRad(w2);	
	w  = w1 + w2 * d;
	w  = normalize(w, 2 * Math.PI);
	
	return w;
	}

function LMercury(d) {

// Calculate the Mean Logitude, L, for Mercury.  Input is the day number, d. 

	var M = MSun(d);	
	var w = wSun(d);
	
	var L = M + w;
	L = normalize(L, 2 * Math.PI);
	
	return L;
	}
	
function MMercury(d) {

// Calculate the Mean Logitude, L, for Mercury.  Input is the day number, d. 

	var M1 = 168.6562;
	var M2 = 4.0923344368;
	var M  = 0;
	
	M1 = degToRad(M1);
	M2 = degToRad(M2);	
	M  = M1 + M2 * d;
	M  = normalize(M, 2 * Math.PI);
	
	return M;
	}
