// Small JS, originally based on the old 'snow script'
// added new functions for correct browser handling
// rewritten by Marco Paland, 05-08-24 

var no    =  3;           // number of simultaneous displayed objects
var speed =  2;           // the lower the number the faster the image moves
var snow  = new Array();

// image sources
snow[0]   = "bubble.gif"
snow[1]   = "bluebub.gif"
// snow[2]   = "bubble2.gif"

// simple browser detection
var ns4up = (document.layers) ? 1 : 0;  // browser sniffer
var ie4up = (document.all) ? 1 : 0;
var ns6up = (document.getElementById && !document.all) ? 1 : 0;

var dx, xp, yp;    // coordinate and position variables
var am, stx, sty;  // amplitude and step variables
var i, doc_width, doc_height;

doc_width  = getWindowSize()[0];
doc_height = getWindowSize()[1];

dx  = new Array();
xp  = new Array();
yp  = new Array();
am  = new Array();
stx = new Array();
sty = new Array();
j   = 0;

// init
for (i = 0; i < no; ++ i) {
   dx[i] = 0;                               // set coordinate variables
   xp[i] = Math.random()*(doc_width - 270) + 220;  // set position variables
   yp[i] = Math.random()*doc_height;
   am[i] = Math.random() * 20;              // set amplitude variables
   stx[i] = 0.02 + Math.random()/10;        // set step variables
   sty[i] = 0.7  + Math.random();           // set step variables
   if (ns4up) {                        // set layers
      if (i == 0) {
         document.write("<layer name=\"dot"+ i +"\" left=\"15\" top=\"15\" visibility=\"show\"><img src=\""+ snow[j] + "\" border=\"0\"></layer>");
      } else {
         document.write("<layer name=\"dot"+ i +"\" left=\"15\" top=\"15\" visibility=\"show\"><img src=\""+ snow[j] + "\" border=\"0\"></layer>");
      }
   } else if (ie4up||ns6up) {
      if (i == 0) {
         document.write("<div id=\"dot"+ i +"\" style=\"POSITION: absolute; Z-INDEX: "+ i +"VISIBILITY: visible; TOP: 15px; LEFT: 15px; width:1;\"><img src=\"" + snow[j] + "\" border=\"0\"></div>");
      } else {
         document.write("<div id=\"dot"+ i +"\" style=\"POSITION: absolute; Z-INDEX: "+ i +"VISIBILITY: visible; TOP: 15px; LEFT: 15px; width:1;\"><img src=\"" + snow[j] + "\" border=\"0\"></div>");
      }
   }
   if (j == (snow.length-1)) { j = 0; } else { j += 1; }
}


function getWindowSize() {
   var myWidth = 0, myHeight = 0;
   if ( typeof( window.innerWidth ) == 'number' ) {
      //Non-IE
      myWidth  = window.innerWidth;
      myHeight = window.innerHeight;
   } else if ( document.documentElement &&
     ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
      //IE 6+ in 'standards compliant mode'
      myWidth  = parseInt(document.documentElement.clientWidth);
      myHeight = parseInt(document.documentElement.clientHeight);
   } else if ( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
      //IE 4 compatible
      myWidth  = parseInt(document.body.clientWidth);
      myHeight = parseInt(document.body.clientHeight);
   }
   return [myWidth, myHeight ];
}

function getScrollXY() {
   var scrOfX = 0, scrOfY = 0;
   if ( typeof( window.pageYOffset ) == 'number' ) {
      //Netscape compliant
      scrOfY = window.pageYOffset;
      scrOfX = window.pageXOffset;
   } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
      //DOM compliant
      scrOfY = parseInt(document.body.scrollTop);
      scrOfX = parseInt(document.body.scrollLeft);
   } else if( document.documentElement &&
     ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
      //IE6 standards compliant mode
      scrOfY = parseInt(document.documentElement.scrollTop);
      scrOfX = parseInt(document.documentElement.scrollLeft);
   }
   return [ scrOfX, scrOfY ];
}

// main animation function
function Animate() {  
   for (i = 0; i < no; ++ i) {   // iterate for every dot
     yp[i] -= sty[i];
     if (yp[i] < -50) {
        xp[i] = Math.random()*(doc_width -am[i] - 270) + 220;
        yp[i] = doc_height - 50;
        stx[i] = 0.02 + Math.random() / 10;
        sty[i] = 0.7 + Math.random();
        doc_width  = getWindowSize()[0];
        doc_height = getWindowSize()[1];
     }
     dx[i] += stx[i];

     // modify position
     if (document.getElementById) {
        document.getElementById("dot"+i).style.top= yp[i] + getScrollXY()[1] + "px";
        document.getElementById("dot"+i).style.left=xp[i] + am[i]*Math.sin(dx[i]) + "px";
     } else if (document.all) {
        document.all["dot"+i].style.top  = yp[i] + getScrollXY()[1] + "px";
        document.all["dot"+i].style.left = xp[i] + am[i]*Math.sin(dx[i]) + "px";
     } else if (document.layers) {
        document.layers["dot"+i].top  = yp[i] + getScrollXY()[1] + "px";
        document.layers["dot"+i].left = xp[i] + "px"; 
     }					
   }
   setTimeout("Animate()", speed);
}

Animate();   // start it!

