
var originWinWidth;
var originWinHeight;
var originFlashWidth;
var originFlashHeight;
var originFlashRatio;
var originDeltaWidth;
var originDeltaHeight;

function onResizeInit(){
 var o=document.getElementById('flashObject');
 originWinWidth=getWindowWidth();
 originWinHeight=getWindowHeight();
 originFlashWidth=o.width;
 originFlashHeight=o.height;
 originFlashRatio=eval(originFlashWidth/originFlashHeight);
 originDeltaWidth=eval(originWinWidth-originFlashWidth);
 originDeltaHeight=eval(originWinHeight-originFlashHeight);
 //alert('init\noriginFlashRatio='+originFlashRatio);
}

function getWindowHeight(){
  var result = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    result = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    result = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    result = document.body.clientHeight;
  }
  return result;
}


function getWindowWidth(){
  var result = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    result = window.innerWidth;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    result = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    result = document.body.clientWidth;
  }
  return result;
}

function onResize(){
 var o=document.getElementById('flashObject');
 var e=document.getElementById('flashObjectEmbed');
 
 var newFlashWidth=getWindowWidth()-originDeltaWidth; 
 var newFlashHeight=getWindowHeight()-originDeltaHeight;

 //alert('originDeltaWidth='+originDeltaWidth);
 
 // Max Width
 if(newFlashWidth>1000){newFlashHeight=800;if(newFlashHeight>(getWindowHeight()-originDeltaHeight)){newFlashHeight=(getWindowHeight()-originDeltaHeight)}}

 if(newFlashWidth>newFlashHeight){
  newFlashWidth=Math.round(newFlashHeight*originFlashRatio);
 }else{
  newFlashHeight=Math.round(newFlashWidth/originFlashRatio);
 } 

 if(newFlashWidth<originFlashWidth){newFlashWidth=originFlashWidth;}
 if(newFlashHeight<originFlashHeight){newFlashHeight=originFlashHeight;}
 
 //alert('originW='+originDeltaWidth+'\nw='+newFlashWidth+'\nh='+newFlashHeight+'\nactualWinWidth='+getWindowWidth()+'\nactualWinHeight='+getWindowHeight());
 
 if(o){
 o.width=newFlashWidth;
 o.height=newFlashHeight;
 }
 
 if(e){
  e.width=newFlashWidth;
  e.height=newFlashHeight;
 }
 
 var ad=document.getElementById('gameAd');
 if(ad){
  if((getWindowWidth()-newFlashWidth)>180){
   ad.style.position='static';
   ad.style.visibility='visible';
  }else{
   ad.style.position='absolute';
   ad.style.visibility='hidden';
  }
 }
}

