// �������� �������� v1.0
// � 2007 ������� �.�., info@webfilin.ru
// ��������: GNU PL

var _gsnow=new Array();

function Snow()
{
	if (!this.docWidth)
	{
		this.docWidth=window.innerWidth?window.innerWidth:document.body.clientWidth;
		if (this.docWidth<this.docMinWidth)	this.docWidth=this.docMinWidth;
		this.allWidth=true;
	}

	if (!this.docHeight)
	{
		this.docHeight=window.innerHeight?window.innerHeight:(document.body.clientHeight?document.body.clientHeight:document.documentElement.clientHeight);
		if (this.docHeight<this.docMinHeight)	this.docHeight=this.docMinHeight;
		this.allHeight=true;
	}
	
	
	this.id=_gsnow.length;
	_gsnow.push(this);
	
	var pastetext="";
	var img;

	for (var i=0; i<this.snowN; i++)
	{
		this.dx[i]=0;
		this.xp[i]=Math.random()*(this.docWidth-50);
		this.yp[i]=Math.random()*this.docHeight;
		this.am[i]=Math.random()*20;
		this.stx[i]=0.02+Math.random()/10;
		this.sty[i]=0.7+Math.random();
		img=this.imgDir+Math.floor(Math.random()*9)+".png";
		pastetext+="<div id=\"dot"+this.id+i+"\" style=\"visibility:visible; top:0; left:0; position:absolute; z-index:"+(900+i)+";\"><img style=\"width:30px; height:30px; background:url('"+img+"') no-repeat top left; //background:none; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+img+"',sizingMethod=crop);\" src=\""+this.imgDir+"x.gif\" border=\"0\"\/><\/div>";
	}
	
	//document.body.innerHTML+=pastetext;
	var sn=document.getElementById('snow');
	sn.innerHTML=pastetext;
	
	return;
}

Snow.prototype.docWidth=0; // ������ ���� �������� ��������, 0 - ��� ������ ���� ��������
Snow.prototype.docHeight=0;	// ������ ���� �������� ��������, 0 - ��� ������ ���� ��������
Snow.prototype.docMinWidth=300; // ����������� ������
Snow.prototype.docMinHeight=200; // ����������� ������
Snow.prototype.snowN=3; // ���������� ��������
Snow.prototype.imgDir="/img/snow/"; // ����� � ���������� ��������
Snow.prototype.id=null;
Snow.prototype.dx=new Array();
Snow.prototype.xp=new Array();
Snow.prototype.yp=new Array();
Snow.prototype.am=new Array();
Snow.prototype.stx=new Array();
Snow.prototype.sty=new Array();
Snow.prototype.allWidth=false;
Snow.prototype.sin=true;
Snow.prototype.allHeight=false;

Snow.prototype.show=function()
{
	if (this.allWidth)
	{
		this.docWidth=window.innerWidth?window.innerWidth:document.body.clientWidth;
		if (this.docWidth<this.docMinWidth)	this.docWidth=this.docMinWidth;

		this.docWidth-=50;
	}

	if (this.allHeight)
	{
		this.docHeight=window.innerHeight?window.innerHeight:(document.body.clientHeight?document.body.clientHeight:document.documentElement.clientHeight);
		if (this.docHeight<this.docMinHeight)	this.docHeight=this.docMinHeight;
		
		this.docHeight-=20;
	}
	
	var x,y;
	for (var i=0; i<this.snowN; i++)
	{
		this.yp[i]+=this.sty[i];
		if (this.yp[i]>this.docHeight-20)
		{
			this.xp[i]=Math.random()*(this.docWidth-this.am[i]-30);
			this.yp[i]=-4;
			this.stx[i]=0.02+Math.random()/10;
			this.sty[i]=0.7+Math.random();
			this.setOpacity("dot"+this.id+i, 100);
		}
		
		if (this.yp[i]>this.docHeight-40 && this.yp[i]<this.docHeight-20)
		{
			this.setOpacity("dot"+this.id+i, (this.docHeight-this.yp[i]-20)*5);
		}
		
		this.dx[i]+=this.stx[i];
		
		y=Math.floor(this.yp[i]);
		
		if (this.sin)	x=Math.floor(this.xp[i]+this.am[i]*Math.sin(this.dx[i]));
		else	x=Math.floor(this.xp[i]+this.am[i]);
		
		if (x>this.docWidth)	x=this.docWidth;
		if (y>this.docHeight)	y=this.docHeight;
		document.getElementById("dot"+this.id+i).style.top=''+y+'px';
		document.getElementById("dot"+this.id+i).style.left=''+x+'px';
	}
	setTimeout('_gsnowShow('+this.id+');', 20);
	
	return;
}

Snow.prototype.setOpacity=function(id, opacity)
{
	var object=document.getElementById(id).style;

	object.opacity=(opacity/100);
	object.filter='alpha(opacity='+opacity+')';
	
	return;
}

function _gsnowShow(id)
{
	_gsnow[id].show();

	return;
}


function CreateSnow(amount){
	if (!amount) return;
	if (amount<=0) return;
	Snow.prototype.snowN=amount;
	var obj=new Snow();
	obj.show();
}

/*
window.onload=function()
{
	//CreateSnow();

	return;
}*/
