// JavaScript Document

var snowLines = new Array();
	var SNOWIMAGE = "images/SNOW.png"; //the image to be repeated
	var SNOWFALLSTART = 120; //where on the page to start the snow
	var SNOWFALLHEIGHT = 411; //where to end the snow fall on the page
	var SNOWWIDTH = 1440;
	var cnt = 10;
	var stopAni = 0;
	var bod = window.document.getElementsByTagName("body");
	var k = 0;
	
	/**
	 * Runs the snow animation also determines in a new line of snow needs to be made
	 *
	 * @return void
	 */
	function makeSnow()
	{
		if(stopAni != 1){
			moveSnow();
			
			if(cnt==10){
				var line = document.createElement("div");
				line.className = "snowLine";
				line.style.top = SNOWFALLSTART+"px";
				line.id = "snow_"+k;
				
				for(i=0; i<50; i++){
					var img = document.createElement("img");
					var offset = Math.random()*150;
					img.style.marginLeft = offset+"px";
					img.src = SNOWIMAGE;
					line.appendChild(img);
				}
				
				snowLines[snowLines.length] = "snow_"+k;
				bod[0].appendChild(line);
				cnt = -1;
				k++;
				
				removeSnowLines();
			}
			
			cnt++;		
			
			window.setTimeout("makeSnow()",100);
		}
	}
	
	/**
	 * Moves the snow on the screen downwards
	 *
	 * @return void
	 */
	function moveSnow()
	{

		for(i=0; i<snowLines.length; i++){
			top = 0;
			var line = document.getElementById(snowLines[i]);
			var top = parseInt(line.style.top.substring(0,line.style.top.length-2));
			
			fadeSnow(line,top);
			
			if(top<SNOWFALLHEIGHT){
				top += 3;
				line.style.top = top+"px";
			}
		}
	}
	
	/**
	 * Cleans up the snow divs so we don't kill the memory
	 *
	 * @return voiid
	 */
	function removeSnowLines()
	{
		if(snowLines.length > 10){
			var temp = snowLines.shift();	
			var line = document.getElementById(temp);
			bod[0].removeChild(line);
		}
	}
	
	/**
	 * As the snow moves down the screen it slowly fades out
	 *
	 * @param DOMElement The div containing the snow elements
	 * @param int The distance from the top of the page that the snow element appears
	 *
	 * @return void 
	 */
	function fadeSnow(line,top)
	{
		var cons = 0;
		
		if(top < 135){
			cons = ((top-120)/3)*.05;
		}
		else{
			cons = .25;
		}
		
		line.style.opacity = cons;
	}