
/**
 * N is the number of comments to include. The rest will be hidden.
 */
var N = 5;

/*
  return a random permutation of the numbers from 0 to n-1.
  This is an inside-out fisher-yates shuffle.
  http://en.wikipedia.org/wiki/Fisher-Yates
*/
function shuffle(n) {
  var l = [0];
  var i, j;
  for (i = 1; i < n - 1; i++) {
    j = Math.floor(Math.random() * (i+1))
      l[i] = l[j];
    l[j] = i;
  }
  return l;
}

window.addEventListener("load", function(){
    var cl = document.getElementById('commentList');
    cl.setAttribute('style', 'display:none');
    var items = cl.getElementsByTagName('li');
    var l = shuffle(items.length);
    var ul = document.createElement("ul");
    ul.setAttribute("class", cl.getAttribute("class"));
    for(var i = 0; i < N; i++) {
        if(items[l[i]] != null) {
            ul.appendChild(items[l[i]]);
        }
    }
    cl.parentNode.replaceChild(ul, cl);
});

