// JavaScript Document firework v 1.0 wymaga onload="diInit(...) w body
var diCount = 0;
var diArray = new Array();
  
function diHide(obj_id){
  obj=document.getElementById(obj_id);
  obj.setAttribute("di_run", "0");
  //obj.width=0;
  //obj.height=0;
  obj.style.visibility="hidden";
  //obj.src="";
  } 
function preImage( dir, duration ){
    this.img=new Image();
    this.duration = duration;
    this.img.src = dir;
    }   
function docImage(container,pre){
  this.pre = pre;
  this.el=document.createElement( "img" );
  this.el.style.position="absolute";
  this.el.src=pre.img.src;
  this.el.width=0;
  this.el.height=0;
  this.el.style.visibility="hidden";
  diArray[diCount]=this;
  this.el.id = "d_img_" + diCount;
  this.el.setAttribute("di_run","0");
  diCount++;
  container.appendChild(this.el);
  }
function diSetPos( x, y ){
  this.el.style.left = x+"px";
  this.el.style.top = y+"px";
  }
function diRandomPos( max_x, max_y ){
  this.diSetPos( Math.random()*max_x, Math.random()*max_y );
  }
function diDisplay(){
  if( this.el.getAttribute("di_run")=="1" || !this.pre.img.complete )
    return;
  this.el.setAttribute("di_run","1");
  this.el.width = this.pre.img.width;
  this.el.height = this.pre.img.height;
  this.el.style.visibility="visible";
 // this.el.src = this.pre.img.src;
  fun="diHide('"+this.el.id+"')";
  setTimeout( fun, this.pre.duration );
  }

  
docImage.prototype.diSetPos = diSetPos;
docImage.prototype.diRandomPos = diRandomPos;
docImage.prototype.diDisplay = diDisplay;
 
 function diRun(){
  for( i=0; i<diCount; i++ ){
    obj = diArray[i];
    if( obj.el.getAttribute("di_run" )!="1" ){
      if( Math.random() >0.5 ){
          obj.diRandomPos(900,50);
          obj.diDisplay();
          }
          }
    }
  setTimeout( "diRun()", 2000 );
  } 
  function diInit(x,y,w,h){
    e=document.createElement("div");
    e.style.position="absolute";
    e.style.left=x+"px";
    e.style.top=y+"px";
    e.style.width=w+"px";
    e.style.height=h+"px";
  //  e.style.display="block";
    e.style.overflow="hidden";
   /* e.style.borderWidth="1px";
    e.style.borderColor="yellow";
    e.style.borderStyle="solid";*/
    b=document.getElementById("b0");
    b.appendChild( e );
    i1=new preImage( "img/ani3.gif", 2000 );
    i2=new preImage( "img/ani03.gif", 2000 );
    obj=e;
    new docImage( obj,i1 );
    new docImage( obj,i1 );
    new docImage( obj,i1 );
    new docImage( obj,i2 );
    new docImage( obj,i2 );
    new docImage( obj,i2 );
    diRun();
    }

