function sunEphemeris(year, month, day, latitude, longitude) {

// This function will calculate orbital data for the Sun 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);	
		
// Calculate the orbital parameters for the given day.

	var o = obliquity(d);
	var N = 0;
	var i = 0;
	var w = wSun(d);
	var a = aSun(d);
	var e = eSun(d);
	var M = MSun(d);
		
// Calculate the eclipse values.

	var L = w + M;
	L = normalize(L, 2 * Math.PI);
	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 geocentric ecliptical coordinates.

	var xGeoEcl = r * (Math.cos(N) * Math.cos(v + w) - Math.sin(N) * Math.sin(v + w) * Math.cos(i));
	var yGeoEcl = r * (Math.sin(N) * Math.cos(v + w) + Math.cos(N) * Math.sin(v + w) * Math.cos(i));
	var zGeoEcl = r * Math.sin(v + w) * Math.sin(i);
	
// 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 apparent diameter and magnitude.

	var aprntDiameter = 1919.26 / 3600 / R;
	
	var magnitude = -26.7;

// 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] = 0;
	dataArray[7] = aprntDiameter;
	dataArray[8] = magnitude;
	dataArray[9] = 100;
	dataArray[10] = UTRise;
	dataArray[11] = UTSouth;
	dataArray[12] = UTSet;
	
	return dataArray;
			
	}
	
function aSun(d) {

// Calculate the Mean Distance, a, for the Sun.  Input is the day number, d. 

	var a1 = 1.0;
	var a2 = 0;
	var a  = 0;
	
	a = a1 + a2 * d;
	
	return a;
	}

function eSun(d) {

// Calculate the Longitude of Perihelion, w, for the Sun.  Input is the day number, d.

	var e1 = 0.016709;
	var e2 = -0.000000001151;
	var e  = 0;
	
	e = e1 + e2 * d;
	
	return e;
	}

function wSun(d) {

// Calculate the Longitude of Perihelion, w, for the Sun.  Input is the day number, d.

	var w1 = 282.9404;
	var w2 = 0.0000470935;
	var w  = 0;
	
	w1 = degToRad(w1);
	w2 = degToRad(w2);	
	w  = w1 + w2 * d;
	w  = normalize(w, 2 * Math.PI);
	
	return w;
	}

function MSun(d) {

// Calculate the Mean Logitude, L, for the Sun.  Input is the day number, d. 

	var M1 = 356.0470;
	var M2 = 0.9856002585;
	var M  = 0;
	
	M1 = degToRad(M1);
	M2 = degToRad(M2);	
	M  = M1 + M2 * d;
	M  = normalize(M, 2 * Math.PI);
	
	return M;
	}

function LSun(d) {

// Calculate the Mean Logitude, L, for the Sun.  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;
	}
