/**
 * Calendar months collection
 */

var Backbone = require('backbone');

var Month = require('../models/month');

module.exports = Backbone.Collection.extend({
  model : Month,

  /**
   * Build calendar(add month models to collection)
   */
  populate : function () {
    var
      d = new Date(),   // current date
      m = d.getMonth(), // current month
      prec = 3,         // number of preceding months to show
      follow = 4,       // number of following months to show
      model, i, j;

    for(i = -prec; i <= follow; i += 1) {
      j = m + i; // month to show
      j = (j < 0) ? (12 + j) : j;  // handle if month < 0
      j = (j > 11) ? (j - 12) : j; // handle if month > 11

      this.add(new Month([], {
        date : new Date(d.getFullYear(), j, 1)
      }));
    }
  }

});

@@ -292,16 +292,26 @@
 ew Date(
+2015, 1, 1
 ),   // 
@@ -505,16 +505,19 @@
 el, i, j
+, k
 ;%0A%0A    f
@@ -549,24 +549,37 @@
 ; i += 1) %7B%0A
+      k = 0;%0A
       j = m 
@@ -604,26 +604,25 @@
 how%0A
+%0A
       
-j = 
+if
 (j %3C 0) 
 ? (1
@@ -621,106 +621,200 @@
  0) 
-? (12 + j) : j;  // handle if month %3C 0%0A      j = (j %3E 11) ? (j - 12) : j; // handle if month %3E 11
+%7B%0A        // Show month from the previous year%0A        k = -1;%0A        j = 12 + j;%0A      %7D else if(j %3E 11) %7B%0A        // Show month from the next year%0A        k = 1;%0A        j = j - 12;%0A      %7D
 %0A%0A  
@@ -881,16 +881,20 @@
 llYear()
+ + k
 , j, 1)%0A

Fix bug with calendar showing only current year months