var bG = {
  // initialisation function, call with load
  init: function() {
    if (!document.getElementById) return;        
    
    bG.wrapper = document.getElementById('wrapper');
    bG.flashcontent = document.getElementById('flashcontent');
    bG.headercont = document.getElementById('headercont');


	
	bG.addEvent(window, 'scroll', bG.updateDims, false);
	bG.addEvent(window, 'resize', bG.updateDims, false);
	
	bG.updateDims();
  },
  
  updateDims: function() {
    bG.viewwidth = bG.getBrowserWidth();
    bG.viewheight = bG.getBrowserHeight();
	bG.contentheight = bG.wrapper.offsetHeight;
	bG.contentwidth = bG.headercont.offsetWidth;
  	
	if (bG.viewwidth > bG.headercont.offsetWidth) {
		var newwidth = "100%";
	} else {
		var newwidth = bG.contentwidth+"px";
	}

	if (bG.viewheight > bG.wrapper.offsetHeight) {
		//var newheight = "100%";
		var newheight = bG.viewheight+"px";
	} else {
		var newheight = bG.contentheight+"px";
	}	
	document.getElementById('content').style.width = newwidth;
	
	bG.flashcontent.style.height = newheight;
	bG.flashcontent.style.width = newwidth;
	
	//alert("vh"+bG.viewheight+"; h="+newheight+"; vw="+bG.viewwidth+"; w="+newwidth);
  },
  
  getBrowserWidth: function(){
		if (window.innerWidth){
			return window.innerWidth;}	
		else if (document.documentElement && document.documentElement.clientWidth != 0){
			return document.documentElement.clientWidth;	}
		else if (document.body){return document.body.clientWidth;}		
			return 0;
	},
  
  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);