I think it's a problem with the Date.getDay() function. I believe it returns 0 for sundays which may be throwing your following logic off.
I had a quick look and found this:
Line 89:
firstDay = firstDate.getDay() + 0;
Ignore the fact that
+0
is doing absolutely nothing useful. All you need is a little condition on the line underneath it like:
firstDay = ( firstDay == 0 ) ? 7 : firstDay;