allTypeOfLeaves = new Array(2)
Leaf1 =new Image();
Leaf1 = allTypeOfLeaves[0] = "leaf.png";
Leaf2 =new Image();
Leaf2 = allTypeOfLeaves[1] ="leaf1.png";
//Leaf3 =new Image();
//Leaf3 = allTypeOfLeaves[2] ="leaf2.png";

var speedC = 2;//here you can define speed of leaves
var rotation = 3;//define rotation of leaves
var numberOfLeaves = 10;//define number of leaves
var size = 35;
var style = 'easeInOutBack';//style of lava lamp

Ypos=new Array();
Xpos=new Array();
Speed = new Array();
startYPos = new Array();
Cstep=new Array();
Step=new Array();
rotationAll = new Array();
height = new Array();
width = new Array();
var counter = 0;
opacityLeaf = new Array();

WinWidth = $(window).width();//width and height of browser window
WinHeight = $(window).height();


for (i = 0 ;i < numberOfLeaves;i++){
	 var randomLeaf = Math.floor(Math.random()*allTypeOfLeaves.length);
	 rndLeaf=allTypeOfLeaves[randomLeaf];
	 
	 width[i]=Math.round(Math.random()*size+20);
     height[i]=Math.round(Math.random()*size+20);
	 if (width[i] > height[i]*1.5 || height[i] > width[i]*1.5) 
		width[i] = height[i];
	
	 Ypos[i] = -50;//starting y position of leaves
	 Xpos[i] = Math.round(Math.random()*(WinWidth)-width[i]*4);//randomization of x position of leaves
	 opacityLeaf[i] = 0.3;
	 Speed[i]= Math.random()*speedC + 2;//speed of leaves
	 rotationAll[i] = Math.round(Math.random()) * rotation + Speed[i];
	 Cstep[i]=0;
	 Step[i]=Math.random()*0.05+0.03;
	 
   	 document.write('<img class="slike'+i+'" src="'+rndLeaf+'" style="position:absolute;top:'+Ypos[i]+'px;left:'+Xpos[i]+'px;height:'+height[i]+'px;width:'+width[i]+'px;opacity:'+opacityLeaf[i]+';">');
}   
function fall(){	
	
	for (i = 0 ;i < numberOfLeaves;i++)
    {
		//alert(WinHeight)
		sy = Speed[i]*Math.sin(90*Math.PI/180);
		sx = Speed[i]*Math.cos(Cstep[i]);
		rotationAll[i]+=rotation;

		Ypos[i]+=sy;
		Xpos[i]+=sx; 
		if (Ypos[i] < 0){
			opacityLeaf[i]=1;
			$(".slike"+i).css({opacity:opacityLeaf[i]});			
		}
		if (Ypos[i] > WinHeight - height[i] * 6){
			opacityLeaf[i]-=0.02;	
			$(".slike"+i).css({opacity:opacityLeaf[i]});			
		}
		if (Ypos[i] > WinHeight - (width[i] + 10)){
			
			Ypos[i]=-50;
			Xpos[i]=Math.round(Math.random()*WinWidth-width[i]*4);
			Speed[i]= Math.random()*speedC + 2;
		}

		($(".slike"+i).animate({top:Ypos[i], left:Xpos[i]},{duration:Speed[i]})).animate({rotate:rotationAll[i]}, 0);
		
		//$(".slike"+i).css({top: Ypos[i], left: Xpos[i]});
		Cstep[i]+=Step[i];
    }
	
	setTimeout('fall()',25);
}
window.onload=fall

