var canvasWidth  = window.innerWidth  ? window.innerWidth  : document.documentElement.clientWidth;
var canvasHeight = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight;
var bgndWidth   = 0;
var bgndHeight  = 0;

function sizeWindow() {
   var h = document.getElementById("precontent").offsetHeight + document.getElementById("postcontent").offsetHeight;
   if (canvasHeight - h > 200 && canvasWidth >= document.body.offsetWidth) {
       document.getElementById("logo1").style.marginRight = "0";
       document.getElementById("contentarea").style.height = (canvasHeight - h) + "px";
       document.documentElement.style.overflowY = "hidden";
   } else {
       document.getElementById("logo1").style.marginRight = document.getElementById("contentarea").currentStyle
                             ? document.getElementById("contentarea").currentStyle.paddingRight
                             : getComputedStyle(document.getElementById("contentarea"),null).paddingRight;
       document.getElementById("contentarea").style.height = "auto";
       document.documentElement.style.overflowY = "scroll";
   }
   var pw = document.getElementById("lyrics").offsetWidth;
   var ph = document.getElementById("lyrics").offsetHeight;
   if (pw * bgndHeight < ph * bgndWidth) {
      document.getElementById("bgndimage").style.width  = (bgndWidth * ph / bgndHeight) + "px";
      document.getElementById("bgndimage").style.height = ph + "px";
   }
   else {
      document.getElementById("bgndimage").style.width  = pw + "px";
      document.getElementById("bgndimage").style.height = (bgndHeight * pw / bgndWidth) + "px";
   }
}
   
function orsz() {
   var w = window.innerWidth  ? window.innerWidth  : document.documentElement.clientWidth;
   var h = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight;
   if (w != canvasWidth || h != canvasHeight) {
      canvasWidth  = w;
      canvasHeight = h;
      sizeWindow();
   }
}

function ofld() {
   if (typeof AudioPlayer == "object") {
   	 AudioPlayer.setup("../wpap/player.swf", {width: 290, transparentpagebg: "yes", animation: "no", noinfo: "yes"});
   	 AudioPlayer.embed("wpap", {soundFile: "../recordings/" + encodeURIComponent(document.title.replace(/,/g,"")) + ".mp3"});
   }
}

function owld() {
   bgndWidth  = document.getElementById("bgndimage").scrollWidth;
   bgndHeight = document.getElementById("bgndimage").scrollHeight;
   ofld();
   sizeWindow();
   window.onresize = orsz;
}

window.onload = parent.frames.length ? ofld : owld;
