(function() {
  var currentPosition, gutterH, marginnotes, markerPosition, note, sidebar, _i, _len, _ref;

  sidebar = $(".leftcolumn");

  gutterH = 5;

  marginnotes = [];

  $(".marginmarker").each(function(index) {
    var notediv, vpos;
    $(this).removeClass("hidden");
    $(this).attr('id', 'marker' + index);
    $(this).contents().wrapAll('<div class="marginnote clearfix">');
    notediv = $(this).children(".marginnote");
    notediv.attr('id', 'note' + index);
    notediv.detach();
    $(this).text(".").addClass("placeholder");
    vpos = $(this).offset().top;
    return marginnotes.push([notediv, vpos]);
  });

  currentPosition = sidebar.offset().top;

  for (_i = 0, _len = marginnotes.length; _i < _len; _i++) {
    _ref = marginnotes[_i], note = _ref[0], markerPosition = _ref[1];
    if (markerPosition > currentPosition + gutterH) {
      sidebar.append($('<div class="marginspacer clearfix"> </div>').height(markerPosition - currentPosition));
      sidebar.append(note);
    } else {
      sidebar.append($('<div class="marginspacer clearfix"> </div>').height(gutterH));
      sidebar.append(note);
    }
    currentPosition = note.offset().top + note.height();
  }

}).call(this);

