// JavaScript Document
var bgimg = document.getElementById('bgimg');
var bgdiv = document.getElementById('bgdiv');

function bgresize(){ 
  var screenx = 0;
  var screeny = 0
  if (self.innerHeight)  {
      screenx = self.innerWidth;
      screeny = self.innerHeight;
  }
  // Explorer 6 Strict Mode
  else if (document.documentElement && document.documentElement.clientHeight) {
      screenx = document.documentElement.clientWidth;
      screeny = document.documentElement.clientHeight;
  }
  // other Explorers
  else if (document.body) {
      screenx = document.body.clientWidth;
      screeny = document.body.clientHeight;
  }    
  var ratiow = screenx / bgimg.width;
  var ratioh = screeny / bgimg.height;  
  var ratio;
  //alert (" H"+screeny+" B"+screenx+" rh"+ratioh+" rb"+ratiow+" => "+ratio);
  (ratiow < ratioh) ? ratio = ratioh : ratio = ratiow; 
  bgimg.height *=  ratio;
  bgdiv.style.height = screeny;
}

bgimg.onload = bgresize;
window.onresize = bgresize;
window.onload = bgresize;