// JavaScript Document

$(window).resize(FG_fixfloats);
$(document).ready(FG_fixfloats);

function FG_fixfloats() {
  lastParent = 0;
  galleryitems = $(".floating_container");
  galleryitems.each(function(i){
	//alert(this.offsetTop);
    if(this.parentNode != lastParent) {
      lastTop = 0;
      rowHeight = 0;
	sib_height = 0;
      rowStart = i;
      lastParent = this.parentNode;
    }
    this.style.height = "auto";
    this.style.clear="none";
	
	//Wenn zwischen dieser und letzter Reihe eine Überschrift lag, muß Reihenhöhe verringert werden
 
	//aus irgendeinem Grund für IE nur die Hälfte
	//if( -1 != navigator.userAgent.indexOf ("MSIE") ) {
	//	sib = this.previousSibling.previousSibling;
	//} else {
	//	sib = this.previousSibling.previousSibling.previousSibling.previousSibling;
	//}
	//if(sib) {
	//	if(sib.id=="main_headline") {
	//	sib_height=80;
	//	}
	//}
	//alert(sib_height);
	
	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;
	  sib_height=0;
    } 
  });
}
