var no = 20; // количество снежинок // 20
var speed = 40; // скорость снежинок
var snowflake = "snow.gif";

var dx, xp, yp; 
var am, stx, sty; 
var i, doc_width = 800;
var doc_width = screen.width-20;
//var doc_width = $("window").width()-20;
var doc_height = screen.height;
var docu = $("#top");
//console.log($("window").width(), $(window).width());

dx = new Array();
xp = new Array();
yp = new Array();
am = new Array();
stx = new Array();
sty = new Array();
var div;
$(function() {
	doc_width = $(window).width();
	var docu = $("body");
	var tt = $("table").eq(0);
	doc_height = Math.max(tt.height(),doc_height);
	makeDiv(docu);
	snow();

});

function makeDiv(docu) {
	for(var i = 0;i < no; i++) {
		dx[i] = 0;
		xp[i] = Math.random()*(doc_width-50); 
		yp[i] = Math.random()*doc_height;
		am[i] = Math.random()*20;         
		stx[i] = 0.02 + Math.random()/10; 
		sty[i] = 0.7 + Math.random();
		div = $("<div id='dot"+ i +"' style='position:absolute; z-index: "+i+"; top:15px; left:"+xp[i]+"px;'><img src='"+snowflake+"'></div>");
		docu.append(div);
	}
}

function snow(docu) {
	for(var i = 0;i< no; i++) {
		var snow = $("#dot"+i);
		yp[i] += sty[i];
		if (yp[i] > doc_height-50) {
			xp[i] = Math.random()*(doc_width-am[i]-30);
			yp[i] = 0;
			stx[i] = 0.02 + Math.random()/10;
			sty[i] = 0.7 + Math.random();
		}
		dx[i] += stx[i];
		snow.css("top", yp[i]+"px").css("left",xp[i] + am[i]*Math.sin(dx[i])+"px");
	}
	setTimeout("snow()", speed);
}


/*
$(function() {
	snow();
});



for (i = 0; i < no; ++ i) {  
	dx[i] = 0;         
	xp[i] = Math.random()*(doc_width-50); 
	yp[i] = Math.random()*doc_height;
	am[i] = Math.random()*20;         
	stx[i] = 0.02 + Math.random()/10; 
	sty[i] = 0.7 + Math.random();   

	if (i == 0) {
		document.write("<div id=\"dot"+ i +"\" style=\"POSITION: ");
		document.write("absolute; Z-INDEX: "+ i +"; VISIBILITY: ");
		document.write("visible; TOP: 15px; LEFT: 15px;\"><img src=\"");
		document.write(snowflake + "\" border=\"0\"></div>");
	} else {
		document.write("<div id=\"dot"+ i +"\" style=\"POSITION: ");
		document.write("absolute; Z-INDEX: "+ i +"; VISIBILITY: ");
		document.write("visible; TOP: 15px; LEFT: 15px;\"><img src=\"");
		document.write(snowflake + "\" border=\"0\"></div>");
   }
}

function snowIE() 
{ 
	for (i = 0; i < no; ++ i) { 
		yp[i] += sty[i];
		if (yp[i] > doc_height-50) {
			xp[i] = Math.random()*(doc_width-am[i]-30);
			yp[i] = 0;
			stx[i] = 0.02 + Math.random()/10;
			sty[i] = 0.7 + Math.random();
			doc_width = document.body.clientWidth;
			doc_height = document.body.clientHeight;
			doc_height=1270;
		}
		dx[i] += stx[i];
		document.all["dot"+i].style.pixelTop = yp[i];
		document.all["dot"+i].style.pixelLeft = xp[i] + am[i]*Math.sin(dx[i]);
	}
	setTimeout("snowIE()", speed);
}

snowIE();
*/
