historyOffset=0;
futureOffset=0;

$(document).ready(function(){
  $(".calendarbody").datepicker(
    $.extend({}, $.datepicker.regional["nl"], { 
        showStatus: true, 
        showOn: "both", 
        onSelect: function(date) {  
          openEpisodeUrl(date);
        },
        beforeShowDay: broadcastDays,
        firstDay: 7,
        showStatus: false,
        changeFirstDay: false,
        minDate: historyOffset,
        maxDate: futureOffset 
  }));
  
});


function broadcastDays(date) {
    for (i = 0; i < bcDays.length; i++) {
      if (date.getMonth() == bcDays[i][0] - 1 && date.getDate() == bcDays[i][1] && date.getFullYear() == bcDays[i][2]) {
        return [true, 'frutsel'];
      }
    }
  return [false, ''];
}

function openEpisodeUrl(date) {
  var splitDate = date.split(".");
  var day = parseInt(splitDate[0],10);
  var month = parseInt(splitDate[1],10);
  var year = parseInt(splitDate[2],10);
  for (i = 0; i < bcDays.length; i++) {
    if (month == bcDays[i][0] && day == bcDays[i][1] && year == bcDays[i][2]) {
      window.open(bcDays[i][3],'_self');
    }
  }
}

