function $id(id) {
  if (typeof id == 'string') {
    return document.getElementById(id);
  }
  return id;
}

function windowHeight() {
  return self.innerHeight || document.documentElement.clientHeight || document.body.clientHeight || 0;
}

function getY(o) {
  var y = 0;
  if (o.offsetParent) {
    while (o.offsetParent) {
      y += o.offsetTop; o = o.offsetParent;
    }
  }
  return y;
}

function footer() {
    var dif = 0;
	var h = windowHeight()
    var footer = $id('footer')
    var bottom = getY($id('bottom'))
    if ($id('sidebarbottom')) {
      var sidebar = getY($id('sidebarbottom'))
    } else {
      var sidebar = 0;
    }
	var fh = footer.clientHeight || footer.offsetHeight // todo: why does IE report 0 for clientHeight?
    if (sidebar > bottom) {
      if ((h - fh) < sidebar) {
        var dif = sidebar - bottom
      }
    }
	if (bottom != 0) {
		if (bottom < h - fh) {
        if (dif == 0) {
          footer.style.marginTop = ((h - fh)-bottom-3)+'px'
        } else {
          footer.style.marginTop = (dif)+'px'
        }
//          alert(bottom + ' - ' + sidebar + ' - ' + footer.style.marginTop)
        } else {
//          footer.style.marginTop = 0
          footer.style.marginTop = (dif)+'px'
//          alert(bottom + ' - ' + sidebar + ' - ' + footer.style.marginTop)
        }
	}
	footer.parentNode.style.visibility = 'visible'
}


