var bG = {
  // initialisation function, call with load
  init: function() {
    if (!document.getElementById) return;        
    
    bG.wrapper = document.getElementById('wrapper');		
    	
    bG.leftheight = document.getElementById('left-col').offsetHeight;	
    bG.rightheight = document.getElementById('right-col').offsetHeight;	
    bG.contentheight = bG.leftheight;
    if (bG.rightheight > bG.leftheight) {
    	bG.contentheight = bG.rightheight;
    }
    bG.maxheight = bG.contentheight+90;

		//alert("content = "+bG.contentheight);	
		//alert("wrapper = "+bG.wrapper.offsetHeight);
		
		bG.addEvent(window, 'resize', bG.updateHeight, false);
		
		bG.updateHeight();
  },
  
  updateHeight: function() {
    bG.viewheight = bG.getBrowserHeight();
  	
		if (bG.viewheight > bG.maxheight) {
			var newheight = "100%";
		} else {
			var ht = bG.contentheight + 200;
			var newheight = ht+"px";
		}
		
		
	  bG.wrapper.style.height = newheight;
		//alert("newheight = "+newheight+" | wrapper = "+bG.wrapper.offsetHeight);
  },
  
  getBrowserHeight: function(){
		if (window.innerHeight){
			return window.innerHeight;}	
		else if (document.documentElement && document.documentElement.clientHeight != 0){
			return document.documentElement.clientHeight;	}
		else if (document.body){return document.body.clientHeight;}		
			return 0;
	},
  
  // function to add event listener, also caches events so they can be removed when the
	// page unloads to avoid memory leaks in IE
  addEvent: function(elm, evType, fn, useCapture) {
		// for W3C DOM complience
    if (elm.addEventListener) {
      elm.addEventListener(evType, fn, useCapture);
      return true;
    } 
		// for IE...
		else if (elm.attachEvent) {
      var r = elm.attachEvent('on' + evType, fn);
      //EventCache.add(elm, evType, fn);
      return r;
    } else {
			// for anyone else not IE or Moz... Safari etc
      elm['on' + evType] = fn;
    }
  }
  
	
}

bG.addEvent(window, 'load', bG.init, false);