// Adds a clearing div every nth element
function tidyfloats (element, childTag, nth) {
  // Get a list of the elements that apply:
  el = document.getElementById (element);
  els = el.getElementsByTagName (childTag);
  els2 = [];
  for (var i=0, len=els.length; i<len; i++) {
    els2.push (els[i]);
  }
  // Create a clearing div
  var div = document.createElement ("div");
  div.style.clear    = "both";
  div.style.height   = "1px";
  div.style.overflow = "hidden";
  // Now loop over them (2x2 etc) and add in the clearing div
  for (var i=nth, len=els2.length; i<len; i+=nth) {
    el.insertBefore (div.cloneNode (false), els2[i]);
  }
  // Finally, add a clear to the end:
  el.appendChild (div);
}
