Event.observe(window, 'resize', FG_fixfloats, false);
Event.observe(window, 'load', FG_fixfloats, false);

function FG_fixfloats() {
  lastParent = 0;
  galleryitems = document.getElementsByClassName("galleryitem");
  for (i=0; i<galleryitems.length; i++) {
    galleryitem = galleryitems[i];
    if(galleryitem.parentNode != lastParent) {
      lastTop = 0;
      rowHeight = 0;
      rowStart = i;
      lastParent = galleryitem.parentNode;
    }
    galleryitem.style.height = "auto";
    galleryitem.style.clear="none";
    if(galleryitem.offsetTop != lastTop) {
      galleryitem.style.clear="left";
      rowHeight = galleryitem.offsetTop - lastTop - (galleryitem.style.marginTop + galleryitem.style.marginBottom);
      for(j=rowStart;j<i;j++) {
        galleryitems[j].style.height = rowHeight+"px";
      }
      lastTop = galleryitem.offsetTop;
      rowStart = i;
    } 
  }
}
