// Original:  Altan (snow@altan.hr)
// Heavily modified by phil.hobson@hcidata.co.uk)
// Web Site:  http://www.altan.hr/snow

// This script and many more are available free online at
// The JavaScript Source!! http://javascript.internet.com


var myDate = new Date;
var dayOfMonth  = myDate.getDate();	// 1-31
var monthOfYear =  myDate.getMonth();	// 0-11

var no = 0; // Number of images

if (monthOfYear == 11) {
	no = dayOfMonth+10;
}
else if (monthOfYear == 0) {
	no = 50-dayOfMonth;
}

var speed = 18; // delay between movement (milliseconds)
var imageParms = 'SRC="/images/snowflak.gif" WIDTH="30" HEIGHT="31" BORDER="0"';

var ns4up = (document.layers) ? 1 : 0;  // browser sniffer
var ie4up = (document.all) ? 1 : 0;

// Need to cater for Firefox .... if (! ns4up && ! ie4up && navigator.vendor) { ie4up = (navigator.vendor =='Firefox') ? 1:0 }

var dx, xp, yp;    // coordinate and position variables
var am, stx, sty;  // amplitude and step variables
var i, doc_width = 800, doc_height = 600;
if (ns4up) {
   doc_width = self.innerWidth;
   doc_height = self.innerHeight;
}
else if (ie4up) {
   doc_width = document.body.clientWidth;
   doc_height = document.body.clientHeight;
}
dx = new Array();
xp = new Array();
yp = new Array();
am = new Array();
stx = new Array();
sty = new Array();
for (i = 0; i < no; ++ i) {
   setInitialPosition(i);
   if (ns4up) {                      // set layers
      document.write("<layer name=\"dot"+ i +"\" left=\"15\" ");
      document.write("top=\"15\" visibility=\"show\"><img " + imageParms + ">");
      document.write("</layer>");
   }
   else if (ie4up) {
      document.write("<div id=\"dot"+ i +"\" style=\"POSITION: ");
      document.write("absolute; Z-INDEX: "+ i +"; VISIBILITY: ");
      document.write("visible; TOP: 15px; LEFT: 15px;\"><img " + imageParms + ">");
      document.write("</div>");
   }
}
function setInitialPosition(index) {
   dx[index] = 0;                        // set coordinate variables
   am[index] = Math.random()*20;         // set amplitude variables
   xp[index] = Math.random()*(doc_width-am[index]-30);  // set position variables
   yp[index] = Math.random()*doc_height;
   stx[index] = 0.02 + Math.random()/10; // set step variables
   sty[index] = 0.7 + Math.random();     // set step variables
}
function snowNS() {  // Netscape main animation function
   for (i = 0; i < no; ++ i) {  // iterate for every dot
      yp[i] += sty[i];
      if (yp[i] > doc_height-50) {
         setInitialPosition(i);
         yp[i] = 0;  // start new images falling from top of screen
         doc_width = self.innerWidth;
         doc_height = self.innerHeight;
      }
      dx[i] += stx[i];
      document.layers["dot"+i].top = yp[i];
      document.layers["dot"+i].left = xp[i] + am[i]*Math.sin(dx[i]);
   }
   setTimeout("snowNS()", speed);
}

function snowIE() {  // IE main animation function
   for (i = 0; i < no; ++ i) {  // iterate for every dot
      yp[i] += sty[i];
      if (yp[i] > doc_height-50) {
         setInitialPosition(i);
         yp[i] = 0;  // start new images falling from top of screen
         doc_width = document.body.clientWidth;
         doc_height = document.body.clientHeight;
      }
      dx[i] += stx[i];
      document.all["dot"+i].style.pixelTop = yp[i];
      document.all["dot"+i].style.pixelLeft = xp[i] + am[i]*Math.sin(dx[i]);
   }
   setTimeout("snowIE()", speed);
}

if (no > 0)
{
if (ns4up) {
   snowNS();
}
else if (ie4up) {
   snowIE();
}
}
