function winW(){
  if (Boolean(window.innerWidth)) return window.innerWidth;
  else if (Boolean(document.body)) return document.body.clientWidth;
  else return 600;
}
function winH(){
  if (Boolean(window.innerHeight)) return window.innerHeight;
  else if (Boolean(document.body)) return document.body.clientHeight;
  else return 420;
}

var sizex = 75;
var sizey = 50;
var dx = 0.0;
var dy = 0.0;
var xp = 0;
var yp = 0;
var am = Math.random()*20;
var stx = 0.02 + Math.random()/10;
var sty = 0.02 + Math.random()/10;
var mx = 2.0 * (0.5 - Math.random());
var my = 2.0 * (0.5 - Math.random());
var timeout = 2 + Math.random() * 256;

function movebfly() {
  timeout--;
  if ((xp > winW() - sizex - mx - am && mx > 0.0) || (xp < mx + am && mx < 0.0)) mx = -1.0 * mx;
  if ((yp > winH() - sizey - my - am && my > 0.0) || (yp < my + am && my < 0.0)) my = -1.0 * my;
  xp += mx;
  yp += my;
  if (timeout < 1) {
    am = Math.random()*20;
    stx = 0.02 + Math.random()/10;
    sty = 0.02 + Math.random()/10;
    mx = 2.0 * (0.5 - Math.random());
    my = 2.0 * (0.5 - Math.random());
    timeout = 2 + Math.random() * 256;
  }
  dx += stx;
  if (dx > 6.283) dx -= 6.283;
  dy += sty;
  if (dy > 6.283) dy -= 6.283;
  if (Boolean(document.getElementById)) {
    document.getElementById("bfly").style.top = yp + am*Math.sin(dy) + "px";
    document.getElementById("bfly").style.left = xp + am*Math.sin(dx) + "px";
    setTimeout("movebfly()", 10);
  }
}
