var bg =$('bgImg');
var interval = 500;
var minWidth = 990;

function checkWindowSize() {
  var w = -1;
  var h = -1;
  // get the width
  if (window.innerWidth)
  { w = window.innerWidth; }
  else if (document.documentElement && document.documentElement.clientWidth != 0)
  { w = document.documentElement.clientWidth; }
  else if (document.body)
  { w = document.body.clientWidth; }
  // get the height
  if (window.innerHeight)
  { h = window.innerHeight; }
  else if (document.documentElement && document.documentElement.clientHeight != 0)
  { h = document.documentElement.clientHeight; }
  else if (document.body)
  { h = document.body.clientHeight; }
  
  //update...
  if (w > -1){
    if (w < minWidth) { w = minWidth; }
    bg.setStyle('width', w  );
  }
} 

// Start the resizing only if target found
if (bg) 
{
  checkWindowSize();
  checkWindowSize.periodical(interval, bg); 
}
