<?xml version="1.0" encoding="utf-8"?>
<Module>
<ModulePrefs title="Sleek Calendar" author="Leonel Corona" author_email="leonel@matt.org" author_affiliation="Matt.org" author_location="San Antonio, TX" screenshot="http://www.matt.org/modules/images/screenshot.jpg" thumbnail="http://www.matt.org/modules/images/sleekcaltn.png" description="Add a Calendar to your page, includes a digital Clock and a nice daily moon calendar" render_inline="optional" height="174" scaling="true">
<Require feature="analytics" /> 
</ModulePrefs>
<Content Type="html">
<![CDATA[
	<script>
     // Track this gadget using Google Analytics.
     _IG_Analytics("UA-1544479-1", "/SleekCalendar");
   </script>
<div id="AllCalendar" style="font-family: Arial"></div>
<font style="font-family: Arial">
<script language="javascript">
function calctime()
{		
			var currenttime = new Date();
			var hours = currenttime.getHours();
			var minutes = currenttime.getMinutes();
			var seconds = currenttime.getSeconds();
			var timesuffix = "AM";
			if (hours > 11)
			{
			timesuffix = "PM";
			hours = hours - 12;
			}
			if (hours == 0)
			{
			hours = 12;
			}
			if (hours < 10)
			{
			hours = "0" + hours;
			}
			if (minutes < 10)
			{
			minutes = "0" + minutes;
			}
			if (seconds < 10)
			{
			seconds = "0" + seconds;
			}
			var clocklocation = document.getElementById('digitalclock');
			//clocklocation.innerHTML = hours + ":" + minutes + ":" + seconds + " " + timesuffix;
			clocklocation.innerHTML = hours * 1 + ":" + minutes + " " + timesuffix;
			setTimeout("calctime()", 1000);
}
</script>
<script language=javascript>
function GetMoon() 
{

			var pastdate
			var pastyear=2002
			var pastmonth=5
			var pastday=11
			var nowdate
			var c
			var pausenormal=50
			var pausenowmoon=3000
			var moonday
			var i_mooncycle=1
			var mooncycle=29.530589
			
			var picture = new Array("http://www.matt.org/modules/images/moonitems/nn1.gif","http://www.matt.org/modules/images/moonitems/nn2.gif","http://www.matt.org/modules/images/moonitems/nn3.gif","http://www.matt.org/modules/images/moonitems/nn4.gif","http://www.matt.org/modules/images/moonitems/nn5.gif","http://www.matt.org/modules/images/moonitems/nn6.gif","http://www.matt.org/modules/images/moonitems/nn7.gif","http://www.matt.org/modules/images/moonitems/nn8.gif","http://www.matt.org/modules/images/moonitems/nn9.gif","http://www.matt.org/modules/images/moonitems/nn10.gif","http://www.matt.org/modules/images/moonitems/nn11.gif","http://www.matt.org/modules/images/moonitems/nn12.gif","http://www.matt.org/modules/images/moonitems/nn13.gif","http://www.matt.org/modules/images/moonitems/nn14.gif","http://www.matt.org/modules/images/moonitems/nn15.gif","http://www.matt.org/modules/images/moonitems/nn16.gif","http://www.matt.org/modules/images/moonitems/nn17.gif","http://www.matt.org/modules/images/moonitems/nn18.gif","http://www.matt.org/modules/images/moonitems/nn19.gif","http://www.matt.org/modules/images/moonitems/nn20.gif","http://www.matt.org/modules/images/moonitems/nn21.gif","http://www.matt.org/modules/images/moonitems/nn22.gif","http://www.matt.org/modules/images/moonitems/nn23.gif","http://www.matt.org/modules/images/moonitems/nn24.gif","http://www.matt.org/modules/images/moonitems/nn25.gif","http://www.matt.org/modules/images/moonitems/nn26.gif","http://www.matt.org/modules/images/moonitems/nn27.gif","http://www.matt.org/modules/images/moonitems/nn28.gif","http://www.matt.org/modules/images/moonitems/nn29.gif")
			
			var imgpreload=new Array()
			for (i=0;i<=picture.length;i++) {
				imgpreload[i]=new Image()
				imgpreload[i].src=picture[i]
			}
			
			pastdate=new Date(pastyear,pastmonth,pastday,0,0,0)
			nowdate=new Date()
			resultdays=(Date.parse(nowdate)-Date.parse(pastdate))/1000/60/60/24
			moonday=resultdays/mooncycle
			moonday=(resultdays/mooncycle)-(Math.floor(resultdays/mooncycle))
			moonday=Math.round(mooncycle*moonday)
			
			
			//START Get the next full moon
			var currentDate  = new Date();
			var x = currentDate;
			// Convert it to GMT
			currentDate.setTime(currentDate.getTime() + (currentDate.getTimezoneOffset()*60000));
			
			// Get Date (GMT) for recent full moon
			var blueMoonDate = new Date(96, 1, 3, 16, 15, 0);
			
			// Compute length of lunar period
			var lunarPeriod  = 29*(24*3600*1000) + 12*(3600*1000) + 44.05*(60*1000);
			
			var moonPhaseTime = (currentDate.getTime() - blueMoonDate.getTime()) % lunarPeriod;
			
			//document.write("<br>The next full moon is in about ", Math.round((lunarPeriod-moonPhaseTime)/(24*3600*1000)), " day", Math.round((lunarPeriod-moonPhaseTime)/(24*3600*1000)) != 1 ? "s" : "", "");
			var alt = "The next full moon is in about " + Math.round((lunarPeriod-moonPhaseTime)/(24*3600*1000)) + " days";
			//END Get the next full moon
			
			c="<img src='http://www.matt.org/modules/images/moonitems/nn"+moonday+".gif' name='moonimg' alt='" + alt + "'>"
			
			//Write Moon Img in calendar
			var moonlocation = document.getElementById('moonid');
			moonlocation.innerHTML = c
}

//window.onload=animatemoon

function animatemoon() {
	if (i_mooncycle==moonday) {
		var pause=pausenowmoon
	}
	else {
		var pause=pausenormal
	}
	var mimg="http://www.matt.org/modules/images/moonitems/nn"+i_mooncycle+".gif"
	document.moonimg.src=mimg
	i_mooncycle++
	if (i_mooncycle>29) {i_mooncycle=1}
	var timer=setTimeout("animatemoon()",pause)
}
</script>
<script language=javascript>
<!-- Begin
function Make_Calendar(Year, Month) {

		//prefs=new _IG_Prefs(__MODULE_ID__)
		var backcolor="Grayscale";//prefs.getString("backcolor")
		
		if (backcolor=="Blue") {
		var strbackgroudn="backgroundblue.jpg";
		}
		
		if (backcolor=="Grayscale") {
		var strbackgroudn="background.jpg";
		}
		
		//  SET ARRAYS
		var day_of_week = new Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
		var month_of_year = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
		
		//  DECLARE AND INITIALIZE VARIABLES
		
		var Calendar = new Date(Year, Month, 1);
		var todayCalendar = new Date();
		
		//var Calendar = new Date();
		
		var year = Calendar.getFullYear();	    // Returns year
		var month = Calendar.getMonth();    // Returns month (0-11)
		var today = todayCalendar.getDate();    // Returns day (1-31)
		var weekday = todayCalendar.getDay();    // Returns day (1-31)
		
		var DAYS_OF_WEEK = 7;    // "constant" for number of days in a week
		var DAYS_OF_MONTH = 31;    // "constant" for number of days in a month
		var cal;    // Used for printing
		
		Calendar.setDate(1);    // Start the calendar day at '1'
		Calendar.setMonth(month);    // Start the calendar month at now
		
		
		/* VARIABLES FOR FORMATTING
		NOTE: You can format the 'BORDER', 'BGCOLOR', 'CELLPADDING', 'BORDERCOLOR'
		      tags to customize your caledanr's look. */
		
		var TR_start = '<TR>';
		var TR_end = '</TR>';
		var highlight_start = '<TD WIDTH="14.2%" style=cursor:hand><CENTER><TABLE CELLSPACING=0 BORDER=0 style="border-style: solid; border-width: 1px; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px" BGCOLOR=E2EFFF BORDERCOLOR=CCCCCC><TR>';
		var highlight_end   = '</CENTER></TD></a></TR></TABLE></B>';
		var TD_start = '<TD WIDTH="14.2%"><CENTER>';
		var TD_end = '</CENTER></TD>';
		
		/* BEGIN CODE FOR CALENDAR
		NOTE: You can format the 'BORDER', 'BGCOLOR', 'CELLPADDING', 'BORDERCOLOR'
		tags to customize your calendar's look.*/
		
		cal =  '<table cellpadding="0" cellspacing="0" width="100%" height="173"><!-- MSCellFormattingTableID="1" --><tr><td rowspan="2" colspan="2"><img alt="" src="http://www.matt.org/modules/images/MsoPnl_Cnr_tl_15F.gif" width="5" height="5"></td><td bgcolor="#C0C0C0" height="1"><img alt="" width="1" height="1" src="http://www.matt.org/modules/images/MsSpacer.gif"></td><td rowspan="2" colspan="2"><img alt="" src="http://www.matt.org/modules/images/MsoPnl_Cnr_tr_161.gif" width="5" height="5"></td></tr><tr><td bgcolor="#FFFFFF" nowrap height="4" width=100%><!-- MSCellFormattingType="header" --></td></tr><tr><td bgcolor="#C0C0C0"><img alt="" width="1" height="1" src="http://www.matt.org/modules/images/MsSpacer.gif"></td><td colspan="3"><!-- MSCellFormattingType="content" -->';
		cal += '<TABLE width=100% BORDER=0 CELLSPACING=0 CELLPADDING=2>' + TR_start;
		cal += '<TD background="http://www.matt.org/modules/images/' + strbackgroudn +  '" COLSPAN="' + DAYS_OF_WEEK + '" BGCOLOR="#EFEFEF">';
		cal += '<table border="0" width="100%" cellspacing="0" cellpadding="0"><tr><td width="2%" align=center><a onClick="Skip(\'-\')" style="cursor:hand" title="Last Month"><img border="0" src="http://www.matt.org/modules/images/leftarrow.gif"></a></td><td width="96%"><CENTER><B>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span id="moonid" style="vertical-align: middle"></span>&nbsp;&nbsp;' + month_of_year[month]  + '   ' + year + '</B>&nbsp;&nbsp;<span id="digitalclock" style="font-family: Arial; font-size: 10px; vertical-align:middle"></span>&nbsp;&nbsp;&nbsp;</CENTER></td><td width="2%" align=center><a onClick="Skip(\'+\')" style="cursor:hand" title="Next Month"><img border="0" src="http://www.matt.org/modules/images/rightarrow.gif"></a></td></tr></table>' + TD_end + TR_end;
		cal += TR_start;
		
		//   DO NOT EDIT BELOW THIS POINT  //
		
		// LOOPS FOR EACH DAY OF WEEK
		for(index=0; index < DAYS_OF_WEEK; index++)
		{
		
		// BOLD TODAY'S DAY OF WEEK
		if(weekday == index)
		cal += TD_start + '<B>' + day_of_week[index] + '</B>' + TD_end;
		
		// PRINTS DAY
		else
		cal += TD_start + day_of_week[index] + TD_end;
		}
		
		cal += TD_end + TR_end;
		cal += TR_start;
		
		// FILL IN BLANK GAPS UNTIL TODAY'S DAY
		for(index=0; index < Calendar.getDay(); index++)
		cal += TD_start + '  ' + TD_end;
		
		// LOOPS FOR EACH DAY IN CALENDAR
		for(index=0; index < DAYS_OF_MONTH; index++)
		{
		if( Calendar.getDate() > index )
		{
		  // RETURNS THE NEXT DAY TO PRINT
		  week_day =Calendar.getDay();
		
		  // START NEW ROW FOR FIRST DAY OF WEEK
		  if(week_day == 0)
		  cal += TR_start;
		
		  if(week_day != DAYS_OF_WEEK)
		  {
		
		  // SET VARIABLE INSIDE LOOP FOR INCREMENTING PURPOSES
		  var day  = Calendar.getDate();
		
		  // HIGHLIGHT TODAY'S DATE
		  if( today==Calendar.getDate() )
		  cal += highlight_start + '<a href="http://www.google.com/search?q=January+' + day + '+events+in+history" target="_blank"><TD background="http://www.matt.org/modules/images/' + strbackgroudn +  '" title="Events in History" WIDTH=20><B><CENTER>' + day + highlight_end + TD_end;
		
		  // PRINTS DAY
		  else
		  cal += TD_start + day + TD_end;
		  }
		
		  // END ROW FOR LAST DAY OF WEEK
		  if(week_day == DAYS_OF_WEEK)
		  cal += TR_end;
		  }
		
		  // INCREMENTS UNTIL END OF THE MONTH
		  Calendar.setDate(Calendar.getDate()+1);
		
		}// end for loop
		
		cal += '</TD></TR></TABLE><td bgcolor="#C0C0C0" height="162"><img alt="" width="1" height="1" src="http://www.matt.org/modules/images/MsSpacer.gif"></td></tr><tr><td rowspan="2" colspan="2"><img alt="" src="http://www.matt.org/modules/images/MsoPnl_Cnr_bl_163.gif" width="5" height="5"></td><td nowrap bgcolor="#FFFFFF" height="4"><!-- MSCellFormattingType="footer" --></td><td rowspan="2" colspan="2"><img alt="" src="http://www.matt.org/modules/images/MsoPnl_Cnr_br_165.gif" width="5" height="5"></td></tr><tr><td bgcolor="#C0C0C0" height="1"><img alt="" width="1" height="1" src="http://www.matt.org/modules/images/MsSpacer.gif"></td></tr><tr><td width="1"><img alt="" width="1" height="1" src="http://www.matt.org/modules/images/MsSpacer.gif"></td><td width="4"><img alt="" width="4" height="1" src="http://www.matt.org/modules/images/MsSpacer.gif"></td><td width="264"><img alt="" width="264" height="1" src="http://www.matt.org/modules/images/MsSpacer.gif"></td><td width="4"><img alt="" width="4" height="1" src="http://www.matt.org/modules/images/MsSpacer.gif"></td><td height="1" width="1"><img alt="" width="1" height="1" src="http://www.matt.org/modules/images/MsSpacer.gif"></td></tr></table>';
		
		//  PRINT CALENDAR
		//document.write(cal);
		var AllCalendar = document.getElementById('AllCalendar');
		AllCalendar.innerHTML = cal

		calctime();
		GetMoon();
}
//  End -->
</script>
<script>
function Defaults() {
		var Calendar = new Date();
		var year = Calendar.getFullYear();	    // Returns year
		var month = Calendar.getMonth();    // Returns month (0-11)
		document.when.month.value = month;
		document.when.year.value = year;
		Make_Calendar(year, month);
}

function Skip(Direction) {

	Selected_Month = document.when.month.value;
	Selected_Year = document.when.year.value;
		//alert (Selected_Month);
		//alert (Selected_Year);
   if (Direction == '+') {
      if (Selected_Month == 11) {
         Selected_Month = 0;
         Selected_Year++;
      }
      else {
         Selected_Month++;
      }
   }
   else {
      if (Selected_Month == 0) {
         Selected_Month = 11;
         Selected_Year--;
      }
      else {
         Selected_Month--;
      }
   }
   Make_Calendar(Selected_Year, Selected_Month);
   document.when.month.value = Selected_Month;
   document.when.year.value = Selected_Year;
}

window.onload=Defaults

//var Selected_Month = document.when.month.value;
//var Selected_Year = document.when.year.value;

</script>
</font>
<form name="when">
<input id=month type=hidden value="">
<input id=year type=hidden value="">
</form>
]]>
</Content>
</Module>
