
//var snowsrc="/js/sneg.gif" //���� � ����������� ��������
var leavesSrc = new Array(); // regular array (add an optional integer
leavesSrc[0] = "/images/sneg.gif"; // argument to control array's size)
leavesSrc[1] = "/images/sneg.gif";
leavesSrc[2] = "/images/sneg.gif";
leavesSrc[3] = "/images/sneg.gif";
leavesSrc[4] = "/images/sneg.gif";
leavesSrc[5] = "/images/sneg.gif";

function getRandom(min, max) {
	var randomNum = Math.random() * (max - min);

	// Round to the closest integer and return it
	return (Math.round(randomNum) + min);
}

var no = 15; // ���-�� ��������
var hidesnowtime = 0; // ����� ������ (� ��������), ��� 0 - ����������
var snowdistance = "pageheight";
var ie4up = (document.all) ? 1 : 0; // ����������� ���� ��������
var ns6up = (document.getElementById && !document.all) ? 1 : 0; // �����������

function iecompattest() {
	return (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement
			: document.body
}

var dx, xp, yp;
var am, stx, sty;
var i, doc_width = 800, doc_height = 150; // �������

if (ns6up) {
	doc_width = self.innerWidth - 25;
	// doc_height = self.innerHeight;
	doc_height = 150;
} else if (ie4up) {
	doc_width = iecompattest().clientWidth - 25;
	// doc_height = iecompattest().clientHeight;
	doc_height = 150;
}

dx = new Array();
xp = new Array();
yp = new Array();
am = new Array();
stx = new Array();
sty = new Array();

/*
var info_block = $("#info_block").position();
var a = info_block.position();
*/

//alert(a.top);

var info_block_x = $("#info_block").offset().left; 
var info_block_y = $("#info_block").offset().top;
//var info_block_w = $("#info_block").width;
//var info_block_h = $("#info_block").height;

//alert(info_block_x+''+info_block_y);

//alert(info_block_x+''+info_block_y);//+''+info_block_w+''+info_block_h);
var dzi = -1;
for (i = 0; i < no; ++i) { // ��������� ���� ������ ��������
	dx[i] = 0;
	xp[i] = Math.random() * (doc_width - 50); // ���������� �������� �� X
	yp[i] = Math.random() * doc_height; // ���������� �������� �� Y
	am[i] = Math.random() * 20; // ���������
	stx[i] = 0.02 + Math.random() / 10; // ���������� ����� ���������� �� �
	sty[i] = 0.7 + Math.random(); // ���������� ����� ���������� �� Y
	if (ie4up || ns6up) {
		var zi = dzi - i;  
		document.write("<div id=\"sneg" + i
				+ "\" style=\"POSITION: absolute; Z-INDEX: " + zi
				+ "; VISIBILITY: hidden; TOP: 15px; LEFT: 15px;\"><img src='"
				+ leavesSrc[getRandom(0, 5)]
				+ "' border=\"0\" width=\"20\" height=\"20\" ><\/div>");

	}
}

function snowIE_NS6() { // �������� ��� InternetExplorer � NetScape6
	doc_width = ns6up ? window.innerWidth - 70
			: iecompattest().clientWidth - 70;
	// doc_height=(window.innerHeight && snowdistance=="windowheight")?
	// window.innerHeight : (ie4up && snowdistance=="windowheight")?
	// iecompattest().clientHeight : (ie4up && !window.opera &&
	// snowdistance=="pageheight")? iecompattest().scrollHeight :
	// iecompattest().offsetHeight;
	doc_height = 140;
	
	var bb = 20;
	// ���� ���������
	var ibx = $("#info_block").position().left;
	var iby = $("#info_block").position().top;
	var ibw = $("#info_block").width();
	var ibh = $("#info_block").height();
	var ibx2 = ibx + ibw;
	var iby2 = iby + ibh;
	
	//alert(ibx+':'+iby);
	
	ibx = ibx - bb;
	iby = iby - bb;
	ibx2 = ibx2 + bb;
	iby2 = iby2 + bb;
	
	// �������
	var lx = $("#logo").position().left;
	var ly = $("#logo").position().top;
	var lw = $("#logo").width();
	var lh = $("#logo").height();
	var lx2 = lx + lw;
	var ly2 = ly + lh;
	
	lx = lx - bb;
	ly = ly - bb;
	lx2 = lx2 + bb;
	ly2 = ly2 + bb;
	
	// ���� ��������� ������� �������
	var hnx = $("#header_name").position().left;
	var hny = $("#header_name").position().top;
	var hnw = $("#header_name").width();
	var hnh = $("#header_name").height();
	var hnx2 = hnx + hnw;
	var hny2 = hny + hnh;
	
	hnx = hnx - bb;
	hny = hny - bb;
	hnx2 = hnx2 + bb;
	hny2 = hny2 + bb;
	
	var again = false;
	for (i = 0; i < no; i++) { // ������ �������� ����, �� �� �����
		if (again == true) {
			i--;
			again = false;
		}
				
		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];
		
		var top = yp[i];
		var left = xp[i] + am[i] * Math.sin(dx[i]);
						
		//alert('ibx='+ibx+': iby='+iby+': ibx2='+ibx2+': iby2='+iby2+': left='+left+': top='+top);		
		//break;
		
		if ((left >= ibx && top >= iby && left <= ibx2 && top <= iby2) ||
			(left >= lx && top >= ly && left <= lx2 && top <= ly2) ||
			(left >= hnx && top >= hny && left <= hnx2 && top <= hny2) ) {
			again = true;			
		} else {		
			document.getElementById("sneg" + i).style.top = top + "px";
			document.getElementById("sneg" + i).style.left = left + "px";
			document.getElementById("sneg" + i).style.visibility = 'visible';			
		}
	}
	// snowtimer=setTimeout("snowIE_NS6()", 30);
}

function hidesnow() { // ������������ �������� � ���������� �������
	if (window.snowtimer)
		clearTimeout(snowtimer)
	for (i = 0; i < no; i++)
		document.getElementById("sneg" + i).style.visibility = "hidden"
}

$(function() {
	if (ie4up || ns6up) {
		snowIE_NS6();
		if (hidesnowtime > 0)
			hidesnow();
		//setTimeout("hidesnow()", hidesnowtime*1000)
	}
});


