// created by David Seidenberg, neohasid.org, based on Javascript by Julie Baumler, BellaOnline 

var millisecs_per_day=86400000
// set countdown time in milliseconds
// put desired day as arguments to Date.UTC 
// in the order: year, month (January is 0), day of month, offset from GMT

var countdown_time=Date.UTC(2010,4,18);

// get the current time and convert to milliseconds
var now=new Date();

// convert to msec since Jan 1 1970
var localTime=now.getTime();

// obtain local UTC offset and convert to msec
var localOffset=now.getTimezoneOffset() * 60000;

var countdown_time=countdown_time + localOffset;

var now_millisecs=now.valueOf();

// day counting and week counting: days til, days counted, weeks and remainder
var day_cnt= Math.ceil((countdown_time - now_millisecs)/86400000 - 1)

var theHour = now.getHours();
	
var hoursLeft = 24 - theHour - 1;

var nowMonth = now.getMonth() + 1;
	
var nowDay = now.getDate();		
	
	
if (hoursLeft == 23 || hoursLeft == 22)
 
	{
	day_cnt = day_cnt + 1;
	
}

var cnt_tonit= Math.ceil( 49 - day_cnt.valueOf() )
var cnt_week= Math.ceil(cnt_tonit.valueOf()/7)
var cnt_day= Math.ceil((cnt_tonit.valueOf() + 21) % 7 )
var chag_cnt= day_cnt + 1

// day of the week & date 
var wkday=now.getDay()
var weekday=new Array()
weekday[0]="Sun"
weekday[1]="Mon"
weekday[2]="Tues"
weekday[3]="Wed"
weekday[4]="Thurs"
weekday[5]="Fri"
weekday[6]="Sat"

//sefirot by number and name
var sef_week= Math.ceil( cnt_week - 1 )
var sef_day= Math.ceil( (cnt_day + 13) % 7 )

var sefirah=new Array()
sefirah[0]="Chesed"
sefirah[1]="Gevurah"
sefirah[2]="Tiferet"
sefirah[3]="Netzach"
sefirah[4]="Hod"
sefirah[5]="Yesod"
sefirah[6]="Malkhut"

{
document.write( '<table width="180" title="Eco-Hasid Omer-counter widget"><tr width="178"><td style="background:url(http://neohasid.org/i/sefirotbg3.PNG); width: 178; height: 116; line-height:10pt; font-size:10pt; padding-top:0px; padding-bottom:0px; font-family:arial, sans serif;"><center><p style="font-size:.8em;font-style:strong;text-decoration:none;margin:0px;"><strong><font color="black">' )
}


// display day of the Omer
if ( ( day_cnt < 49 ) && ( day_cnt >= 0 ) )
{
document.write( '<font color="#44444"><span style="font-size:1.5em;line-height:110%;"><a href="http://neohasid.org/resources/count_the_omer/" title="How to count the omer" style="text-decoration:none;"><font color="black"> Tonight is day ' + cnt_tonit + '</font></a></span>');
}

else if ( day_cnt > 49) 
{
cnt_tonit= -cnt_tonit + 1

document.write( '<a href="http://neohasid.org/resources/count_the_omer/" title="How to count the omer" style="text-decoration:none;"><font color="black">The count begins <br>in ' + cnt_tonit + ' days</font></a>');
cnt_tonit=-cnt_tonit
}

else if ( day_cnt == 49) 
{
document.write( '<a href="http://neohasid.org/resources/count_the_omer/" title="How to count the omer" style="text-decoration:none;"><font color="black">The count begins tomorrow!</font></a><br>');
}

// sun blessing date
if ( day_cnt > 49 )
{
		
document.write(  '<br><span style="font-size:1.2em;font-family:trebuchet ms, arial, sans serif; line-height:160%;"><em>&nbsp;<a href="http://neohasid.org/stoptheflood/sunblessing/" title="Prayers for Blessing the Sun" style="text-decoration:none;"><font color=#9C0606>Bless the sun on April 8th!</font></a></em></span>');

}

// days til shavuot
if ( day_cnt > 1 && day_cnt < 49)
{
		
document.write(  '<br><span style="font-size:1.2em;font-family:trebuchet ms, arial, sans serif; line-height:160%;"><font color=#9C0606><em>&nbsp;&nbsp;' + chag_cnt + ' days til Shavuot </em></font></span>');

}
	

else if ( day_cnt == 1 )
{
// one day to go
document.write( "<br>One day to go!")
}
else if (day_cnt == 0)
{
// it's today
document.write( "<br>Tomorrow is Shavuot!")
}
else if ( day_cnt == -1 )
{
// one day ago
document.write( '<span style="font-size:10pt; line-height:11pt;">Tonight is Shavuot!')
}
else if ( day_cnt < -1 )
{
document.write( '<span style="text-align:top; color:black;"><a href="http://www.neohasid.org/stoptheflood/ramak" title="Love Your Fellow Species" style="text-decoration:none;"><font color="black">This is the essence:<br>compassion <em>chemlah</em><br>upon all beings<small><br><font color="blue"><em>~ Moshe Cordovero</em></font></a></span> <span style="line-height:4pt;"><font color="purple"></em></small></font></a></span>' )
}

if ( day_cnt == -1 )
{
document.write( '<br> Chag Sameach!</span>')
}


// if it's before 2Am show that night's date (i.e. previous date)
if (hoursLeft == 23 || hoursLeft == 22) 
		{
		wkday = wkday - 1;
		}

if (wkday < 0)
		{
			wkday = 6;
		}
	

if ( (hoursLeft == 23 || hoursLeft == 22)
 && ( nowDay > 1 ) )
		{	
		nowDay = nowDay - 1;

		}

else if ( (hoursLeft == 23 || hoursLeft == 22)
 && ( nowDay == 1 ) )
{
		if (nowMonth == 5) 
		{
			nowDay = 30;
			nowMonth = 4;
		}
		else if (nowMonth == 6)
		{
			nowDay = 31;
			nowMonth = 5;
		}
}

//show weekday, date
if ( day_cnt != 16 )
{
document.write( '<a href="http://www.neohasid.org" style="text-decoration:none;"><span style="line-height:12pt; color:purple;" title="Refresh page to update"><br>' + weekday[wkday.valueOf()] + ' ' + nowMonth + '/' + nowDay + '</small></span></a><br>')
}


if ( day_cnt == 16 )
{
document.write( '<span title="Refresh page to update"><br>Happy Lag B\'Omer ~ ' + weekday[wkday.valueOf()] + ' ' + nowMonth + '/' + nowDay + '</small><br></span>' )
}

// count by weeks

if ( ( day_cnt < 49 ) && ( day_cnt >= 0 ) && ( cnt_week <= 7 ) && ( cnt_week > 1 ) && (cnt_day == 0 ) )
{
document.write( ' completing ' + cnt_week + ' weeks ');
}

else if ( ( day_cnt < 49 ) && ( day_cnt >= 0 ) && ( cnt_week <= 7 ) && ( cnt_week == 1 ) && (cnt_day == 0 ) )
{
document.write( ' completing ' + cnt_week + ' week ');
}

else if ( ( day_cnt < 49 ) && ( day_cnt >= 0 ) && ( cnt_week <= 7 ) && ( cnt_week >= 1 ) && (cnt_day != 0 ) )
{
document.write( ' Day ' + cnt_day + ' of Week ' + cnt_week );
}


// display sefirah of day and week
{
 ofsefirah=String("<em> shebe</em>-")
}
if ( sef_week == 1 )
{ ofsefirah="<em> shebi</em>-"}

if ( (day_cnt < 49) && ( sef_week.valueOf() <= 6 ) && ( sef_week.valueOf() >= 0 ) && ( sef_day.valueOf() >= 0) )
{
document.write( '<br>' + sefirah[sef_day.valueOf()].valueOf() + ofsefirah + sefirah[sef_week.valueOf()].valueOf() )
}

if (day_cnt < -2) { document.write( '<br>' ) }
if (day_cnt == -2) { document.write( 'Chag Sameach!<br>' ) }

{
document.write('</span></p>')
}


{
document.write( '<a href="http://neohasid.org"><img src="http://neohasid.org/i/neohasid-tiny-read2.PNG" title="What\'s new: Bless the Sun, iPhone Omer" alt="neohasid.org" style="border-style:none; float:bottom; padding-top:0px;padding-bottom:0px;" border="none"></a><br><small><i></small></i>' )
}
//<br><small>May your life be full<br> as the Omer is complete!</small>' )
	


//end text centering
{
document.write( '</center></td></tr></table>' )
}

