
var imgwidth;
var imgheight;
var fsimage;
var shadow;

var opacity = 100;
function unfade() {
  if(opacity > 0) {
    opacity = opacity - 10;
    shadow.style.opacity = (opacity / 100.0);
    shadow.style.filter = 'alpha(opacity=' + opacity + ')';
    setTimeout('unfade()', 20);
  }
}

function onResize() {
  var docheight;
  var docwidth;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    docwidth = window.innerWidth;
    docheight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    docwidth = document.documentElement.clientWidth;
    docheight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    docwidth = document.body.clientWidth;
    docheight = document.body.clientHeight;
  }

  shadow.style.width = docwidth + 'px';
  shadow.style.height = docheight + 'px';

  var tgtwidth = imgwidth;
  var tgtheight = imgheight;
  while(tgtwidth < docwidth) {
    tgtwidth += 1;
    tgtheight = Math.floor((tgtwidth / imgwidth) * imgheight);
  }
  while(tgtheight < docheight) {
    tgtheight += 1;
    tgtwidth = Math.floor((tgtheight / imgheight) * imgwidth);
  }

  if(tgtwidth > docwidth) {
    fsimage.style.left = (0 - ((tgtwidth - docwidth) / 2)) + 'px';
  } else {
    fsimage.style.left = '0px';
  }
  if(tgtheight > docheight) {
    fsimage.style.top = (0 - ((tgtheight - docheight) / 2)) + 'px';
  } else {
    fsimage.style.top = '0px';
  }

  fsimage.width = tgtwidth;
  fsimage.height = tgtheight;
  if(fsimage.complete) {
    unfade();
  } else {
    fsimage.onload = unfade;
  }
}

function initImage() {
  var ipts = document.getElementsByTagName('INPUT');
  for(var i = 0; i < ipts.length; i++) {
    if(ipts[i].name == 'height') {
      imgheight = parseInt(ipts[i].value);
    } else if(ipts[i].name == 'width') {
      imgwidth = parseInt(ipts[i].value);
    }
  }
  fsimage = document.getElementById('fsimage');
  fsimage.style.position = 'absolute';
  
  shadow = document.getElementById('shadow');
  shadow.style.opacity = '1.0';
  shadow.style.filter = 'alpha(opacity=100)';

  document.getElementById('frontBackground').style.overflow = "hidden";
  window.onresize = onResize;
  onResize();
}

window.onload = initImage;
