// based on Javascript by Julie Baumler, BellaOnline, written by David Seidenberg, neohasid.org

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(2011,5,7);

// 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( '<p><span style="vertical-align:top;align:center;"><center>');
}


// display day of the Omer
if ( ( day_cnt < 49 ) && ( day_cnt >= 0 ) )
{
document.write( '<a href="http://neohasid.org/omer/count_the_omer" title="How to Count the Omer" style="text-decoration:none;">Tonight is <strong>day ' + cnt_tonit + ' </strong></a><br>');
}

else if ( day_cnt > 49) 
{
cnt_tonit= -cnt_tonit + 1

document.write( '<a href="http://neohasid.org/omer/count_the_omer" title="How to Count the Omer" style="text-decoration:none;">The count begins <br>in ' + cnt_tonit + ' days</a>');
cnt_tonit=-cnt_tonit
}

else if ( day_cnt == 49) 
{
document.write( '<a href="http://neohasid.org/omer/count_the_omer" title="How to Count the Omer" style="text-decoration:none;">The count begins tomorrow!<br></a>');
}




// 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( '<span title="Refresh page to update"><br>' + weekday[wkday.valueOf()] + ' ' + nowMonth + '/' + nowDay + '</small><br></span>')
}
*/
if ( day_cnt == 16 )
{
document.write( '<span title="Refresh page to update"><br>Happy Lag B\'Omer ~ ' + weekday[wkday.valueOf()] + ' ' + nowMonth + '/' + nowDay + '<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 );
}

// days til shavuot

if ( day_cnt > 49 )
{
document.write(  '<span style="font-size:1em;font-family:trebuchet ms;line-height:160%;"><em>&nbsp;<a href="http://neohasid.org/stoptheflood/sunblessing/" title="Prayers for Blessing the Sun" style="text-decoration:none;"><center><font color=#9C0606>Bless the sun April 8th!</font></center></a></em></span><span style="line-height:100%;"> ');
}

if ( day_cnt > 1 && day_cnt < 49 )
{
		
document.write(  '<br>' + chag_cnt + ' days til Shavuot ');

}
	

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!</span>')
}
else if ( (day_cnt < -1) && (day_cnt > -5) )
{
document.write( '<span style="vertical-align:top;">May your life be full<br> as the Omer is complete!<br></span>' )
}
else if ( day_cnt < -5 )
{
document.write( '<span style="vertical-align:top;align:center;"><center><a href="http://www.neohasid.org/stoptheflood/ramak/" title="Love Your Fellow Species" style="text-decoration:none;"><small>This is the essence:<br>to have compassion upon all beings<br><em>~ Moshe Cordovero</em></a></small></a></center></span>' )
}

if ( day_cnt == -1 )
{
document.write( '<br> Chag Sameach!</span>')
}


// display sefirah of day and week
{
 ofsefirah=String(" shebe-")
}
if ( sef_week == 1 )
{ ofsefirah=" shebi-"}

if ( (day_cnt < 49) && ( sef_week.valueOf() <= 6 ) && ( sef_week.valueOf() >= 0 ) && ( sef_day.valueOf() >= 0) )
{
document.write( '<br><em>' + sefirah[sef_day.valueOf()].valueOf() + ofsefirah + sefirah[sef_week.valueOf()].valueOf() + '</em>' )
}

//if (day_cnt < -2) { document.write( '<br>' ) }
if (day_cnt == -2) { document.write( 'Chag Sameach!<br>' ) }


{
document.write('<span style="font-size: 10px"><center>widget by <a href="http://www.neohasid.org" title="What\'s new: Bless the Sun, iPhone Omer">neohasid.org</a></center></span>');	
}

//end text centering
{
document.write( '</span></center></p>' )
}
