// *******************************************************************

// Define the images used to overlay the image
var white = "Moonglowclear.gif";
var black = "Moonglowblack.gif";

// Size od display. DO NOT CHANGE!
var size = 50;

// Get the current Date
var currentDate  = new Date();

// Change the Time from Local to GMT
currentDate.setTime(currentDate.getTime() + (currentDate.getTimezoneOffset()*60000));

// Calculations for image display
var blueMoonDate = new Date(96, 1, 3, 16, 15, 0);
var lunarPeriod  = 29*(24*3600*1000) + 12*(3600*1000) + 44.05*(60*1000);
var moonPhaseTime = (currentDate.getTime() - blueMoonDate.getTime()) % lunarPeriod;

// Calculations for phase
var percentRaw = (moonPhaseTime / lunarPeriod);
var percent    = Math.round(100*percentRaw) / 100;
var percentBy2 = Math.round(200*percentRaw);
if (percentBy2 > 100)
{
	percentBy2 = percentBy2 - 100;
}

// Define overlay bounderies
var left  = (percentRaw >= 0.5) ? black : white;
var right = (percentRaw >= 0.5) ? white : black;

// The Luanr Time
var time = Math.round((lunarPeriod-moonPhaseTime)/(24*3600*1000));

// ------------------------------------------------
function displayOverlay()
{
	// Place the overlay image inside a SPAN for placement control
//	document.write("<span class='overlay' style='width: " + (size*2) + "px; height: " + (size*2) + "px;'>");
	document.write("<span class='overlay'");

	// Calculations for Phase display
	for (i = -(size-1); i < size; ++i)
	{
		var wid=2*parseFloat(Math.sqrt((size*size)-(i*i)));
	
		if (percentBy2 != 100)
			document.write ("<img src="+left +" height=1 width="+(wid*((100-percentBy2)/100))+">");

		if (percentBy2 != 0)
			document.write("<img src="+right+" height=1 width="+(wid*((percentBy2)/100))+">");
			document.write("<br>");
	}

	// Close our overlay SPAN
	document.write("</span>");
}

// ------------------------------------------------
function displayText()
{
	if (self.time > 0)
	{
		document.write("<BR><FONT SIZE=4 color='white'>" + currentDate + "<br>Next full moon is in about ",time," day");
		if (self.time > 1) document.write("s");
			document.write("</font>");
	}
	else
	{
		document.write("<BR><FONT SIZE=4 color='white'>The Full Moon");
	}

}

// eof

