function snow(){
	var windX=0;
	var windY=0;
	var canvasElement;
	var canvas;
	var gradient;
	var windStrenght;
		$.post('/log_ip.php',{log:'snow'});
		$('body').append('<canvas id="snow"></canavas>');
		$('#snow').attr('width','760').attr('height','400').css({position:'fixed',top:'0px',width:'100%',height:'100%',pointerEvents:'none'});
		canvasElement = document.getElementById('snow');
		canvas = canvasElement.getContext('2d');
		gradient = canvas.createRadialGradient(0,0,2,0,0,10);
		gradient.addColorStop(0, "black");
		gradient.addColorStop(1, "white");
		
		var snow = new Array();
		for (var i=0; i<200; i++){
			snow[i]=new Flake(i);
		}
		
		newWindX = (Math.random()*5-2.5);
		windStrenght=0;
		for(var j=0; j<200;j++){
		for (var i=0; i<200; i++){
				snow[i].move();
		}	
		}
		setInterval(function(){
			if (Math.abs(newWindX-windX)<0.5)
			{
				newWindX = (Math.random()*10-5);
				windStrenght=0;
			}
			
			windX+=(newWindX-windX)*windStrenght
			windStrenght+=0.01;
			//windY+=(Math.random()*2)*windStrength/2;
			canvas.clearRect ( 0 , 0 , 760 , 400 );
			for (var i=0; i<200; i++){
				snow[i].move();
				snow[i].draw();
			}	
			
		},100);
		
		
	function Flake(i){
		this.x = (Math.random()*760+1)
		this.y = 0;
		this.weight = Math.random()*5+1;
		
		
		this.move= function(){
			this.y+=this.weight/2 ;
			this.x+=windX*((this.weight*this.weight)/10);
			this.y+=windY*((this.weight*this.weight)/10);
			if (this.y>400 || this.y<0 || this.x>800 || this.x<-50)
			{
				this.x = (Math.random()*850-50)
				this.y = 0;
				this.weight = Math.random()*5+0.1;
			}
		};
		this.draw= function(){
			//console.log(this.x, this.y);
			canvas.beginPath();
			canvas.arc(this.x, this.y, this.weight, 0, Math.PI * 2, false);
			canvas.closePath();
			canvas.fillStyle='white';
			canvas.fill();
		};
	}
}
var keyQueue = new Array(); 
		$(function(){
			$(window).keyup(function(e){
				keyQueue.push(e.which);
				if (keyQueue.length>4)
					keyQueue=keyQueue.slice(keyQueue.length-4);
				if (keyQueue[0]==83 && keyQueue[1]==78 && keyQueue[2]==79 && keyQueue[3]==87)
					snow();
			});
		});
