/* 
	Snowflakes script by lead at kattenbak dot net
*/

function Snowflakes(instanceName)
{

	this.flakes = parseInt(window.innerHeight / 40);
	this.timeout = 100; //-- update timeout
	this.tick = 0;
	this.speed = 5;
	this.snowTypes  = new Array("Arial Black", "Arial Narrow", "Times","Comic Sans MS");
	this.snowColors = new Array("#aaaacc","#ddddFF","#ccccDD");

	this.drawFlakes();
	setInterval(instanceName + '.interval()', this.timeout);

}

Snowflakes.prototype.drawFlakes = function()
{

	// place the snowflakes, 

	for (var i=0; i<this.flakes; i++)
	{
		var flake = document.createElement('SPAN');

		flake.id = 'snowflake_' + i;
		flake.innerHTML = '*';
		flake.style.fontSize = parseInt( 5 + (Math.random() * 40)) + 'px';
		flake.style.fontFamily = this.snowTypes[ Math.floor( Math.random() * this.snowTypes.length) ];
		flake.style.color = this.snowColors[ Math.floor( Math.random() * this.snowColors.length) ];
		flake.style.position = 'absolute';
		flake.style.left = parseInt( Math.random() * (window.innerWidth - 50) ) + 'px';
		flake.style.top  = parseInt( (Math.random() * window.innerHeight) ) + 'px';

		document.body.appendChild(flake);
		
		
	}
}

Snowflakes.prototype.interval = function()
{

	for (var i=0; i<this.flakes; i++)
	{
		var flake = document.getElementById('snowflake_' + i);
		
		var top = flake.style.top;
		top = top.substr(0,top.length-2); //-- get rid of the 'px'

		if (top > window.pageYOffset + window.innerHeight - 60)
			top = window.pageYOffset;
		else
			top = top - this.speed * -1;;

		flake.style.top = top + 'px';

		
		var left = flake.style.left;
		left = left.substr(0,left.length-2); //-- take off the 'px'
		
		var rand = Math.random();

	    if (rand >= 0.5)
			left--;
		else
			left++;
		
			
		flake.style.left = left + 'px';
	}
}

var s;
function initsnow()
{
	var date = new Date()
	if (date.getMonth() == 11) //-- only show snow in december
		s = new Snowflakes('s');
}

