Amount=10; //Smoothness! depends on image file size, the smaller the size the more you can use!

//Pre-load your image below!
Image0=new Image();
Image0.src="img10.png";
Image1=new Image();
Image1.src="img20.png";
Image2=new Image();
Image2.src="img30.png";
Image3=new Image();
Image3.src="img10.png";

grphcs=new Array(4)
grphcs[0]="img10.png"
grphcs[1]="img20.png"
grphcs[2]="img30.png"
grphcs[3]="img10.png"


Ypos=new Array();
Xpos=new Array();
Speed=new Array();
Step=new Array();
Cstep=new Array();
ns=(document.div)?1:0;
if (ns)	{
	for (i = 0; i < Amount; i++){
	var P=Math.floor(Math.random()*grphcs.length);
	rndPic=grphcs[P];
	document.write("<div name='sn"+i+"'><img src="+rndPic+"></div>");
	}
}
else{
	document.write('<div style="position:absolute;top:0px;left:0px;z-index:2;"><div style="position:relative">');
	for (i = 0; i < Amount; i++){
	var P=Math.floor(Math.random()*grphcs.length);
	rndPic=grphcs[P];
	document.write('<img id="si'+i+'" src="'+rndPic+'" style="position:absolute;top:0px;left:0px">');
	}
document.write('</div></div>');
}

WinHeight=(document.div)?window.innerHeight:window.document.body.clientHeight;
WinWidth=(document.div)?window.innerWidth:window.document.body.clientWidth;
for (i=0; i < Amount; i++){
 Ypos[i] = Math.round(Math.random()*WinHeight);
 Xpos[i] = Math.round(Math.random()*WinWidth);
 Speed[i]= Math.random()*3+2;
 Cstep[i]=0;
 Step[i]=Math.random()*0.1+0.01;
}

function fall(){
	var WinHeight=(document.div)?window.innerHeight:window.document.body.clientHeight;
	var WinWidth=(document.div)?window.innerWidth:window.document.body.clientWidth;
	var hscrll=(document.div)?window.pageYOffset:document.body.scrollTop;
	var wscrll=(document.div)?window.pageXOffset:document.body.scrollLeft;
	for (i=0; i < Amount; i++){
		sy = Speed[i]*Math.sin(90*Math.PI/180);
		sx = Speed[i]*Math.cos(Cstep[i]);
		Ypos[i]+=sy;
		Xpos[i]+=sx;
		if (Ypos[i] > WinHeight){
		Ypos[i]=-60;
		Xpos[i]=Math.round(Math.random()*WinWidth);
		Speed[i]=Math.random()*5+2;
		}
		if (ns){
		document.div['sn'+i].left=Xpos[i];
		document.div['sn'+i].top=Ypos[i]+hscrll;
		}
		else{
	
	    str=document.getElementById( 'si'+i );
		str.style.left=Xpos[i]+'px';
		str.style.top=Ypos[i]+hscrll+'px';
		}
		Cstep[i]+=Step[i];
	}
	setTimeout('fall()',50);
}
