//Params

//Ile
num = 10;
//Jak długo
stopafter = 10 * 1000;


//Script

//Preloading
pics = new Array("/includes/special/snfla.gif","/includes/special/snflb.gif","/includes/special/snflc.gif","/includes/special/snfld.gif","/includes/special/snfle.gif","/includes/special/snflf.gif"); 
l = new Array();
for(i = 0; i < pics.length; i++){
	l[i] = new Image();
	l[i].src = pics[i];
}

//Utwórz płatki
snowflakes = new Array();
for(i = 0; i < num; i++)
{
	snowflakes[i] = document.createElement("img");
	snowflakes[i].src = pics[Math.floor(Math.random()*pics.length)];
	snowflakes[i].style.position = "absolute";
	snowflakes[i].style.display = "block";
	snowflakes[i].style.left = 0;
	snowflakes[i].style.top = 0;
	document.body.appendChild(snowflakes[i]);
}


timer = null;
ss = new screensize();

y = new Array();
x = new Array();
s = new Array();
s1 = new Array();
s2 = new Array();

inih = ss.height-50;
iniw = ss.width-100;
for (i=0; i < num; i++)
{                                                          
	y[i]=Math.round(Math.random()*inih);
	x[i]=Math.round(Math.random()*iniw)+50;
	s[i]=Math.random()*5+3;
	s1[i]=0;
	s2[i]=Math.random()*0.1+0.05;
}

function screensize()
{
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    this.width = window.innerWidth;
    this.height = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    this.width = document.documentElement.clientWidth;
    this.height = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    this.width = document.body.clientWidth;
    this.height = document.body.clientHeight;
  }
	if (self.pageYOffset) // all except Explorer
	{
		this.off_x = self.pageXOffset;
		this.off_y = self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
		// Explorer 6 Strict
	{
		this.off_x = document.documentElement.scrollLeft;
		this.off_y = document.documentElement.scrollTop;
	}
	else if (document.body) // all other Explorers
	{
		this.off_x = document.body.scrollLeft;
		this.off_y = document.body.scrollTop;
	}

}


function fall()
{
	ss = new screensize();
	h = ss.height;
	w = ss.width - 75;
	scy = ss.off_y;

	for (i=0; i < num; i++)
	{
		sy=s[i];
		sx=s[i]*Math.cos(s1[i]);
		y[i]+=sy;
		x[i]+=sx; 
		if(x[i] > w)
		{
			x[i] = w - Math.random()*5;
		}
		if (y[i] > h)
		{
			y[i]=-60;
			x[i]=Math.round(Math.random()*w);
			s[i]=Math.random()*5+3;
		}
		s1[i]+=s2[i];
		snowflakes[i].style.left = "" + Math.floor(x[i]) + "px";
		snowflakes[i].style.top = "" + Math.floor(y[i]+scy) + "px";
	}
	timer=setTimeout('fall()',20);
}

function stopfalling()
{
	clearTimeout(timer);
	for (i=0; i < num; i++)
	{
		document.body.removeChild(snowflakes[i]);
	}
	
}

fall();
setTimeout('stopfalling()',stopafter);

