/* Set the number of snowflakes (more than 30 - 40 not recommended) */
var snowMax = 30;

/* Set the colors for the snow. Add as many colors as you like */
var snowColor = new Array("#aaaacc", "#ddddff", "#ccccdd");

/* Set the fonts, that create the snowflakes. Add as many fonts as you like */
var snowType = new Array("Arial Black", "Arial Narrow", "Arial", "Times New Roman", "Comic Sans MS");

/* Set the letter that creates your snowflake (recommended:*) */
var snowLetter = "*";

/* Set the speed of sinking (recommended values range from 0.3 to 2) */
var sinkSpeed = 0.5;

/* Set the maximum size of your snowflakes */
var snowMaxSize = 24;

/* Set the minimum size of your snowflakes */
var snowMinSize = 9;

/*
	Set the snowing-zone
	Set 1 for all-over-snowing, set 2 for left-side-snowing
	Set 3 for center-snowing, set 4 for right-side-snowing,
	5 for centered snowingZone with a defined width
*/
var snowingZone = 5;

/* the width of the centered snowingZone */
var zoneWidth = 922;

/* the heigth of the general snowingZone (offset from top), set to -1 for full heigth */
var zoneHeigth = 124;

/**************************************************************************
CONFIGURATION ENDS HERE
**************************************************************************/

/* Do not edit below this line, unless you know what you're doing... ;) */

var snow = new Array();
var marginBottom;
var marginRight;
var timer;
var i_snow = 0;
var x_mv = new Array();
var crds = new Array();
var lftrght = new Array();
var browserinfos = navigator.userAgent;
var ie5 = document.all && document.getElementById && !browserinfos.match(/Opera/);
var ns6 = document.getElementById && !document.all;
var opera = browserinfos.match(/Opera/);
var firefox = browserinfos.match(/Firefox/);
var browserOK = ie5 || ns6 || opera || firefox;

/* generate random number in range */
function randommaker(range) {
   rand = Math.floor(range * Math.random());
   return rand;
}

/* initialise the snow array and parameters */
function initSnow() {
   if (ie5 || opera) {
      marginBottom = document.body.clientHeight;
      marginRight = document.body.clientWidth;
   }
   else if (ns6 || firefox) {
      marginBottom = window.innerHeight - 20;
      marginRight = window.innerWidth - 20;
   }
   
   marginBottom = (zoneHeigth == -1) ? marginBottom : zoneHeigth;
   
   var snowSizeRange = snowMaxSize - snowMinSize;
   for (i=0; i<=snowMax; i++) {
      crds[i] = 0;
      lftrght[i] = Math.random() * 15;
      x_mv[i] = 0.03 + Math.random() / 10;
      snow[i] = document.getElementById("s"+i);
      snow[i].style.fontFamily = snowType[randommaker(snowType.length)];
      snow[i].size = randommaker(snowSizeRange) + snowMinSize;
      snow[i].style.fontSize = snow[i].size + "px";
      snow[i].style.color = snowColor[randommaker(snowColor.length)];
      snow[i].sink = sinkSpeed * snow[i].size / 5;
      
      /* define the area to move the flakes in */
      if (snowingZone == 1) {snow[i].posX = randommaker(marginRight - snow[i].size)}
      if (snowingZone == 2) {snow[i].posX = randommaker(marginRight / 2 - snow[i].size)}
      if (snowingZone == 3) {snow[i].posX = randommaker(marginRight / 2 - snow[i].size) + marginRight / 4}
      if (snowingZone == 4) {snow[i].posX = randommaker(marginRight / 2 - snow[i].size) + marginRight / 2}
      if (snowingZone == 5) {
      	marginwidth = marginRight / 2 - zoneWidth / 2;
      	snow[i].posX = randommaker(zoneWidth) + marginwidth - snow[i].size;
      }
      snow[i].posY = randommaker(2 * marginBottom - marginBottom - 2 * snow[i].size);
      snow[i].style.left = snow[i].posX + "px";
      snow[i].style.top = snow[i].posY + "px";
   }
   movesnow();
}

/* move the snow */
function movesnow() {
   for (i=0; i<=snowMax; i++) {
      crds[i] += x_mv[i];
      snow[i].posY += snow[i].sink;
      snow[i].style.left = snow[i].posX + lftrght[i] * Math.sin(crds[i]) + "px";
      snow[i].style.top = snow[i].posY + "px";

      if (snow[i].posY >= marginBottom - 2 * snow[i].size || parseInt(snow[i].style.left) > (marginRight - 3 * lftrght[i])) {
         if (snowingZone == 1) {snow[i].posX = randommaker(marginRight - snow[i].size)}
         if (snowingZone == 2) {snow[i].posX = randommaker(marginRight / 2 - snow[i].size)}
         if (snowingZone == 3) {snow[i].posX = randommaker(marginRight / 2 - snow[i].size) + marginRight / 4}
         if (snowingZone == 4) {snow[i].posX = randommaker(marginRight / 2 - snow[i].size) + marginRight / 2}
         if (snowingZone == 5) {
	      	marginwidth = marginRight / 2 - zoneWidth / 2;
	     	snow[i].posX = randommaker(zoneWidth) + marginwidth - snow[i].size;
	     }
         snow[i].posY = 0;
      }
   }
   var timer = setTimeout("movesnow()", 50);
}

/* draw the flakes */
for (i=0; i<=snowMax; i++) {
   document.write("<span id='s" + i + "' style='position:absolute;top:-" + snowMaxSize + "px'>" + snowLetter + "</span>");
}

/* init the snow */
if (browserOK) {
   window.onload = initSnow();
}
