	
function initializeProfileRain(){
	window.rain = new ProfileRain(selectedRainIcon);
	window.rain.start();
}


ProfileRain = function(icon){
	this.init(icon)
}

ProfileRain.prototype = {
	
	icon: "",
	_amount: 6,
	_thread: 0,
	_icons: null,
	
	init: function(icon){
		
		this._height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight;
		this._width = document.body.clientWidth ;
		
		this._icons = new Array();

		for(var i=0; i < this._amount; i++){
			this._icons[i] = [];
			this._icons[i].img = this._createIconImg(icon);
			this._icons[i].speed = Math.random()+1;
			this._icons[i].cstep = 0;
			this._icons[i].step = Math.random()*0.1+0.05;
			this._icons[i].x = this._icons[i].img.offsetLeft;
			this._icons[i].y = this._icons[i].img.offsetTop;
		}
		
	},
	
	start: function(){
		
		for(var i=0; i < this._amount; i++){
			this._icons[i].img.style.display = "";
		}
		
		var self = this;
		this._thread = setInterval(function(){self._fall()}, 30);
		
	},
	
	stop: function(){
		clearInterval(this._thread);
		for(var i=0; i < this._amount; i++){
			this._icons[i].img.style.display = "none";
		}	
	},
	
	_fall: function(){
		
		var scrollY = window.pageYOffset || document.documentElement.scrollTop;
		
		for (i=0; i < this._amount; i++){
			
			var icon = this._icons[i];
			
			var sy = icon.speed*Math.sin(90*Math.PI/180);
			var sx = icon.speed*Math.cos(icon.cstep);
			
			icon.y += sy;
			icon.x += sx;
			
			if (icon.y > this._height){
				icon.y = -60;
				icon.x = Math.round(Math.random()*this._width) - 100;
				icon.speed = Math.random()*2+3;
			}
			
			icon.img.style.left = icon.x + "px";
			icon.img.style.top = icon.y + scrollY + "px";
			
			icon.cstep += icon.step;
			
			this._icons[i] = icon;
			
		}
		
	},
	
	_createIconImg: function(icon){
		
		var img = new Image();
		img.style.position = "absolute";
		img.style.zIndex = 1000;
		img.style.top = Math.round(Math.random()*this._height) + "px";
		img.style.left = Math.round(Math.random()*this._width) - 100 + "px";
		img.src = icon;
		document.body.appendChild(img);
		return img;
	}
	
}

YAHOO.util.Event.addListener(window, 'load', initializeProfileRain);
	