(function($) {
  var rsv = {
    
    check_data_exists: function() {
      if (typeof reservations !== 'undefined') {
        rsv.run();
      }
    },
    
    run: function() {
      var _types = ['workshop', 'event'];
      $.each(_types, function(i, _type) {
        $.each(reservations[_type], function(i, num) {
          var _max = rsv.maximums[_type][i];
          var _status = {};
          if (num > Math.floor(_max / 3)) {
            _status = {'class': 'rsv-empty', 'text': '空席あり'};
          } else if (num <= Math.floor(_max / 3) && num > 0) {
            _status = {'class': 'rsv-lots-of', 'text': '残席わずか'};
          } else if (num == 0) {
            _status = {'class': 'rsv-max', 'text': '満席'};
          }
          $("#reservation-" + _type + "-" + i).addClass(_status['class']).text(_status['text']);
        });
      });
    },
    
    maximums: {
      "workshop": [8, 8, 8, 8, 8],
      "event": [20, 40]
    }
    
  };
  
  $(function() {
    rsv.check_data_exists();
  });
})(jQuery);
