function balance() {

 var viewportwidth;
 var viewportheight;

 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight

 if (typeof window.innerWidth != 'undefined')
 {
      viewportwidth = window.innerWidth,
      viewportheight = window.innerHeight
 }

// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

 else if (typeof document.documentElement != 'undefined'
     && typeof document.documentElement.clientWidth !=
     'undefined' && document.documentElement.clientWidth != 0)
 {
       viewportwidth = document.documentElement.clientWidth,
       viewportheight = document.documentElement.clientHeight
 }

 // older versions of IE

 else
 {
       viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
       viewportheight = document.getElementsByTagName('body')[0].clientHeight
 }





  if(window.ActiveXObject) { /*IE*/
    if(event.type=='resize') { /*window was resized*/
      document.body.attachEvent('onmouseup',balance);
      return;
    } else { /*not a resize*/
      document.body.detachEvent('onmouseup',balance);
    }

  }


  if (window.innerHeight && window.scrollMaxY ) {
      pageWidth = window.innerWidth + window.scrollMaxX;
      pageHeight = window.innerHeight + window.scrollMaxY;
  } else if (document.body.scrollHeight > document.body.offsetHeight ) {
    pageWidth = document.body.scrollWidth;
    pageHeight = document.body.scrollHeight;
  } else {
    pageWidth = document.body.offsetWidth + document.body.offsetLeft; pageHeight = document.body.offsetHeight + document.body.offsetTop;
  }


  if(window.ActiveXObject) { /*IE*/
    var wwrap = document.getElementById("wrapper").offsetWidth;
    var wleft = document.getElementById("lefth").offsetWidth;
    var wmid = document.getElementById("midh").offsetWidth;
    var wright = document.getElementById("righth").offsetWidth;

  if((wleft+wmid+wright)>wwrap) {
    wmax = wwrap - (wleft+wright);
    document.getElementById("midh").style.width = wmax + "px";
    document.getElementById("impressumm").style.width = wmax + "px";

   /* alert(wmax);
    alert(document.getElementById("midh").offsetWidth);*/

    }

  }



  var left = document.getElementById("left").offsetHeight;
  var lefth = document.getElementById("lefth").offsetHeight;
  var mid = document.getElementById("mid").offsetHeight;
  var midh = document.getElementById("midh").offsetHeight;
  var right = document.getElementById("right").offsetHeight;
  var righth = document.getElementById("righth").offsetHeight;

/*  alert('left is ' + left);
  alert('lefth is ' + lefth);
  alert('mid is ' + mid);
  alert('midh is ' + midh);
  alert('right is ' + right);
  alert('righth is ' + righth);*/

  var max = Math.max(left,lefth,mid,midh,right,righth);

  if((max+30)<viewportheight) {
    max=viewportheight-30;
  }

  var maxinner = Math.max(left,mid,right);

  if((maxinner+30)<viewportheight) {
    maxinner=max;
  }


/*  alert('max is ' + max);*/

  document.getElementById("left").style.height = max - 114 + "px";
  document.getElementById("mid").style.height = max + 4 + "px";
  document.getElementById("midh").style.height = maxinner + "px";
  document.getElementById("right").style.height = max - 28 + "px";





  var hMenu = document.getElementById("impressuml").offsetHeight;
  var hContent = document.getElementById("impressumm").offsetHeight;
  var hFeatures = document.getElementById("impressumr").offsetHeight;
  var hMaxi = Math.max(hMenu,hContent,hFeatures);

  document.getElementById("impressuml").style.height = hMaxi + "px";
  document.getElementById("impressumm").style.height = hMaxi + "px";
  document.getElementById("impressumr").style.height = hMaxi + "px";

if(viewportheight>pageHeight) {
  pageHeight = viewportheight;

}
  document.getElementById("wrapper").style.height = pageHeight +hMaxi + "px";

  document.body.style.backgroundColor = "#1e1f3a";
}

function setup() {
  if(window.ActiveXObject) {
    document.body.onresize=balance;
  } else {
    window.onresize=balance;
  }
}

/*addLoadEvent(balance);*/

window.onresize=balance;

addLoadEvent(balance);
addLoadEvent(setup);

