document.onselectstart = new Function("return false");
var nx, ny, nx2, ny2, W, H, WR, HR, M, M2, K = 0;

object   = new Array();
var N    = 24;
var zOOm = 1;

function picObj(N){
  this.obj = document.createElement("span");
  this.img = document.createElement("img");
  this.img.src = document.getElementById("doot").src;
  this.obj.appendChild(this.img);
  document.body.appendChild(this.obj);
  this.x   = 0;
  this.y   = 0;
  this.xx  = 0;
  this.yy  = 0;
  this.cx  = 0;
  this.cy  = 0;
  this.w   = 0;
  this.RSZ = function (){
    with (this) {
      w  = Math.round(Math.random() * M);
      x  = Math.round(Math.random() * nx);
      y  = Math.round(Math.random() * ny);
      xx = x;
      yy = y;
      cx = (x - nx2) / nx;
      cy = (y - ny2) / ny;
    }
  }
  this.createPic = function (){
    with (this) {
      x--;
      y--;
      w+=2;
      with(obj.style){
        left   = x;
        top    = y;
        width  = w;
        height = w;
      }
      with(img.style){
        left =  (-xx * WR) + (w * .5) + (zOOm * w * cx) - (zOOm * M2 * cx);
        top  =  (-yy * HR) + (w * .5) + (zOOm * w * cy) - (zOOm * M2 * cy);
      }
      if(w>=M){
        w = 4;
        h = 4;
        x = M/2+Math.round(Math.random() * (nx - M));
        y = M/2+Math.round(Math.random() * (ny - M));
        xx = x;
        yy = y;
        cx = (x - nx2) / nx;
        cy = (y - ny2) / ny;
        obj.style.left   = 3000;
        obj.style.zIndex = K++;
      }
    }
  }
}
function resize(){
  nx  = document.body.offsetWidth;
  ny  = document.body.offsetHeight;
  nx2 = nx / 2;
  ny2 = ny / 2;
  M2  = Math.sqrt((nx * ny) / N);
  M   = M2 * 2;
  WR  = (W * 2) / nx;
  HR  = (H * 2) / ny;
  for(var i in object)object[i].RSZ();
}
onresize = resize;

onload = function() {
  W   = document.getElementById("doot").width / 2;
  H   = document.getElementById("doot").height / 2;
  for(var i=0;i<N;i++)object[i] = new picObj(i);
  resize();
  setInterval(function(){for(var i in object)object[i].createPic()},32);

}
