var Amount=30; // number of items falling

// preload of images so page doesn't drag
Image0 = new Image();
Image0.src = "images/winter/flake1.gif";
Image1 = new Image();
Image1.src = "images/winter/flake2.gif";
Image2 = new Image();
Image2.src = "images/winter/flake3.gif";
Image3 = new Image();
Image3.src = "images/winter/flake4.gif";
Image4 = new Image();
Image4.src = "images/winter/flake5.gif";
Image5 = new Image();
Image5.src = "images/winter/flake6.gif";
Image6 = new Image();
Image6.src = "images/winter/flake7.gif";
Image7 = new Image();
Image7.src = "images/winter/flake8.gif";
Image8 = new Image();
Image8.src = "images/winter/flake9.gif";
Image9 = new Image();
Image9.src = "images/winter/flake10.gif";
Image10 = new Image();
Image10.src = "images/winter/flake11.gif";
Image11 = new Image();
Image11.src = "images/winter/flake12.gif";

// loads images into an array for use later to randomize their appearance
// length of grphcs array must match the number of image sources assigned below
grphcs = new Array(11); 
grphcs[0] = "images/winter/flake1.gif";
grphcs[1] = "images/winter/flake2.gif";
grphcs[2] = "images/winter/flake3.gif";
grphcs[3] = "images/winter/flake4.gif";
grphcs[4] = "images/winter/flake5.gif";
grphcs[5] = "images/winter/flake6.gif";
grphcs[6] = "images/winter/flake7.gif";
grphcs[7] = "images/winter/flake8.gif";
grphcs[8] = "images/winter/flake9.gif";
grphcs[9] = "images/winter/flake10.gif";
grphcs[10] = "images/winter/flake11.gif";
grphcs[11] = "images/winter/flake12.gif";

Ypos=new Array();
Xpos=new Array();
Speed=new Array();
Step=new Array();
Cstep=new Array();

// builds an outer div as a layer for the images to fall in
document.write('<div style="position:absolute;top:0px;left:0px"><div style="position:relative">');

// randomnly lays out Amount number of DIVs with an image in each, placing them in the upper left hand corner
for (i = 0; i < Amount; i++){
	var P=Math.floor(Math.random()*grphcs.length);
	rndPic=grphcs[P];
	document.write('<img id="si" src="'+rndPic+'" style="position:absolute;top:0px;left:-600px">');
}	
document.write('</div></div>');

// determines the width and height of the window so that the shower objects cover the whole window
WinHeight = window.document.body.clientHeight;
WinWidth = window.document.body.clientWidth;

// provides each object a randomn beginng location within the window, randomn speed of movement down, current step for the horizontal oscillation, the base step for horizontal oscillation
for (i=0; i < Amount; i++){                                                                
	Ypos[i] = Math.round(Math.random()*WinHeight);
	Xpos[i] = Math.round(Math.random()*WinWidth);
	Speed[i]= Math.random()*3+2;
	Cstep[i]=0;
	Step[i]=Math.random()*0.1+0.05;
}

function fall(){

	// determines the width and height of the window so that the shower objects cover the whole window
	var WinHeight = window.document.body.clientHeight;
	var WinWidth = window.document.body.clientWidth;
	
	// identifies the where the user has scrolled to on the page
	var hscrll = document.body.scrollTop;
	var wscrll = document.body.scrollLeft;
	
	
	for (i=0; i < Amount; i++){
	
		sy = Speed[i]*Math.sin(90*Math.PI/180);
		sx = Speed[i]*Math.cos(Cstep[i]);
		Ypos[i]+=sy;
		Xpos[i]+=sx;
		 
		if (Ypos[i] > WinHeight){
			Ypos[i]=-60;
			Xpos[i]=Math.round(Math.random()*WinWidth);
			Speed[i]=Math.random()*6+2;
		}
		
		si[i].style.pixelLeft=Xpos[i];
		si[i].style.pixelTop=Ypos[i]+hscrll;
		
		Cstep[i]+=Step[i];
	}
	setTimeout('fall()',10);
}