var app = app || {};

var Keyboard = Backbone.Collection.extend({
  model: app.Key,
});

app.Keyboard = new Keyboard();

app.KeyboardView = Backbone.View.extend({
  el: $('#keyboard'),

  initialize: function() {
    this.listenTo(app.Keyboard, 'reset', this.render);

    app.Keyboard.reset(this.createKeys());
  },

  createKeys: function(){
    var whiteKeyWidth = app.KeyView.whiteKeyWidth;
    var blackKeyWidth = app.KeyView.blackKeyWidth;
    var octaves = 3;

    var i = 0, keys = [];

    for(var index = 0; index < 7 * octaves; index++) {
      i = keys.push(createWhiteKey(index, this.whiteKeyWidth));

      if(hasBlackKey(index)) {
        i = keys.push(createBlackKey(index, this.blackKeyWidth));
      }
    }

    return keys;

    function createWhiteKey(index) {
      return createKey(index * whiteKeyWidth, 'white');
    }

    function createBlackKey(index) {
      return createKey((index + 1) * whiteKeyWidth - blackKeyWidth / 2, 'black');
    }

    function createKey(x, color) {
      return new app.Key({x: x, color: color, id: i});
    }

    function hasBlackKey(index){
      var i = index % 7;
      return i !== 2 && i !== 6;
    }
  },

  render: function() {
    app.Keyboard.where({color: 'white'}).forEach(function(model) {
      var view = new app.WhiteKeyView({model: model}, model.get('x'));
      $('#keyboard').append( view.render().el );
    });

    app.Keyboard.where({color: 'black'}).forEach(function(model) {
      var view = new app.BlackKeyView({model: model}, model.get('x'));
      $('#keyboard').append( view.render().el );
    });

    return this;
  },
});

Backbone.sync = function(method, model) {
  console.log("I've been passed " + method + " with " + JSON.stringify(model));
};
@@ -311,16 +311,65 @@
 ;%0A  %7D,%0A%0A
+  keyCount: function() %7B%0A    return 3 * 7;%0A  %7D,%0A%0A
   create
@@ -386,16 +386,16 @@
 tion()%7B%0A
-
     var 
@@ -491,29 +491,8 @@
 dth;
-%0A    var octaves = 3;
 %0A%0A  
@@ -555,15 +555,23 @@
 7 * 
-octaves
+this.keyCount()
 ; in
@@ -1611,24 +1611,95 @@
 );%0A    %7D);%0A%0A
+    $('#keyboard').width(this.keyCount() * app.KeyView.whiteKeyWidth)%0A%0A
     return t

Set width