// Fix Floats in Image Galleries Layout //

$(window).resize(FG_fixfloats);
$(document).ready(FG_fixfloats);

function FG_fixfloats() {
  lastParent = 0;
  galleryitems = $(".fixfloat_item");
  galleryitems.each(function(i){
    if(this.parentNode != lastParent) {
      lastTop = 0;
      rowHeight = 0;
      rowStart = i;
      lastParent = this.parentNode;
    }
    this.style.height = "auto";
    this.style.clear="none";
    if(this.offsetTop != lastTop) {
      this.style.clear="left";
      rowHeight = this.offsetTop - lastTop - (this.style.marginTop + this.style.marginBottom);
      for(j=rowStart;j<i;j++) {
        galleryitems.get(j).style.height = rowHeight+"px";
      }
      lastTop = this.offsetTop;
      rowStart = i;
    } 
  });
}
