// CREDITS:
// Modified to be more cross-toolkit compatible and more self-contained by Daniel Llewellyn (http://thehoneymonster.net/)
// Snowmaker Copyright (c) 2003 Peter Gehrig. All rights reserved.
// Distributed by http://www.hypergurl.com
// Permission given to use the script provided that this notice remains as is.

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

// 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","Times","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.6;

// Set the maximal-size of your snowflaxes
var snowmaxsize = 22;

// Set the minimal-size of your snowflaxes
var snowminsize = 8;

// 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
var snowingzone = 1;

var snow = {
	prev_onload: null,
	snow: new Array(),
	marginbottom: 0,
	marginright: 0,
	timer: null,
	i: 0,
	x_mv: new Array(),
	crds: new Array(),
	lftrght: new Array(),
	browserinfos: navigator.userAgent,
	
	randommaker: function(range) { return Math.floor(range * Math.random()); },
	init: function() {
		if (snow.prev_onload) { snow.prev_onload(); }
		
		/*
		if (snow.ie5 || snow.opera) {
			snow.marginbottom = document.body.clientHeight;
			snow.marginright = document.body.clientWidth;
		} else if (snow.ns6) {
			snow.marginbottom = window.innerHeight;
			snow.marginright = window.innerWidth;
		} else { return; }
		*/
		// taken from http://siderite.blogspot.com/2007/05/cross-browser-inner-width-and-height-of.html
		var h = 0;
		if (window.document.innerHeight > h)					h = window.document.innerHeight;
		if (window.document.documentElement.clientHeight > h)	h = window.document.documentElement.clientHeight;
		if (window.document.body.clientHeight > h)				h = window.document.body.clientHeight;
		snow.marginbottom = h;
		
		var w = 0;
		if (window.document.innerWidth > w)						w = window.document.innerWidth;
		if (window.document.documentElement.clientWidth > w)	w = window.document.documentElement.clientWidth;
		if (window.document.body.clientWidth > w)				w = window.document.body.clientWidth;
		snow.marginright = w;
		// end taken from http://siderite.blogspot.com/2007/05/cross-browser-inner-width-and-height-of.html
		
		var snowsizerange = snowmaxsize - snowminsize;
		for (i = 0; i < snowmax; i++) {
			snow.crds[i] = 0;                      
	    	snow.lftrght[i] = Math.random() * 15;         
	    	snow.x_mv[i] = 0.03 + Math.random() / 10;
			snow.snow[i] = document.getElementById("snow"+i);
			snow.snow[i].style.fontFamily = snowtype[snow.randommaker(snowtype.length)];
			snow.snow[i].size = snow.randommaker(snowsizerange)+snowminsize;
			snow.snow[i].style.fontSize = snow.snow[i].size;
			snow.snow[i].style.color = snowcolor[snow.randommaker(snowcolor.length)];
			snow.snow[i].sink = sinkspeed * snow.snow[i].size / 5;
			if (snowingzone == 1) { snow.snow[i].posx = snow.randommaker(snow.marginright - snow.snow[i].size); }
			if (snowingzone == 2) { snow.snow[i].posx = snow.randommaker(snow.marginright / 2 - snow.snow[i].size); }
			if (snowingzone == 3) { snow.snow[i].posx = snow.randommaker(snow.marginright / 2 - snow.snow[i].size) + snow.marginright / 4; }
			if (snowingzone == 4) { snow.snow[i].posx = snow.randommaker(snow.marginright / 2 - snow.snow[i].size) + snow.marginright / 2; }
			snow.snow[i].posy = snow.randommaker(6 * snow.marginbottom - snow.marginbottom - 6 * snow.snow[i].size);
			snow.snow[i].style.left = snow.snow[i].posx + 'px';
			snow.snow[i].style.top = snow.snow[i].posy + 'px';
		}
		snow.move();
	},
	move: function() {
		for (i = 0; i < snowmax; i++) {
			snow.crds[i] += snow.x_mv[i];
			snow.snow[i].posy += snow.snow[i].sink;
			snow.snow[i].style.left = (snow.snow[i].posx + snow.lftrght[i] * Math.sin(snow.crds[i])) + 'px';
			snow.snow[i].style.top = (snow.snow[i].posy) + 'px';
			
			if (snow.snow[i].posy >= snow.marginbottom - snow.snow[i].size || parseInt(snow.snow[i].style.left) > (snow.marginright - 3 * snow.lftrght[i])) {
				if (snowingzone == 1) { snow.snow[i].posx = snow.randommaker(snow.marginright - snow.snow[i].size); }
				if (snowingzone == 2) { snow.snow[i].posx = snow.randommaker(snow.marginright / 2 - snow.snow[i].size); }
				if (snowingzone == 3) { snow.snow[i].posx = snow.randommaker(snow.marginright / 2 - snow.snow[i].size) + snow.marginright / 4; }
				if (snowingzone == 4) { snow.snow[i].posx = snow.randommaker(snow.marginright / 2 - snow.snow[i].size) + snow.marginright / 2; }
				snow.snow[i].posy = 0;
			}
		}
		snow.timer = window.setTimeout("snow.move()", 50);
	}
}

/*
snow.ie5 = document.all && document.getElementById && !snow.browserinfos.match(/Opera/);
snow.ns6 = document.getElementById && !document.all;
snow.opera = snow.browserinfos.match(/Opera/);
snow.browserok = snow.ie5 || snow.ns6 || snow.opera;

if (snow.browserok) {
*/
	var now = new Date();
	if (now.getMonth() >= 11 || now.getMonth() <= 0) {
		for (i = 0; i < snowmax; i++) { document.write("<span class='fallingsnow' id='snow"+i+"' style='position:absolute;top:0;'>"+snowletter+"</span>"); }
		if (window.onload) { snow.prev_onload = window.onload; }
		window.onload = snow.init;
	}
//}
