var dx = new Array();
var xPos = new Array();
var yPos = new Array();
var sway = new Array();
var swaymax = 20;
var vx = new Array();
var vy = new Array();

var theFlakes = new Array();
var flakeImages = new Array('/images/snow.gif');

var winwidth = 640;
var winheight = 480;

function recalculateWindowDimensions() {
	winwidth = window.innerWidth?window.innerWidth:document.body.clientWidth;
	winheight = window.innerHeight?window.innerHeight:document.body.clientHeight;
}

function rnd(){return Math.random();}
function xRnd(){return (rnd()/10);}
function yRnd(){return (2 + 2*( .5 - rnd() ));}

function hideSnow() {
	for (var i = 0; i < theFlakes.length; i++) {
		theFlakes[i].move(-100,-100);
	}
}

function snowStorm() {

	recalculateWindowDimensions();
	var delta = (window.pageYOffset!=null)?window.pageYOffset:document.body.scrollTop;
	for (var i=0; i < theFlakes.length; i++) {
		yPos[i] += vy[i];
		if (yPos[i] > winheight+delta-50) {
			xPos[i] = rnd()*(winwidth-sway[i]-30);
			yPos[i] = delta;
			vx[i] = xRnd();
			vy[i] = yRnd();
		}
		dx[i] += vx[i];
		
		theFlakes[i].move(xPos[i]+sway[i]*Math.cos(dx[i]), yPos[i]);
	}
	setTimeout("snowStorm()", 50);
	
}

function initSnow(numFlakes) {
	recalculateWindowDimensions();
	
	document.write('<STYLE type="text/css">.flk {position:absolute;top:-100;z-index:100}</STYLE>');	
	
	for(var i=0; i<numFlakes; i++) {
		theFlakes[i] = new Snowflake(i, flakeImages[Math.floor(rnd()*flakeImages.length)]);
		document.write(theFlakes[i].getHTML());
		
		dx[i] = 0;
		xPos[i] = rnd()*(winwidth-30) +10;
		yPos[i] = rnd()*winheight;
		sway[i] = rnd()*swaymax;
		vx[i] = xRnd();
		vy[i] = yRnd();		
	}
	
	snowStorm();
}



