var no = 15;                             /* number of snowflakes */
var speed = 80;                          /* the smaller, the faster move snowflakes */
var ns4b = (document.layers) ? 1 : 0;    /* Netscape4.x */
var b4up = (document.all) ? 1 : 0;       /* MSIE4, Opera5, Netccape5 */
var dx, xp, yp;                          /* coordinate and position variables */
var am, stx, sty;                        /* amplitude and step variables */
var snowobj, i;
var doc_width = 1000, doc_height = 700;  /* 800x600 screen-default */

if (ns4b) {
  doc_width  = self.innerWidth - 10;
  doc_height = self.innerHeight - 10;
} else if (b4up) {
  doc_width  = document.body.clientWidth - 10;
  doc_height = document.body.clientHeight - 10;
} else {
  doc_width  = window.innerWidth - 10;
  doc_height = window.innerHeight - 10;
  b4up = 1;
}

dx = new Array();
xp = new Array();
yp = new Array();
am = new Array();
stx = new Array();
sty = new Array();
snowobj = new Array();

function snowSetup(snowflake) {
  for (i = 0; i < no; i++) {                   /* iterate for every snowflake */
    dx[i] = 0;                                 /* set coordinate variables */
    xp[i] = Math.random() * (doc_width - 50);  /* set position variable x */
    yp[i] = Math.random() * doc_height;        /* set position variable y */
    am[i] = Math.random() * 20;                /* set amplitude variables */
    stx[i] = 0.02 + Math.random() / 10;        /* set step variables */
    sty[i] = 1.0 + Math.random();              /* set step variables */
    if (ns4b) {                                /* set layers */
      document.write("<layer name=\"flake" + i + "\" left=\"15\" top=\"15\" visibility=\"show\"><img src=\"" + snowflake + "\" border=\"0\"></layer\n>");
    } else if (b4up) {
      document.write("<div id=\"flake" + i + "\" style=\"position:absolute; z-index:" + i + "; visibility:visible; top:15px; left:15px;\"><img src=\"" + snowflake + "\" border=\"0\"></div>\n");
      snowobj[i] = eval (document.getElementById("flake" + i).style);
    }
  }
}

function snowNS() {           /* Netscape4 main animation function */
  for (i = 0; i < no; i++) {  /* iterate for every flake */
    yp[i] += sty[i] * 2;
    if (yp[i] > doc_height - 50) {
      xp[i] = Math.random() * (doc_width - am[i] - 30);
      yp[i] = 0;
      stx[i] = 0.02 + Math.random() / 10;
      sty[i] = 0.7 + Math.random();
    }
    dx[i] += stx[i];
    document.layers["flake"+i].top = yp[i] + "px";
    document.layers["flake"+i].left = xp[i] + am[i]*Math.sin(dx[i]) + "px";
  }
  setTimeout("snowNS()", speed);
}

function snowDocument() {    /* MSIE4, Opera5, Netscape5 main animation function */
  for (i=0; i < no; i++) {   /* iterate for every flake */
    yp[i] += sty[i] * 2;
    if (yp[i] > doc_height - 50) {
      xp[i] = Math.random() * (doc_width - am[i] - 30);
      yp[i] = 0;
      stx[i] = 0.02 + Math.random() / 10;
      sty[i] = 0.7 + Math.random();
    }
    dx[i] += stx[i];
    snowobj[i].top  = yp[i] + "px";
    snowobj[i].left = xp[i] + am[i] * Math.sin(dx[i]) + "px";
  }
  setTimeout("snowDocument()", speed);
}

function snowStart(snowflake) {
  snowSetup(snowflake);
  if (ns4b) {         // Netscape4
    snowNS();
  } else if (b4up) {  // MSIE4, Opera5, Netscape5
    snowDocument();
  }
}
