// written 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
var lag= ""

// 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="139" title="Omer counter and Eco-hasid widget"><tr width="139"><td style="background:url(http://neohasid.org/i/compactsefirotbg.PNG); width: 137; height: 96; line-height:10pt; font-size:10pt; padding-top:2px; padding-bottom:0px; font-family:trebuchet ms, arial, san serif;"><center><p style="font-family:arial;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( '<span style="font-size:1.8em;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">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 in <br>' + cnt_tonit + ' days </font></a><br>');
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>');
}

// 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;"><font color=#9C0606>Bless the sun April 8th!</font></a></em></span><span style="line-height:100%;"> ');
}

if ( day_cnt > 1 && day_cnt < 49)
{
document.write(  '<br><span style="font-size:1.2em;font-family:trebuchet ms;line-height:160%;"><font color=#9C0606><em>&nbsp;&nbsp;' + chag_cnt + ' days til Shavuot</em></font></span><span style="line-height:100%;"> ');
}

// one day to go
else if ( day_cnt == 1 )
{
document.write( "<br>One day to go!")
}

// it's today
else if (day_cnt == 0)
{
document.write( "<br>Tomorrow is Shavuot!")
}

// one day ago
if ( day_cnt == -1 )
{
document.write( "Tonight is Shavuot!")
}

else if ( day_cnt == -3 )
{
document.write( '<span style="vertical-align:top;"><font color="purple">The Omer is complete!</font><br><strong></span>' )
}

if ( day_cnt == -1 )
{
document.write( '<br><font size="-1"> Chag Sameach!<br><br>')
}

if ( day_cnt == -2 )
{
document.write( ' May your life be full<br>as the Omer is complete! <br><big>Chag Sameach!</big>')
}


// 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;
    }
}

lag = String( "" )

//show weekday, date
if ( day_cnt == 16 )
{
lag = String( '<a href="http://neohasid.org/stoptheflood/rainbow_day/" style="text-decoration:none;"><font color="black"><u>Lag B\'Omer</u></font></a> ~ ' )
}

if ( ( day_cnt >= 0 ) )
{
document.write( '<span title="Refresh to update | Click for LAG liturgy"><br>' + lag + '</font><font color="purple">' + weekday[wkday.valueOf()] + ' ' + nowMonth + '/' + nowDay + '</small></font></span>')
}

// count by weeks

if ( ( day_cnt < 49 ) && ( day_cnt >= 0 ) && ( cnt_week <= 7 ) && ( cnt_week > 1 ) && (cnt_day == 0 ) )
{
document.write( '<font color=#9C0606> completing ' + cnt_week + ' weeks </font>');
}

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( '<font color="#44444"> Day ' + cnt_day + ' Week ' + cnt_week + '</font></span>');
}


// display sefirah of day and week
{
 ofsefirah=String("<font color=#44444><em> shebe</em>-</font>")
}
if ( sef_week == 1 )
{ ofsefirah="<font color=#44444><em> shebi</em>-</font>"}

if ( (day_cnt < 49) && ( sef_week.valueOf() <= 6 ) && ( sef_week.valueOf() >= 0 ) && ( sef_day.valueOf() >= 0) )
{
document.write( '<br><font color="black">' + sefirah[sef_day.valueOf()].valueOf() + ofsefirah + sefirah[sef_week.valueOf()].valueOf() + '</font></p>')
}

if ( day_cnt < -1 )
{
document.write( '<a href="http://www.neohasid.org/stoptheflood/ramak" title="Love Your Fellow Species" style="text-decoration:none;"><small><font color="black">This is the essence:<br>to have compassion<br>upon all beings<br><br><font color="blue"><em>~ Moshe Cordovero</em></font></small></a><br>' )
}

{
document.write( '<a href="http://neohasid.org" title="What\'s new: Bless the Sun, iPhone Omer"><img src="http://neohasid.org/i/neohasid-tiny-read2.PNG" style="border-style:none; padding-top:0px;padding-bottom:0px;" border="none" /></a><br><small><i></small></i>')
}

//end text centering
{
document.write( '</center></td></tr></table>' )
}