// Lunar period and moonphase time computing by James Thiele
// Functions and images: 2003-ak-zuss.com
var currentDate = new Date();
currentDate.setTime(currentDate.getTime() + (currentDate.getTimezoneOffset()*60000));
var lunarPeriod = 29*(24*3600*1000) + 12*(3600*1000) + 44.05*(60*1000);
var blueMoonDate = new Date(Date.UTC(2002, 7, 8, 18, 14) - (lunarPeriod/2));
var moonPhaseTime = (currentDate.getTime() - blueMoonDate.getTime()) % lunarPeriod;
var percentRaw = (moonPhaseTime / lunarPeriod);
var T = Math.round((lunarPeriod-moonPhaseTime)/(24*3600*1000));
function moon(){if ((T<=28)&&(T>=24)){return('waninggibbous');}
else if ((T<24)&&(T>=20)){return('lastquarter');}
else if ((T<20)&&(T>=16)){return('waningcrescent');}
else if ((T<16)&&(T>=12)){return('moonnew');}
else if ((T<12)&&(T>=9)){return('waxingcrescent');}
else if ((T<9)&&(T>=5)){return('firstquarter');}
else if ((T<5)&&(T>=2)){return('waxinggibbous');}
else if ((T<2)||(T>28)){return('moonfull');}}
function readme(){if ((T<=28)&&(T>=24)){return('Waning gibbous');}
else if ((T<24)&&(T>=20)){return('Last quarter');}
else if ((T<20)&&(T>=16)){return('Waning crescent');}
else if ((T<16)&&(T>=12)){return('New moon');}
else if ((T<12)&&(T>=9)){return('Waxing crescent');}
else if ((T<9)&&(T>=5)){return('First quarter');}
else if ((T<5)&&(T>=2)){return('Waxing gibbous');}
else if ((T<2)||(T>28)){return('Full moon');}}
function phase(){
document.write('<img src="phases/'+moon()+'.jpg" width="30" height="30" alt="" /><br />');
document.write(readme());}