var Drop = function(options) {
	var self = this;
	this.b = 'http://upminders.com/wp-content/themes/upminders/images/';
	this.s = ['round100_30.png', 'round100_50.png', 'round100_70.png'];
	this.i = this.s[this.random(0,(this.s.length-1))];
	this.f = this.b + this.i;
	this.n = document.createElement('img');
	options.once	= options.once || false;
	if (options.once==true){
		this.newSpeed().newPoint().newSize().display().puffOnce();
	} else {
		this.newSpeed().newPoint().newSize().display().puff();
	}
};

Drop.prototype.random = function(min,max) {
	var	rnd	= Math.floor(Math.random() * (max - min + 1)) + min;
	return	rnd;
}

Drop.prototype.newSpeed = function() {
	this.speed = this.random(4,10) * 1000;
	return this;
};

Drop.prototype.newPoint = function() {
	var	flds= window.innerWidth - 880;
	var	we	= flds - 140;
	var	ww	= 880 + Math.round(flds/2);
	var	xs	= [this.random(1,we),this.random(ww,window.innerWidth)];
//	this.pointX = this.random(1,window.innerWidth - 100);
	this.pointX = xs[this.random(0,1)];
	this.pointY = this.random(1,350);
	return this;
};

Drop.prototype.newSize = function() {
	var	width	= this.random(10,140);
	this.sizeX	= width;
	this.sizeY	= width;
	return this;
};

Drop.prototype.display = function() {
	$(this.n)
	.attr('src', this.f)
	.css('position', 'absolute')
	.css('z-index', this.random(2,20))
	.css('opacity', 0.1)
	.css('top', this.pointY)
	.css('left', this.pointX)
	.css('width', this.sizeX)
	.css('height', this.sizeY);
	$('#page-wrapper').append(this.n);	//	document.body
	return this;
};

Drop.prototype.puff = function() {
	var self = this;
	$(this.n).animate({
		'opacity': 1,
		'width': this.sizeX+20,
		'height': this.sizeY+20,
	}, this.speed, 'linear', function(){
		self.newSpeed().newPoint().newSize().display().puff();
	});
};

Drop.prototype.puffOnce = function() {
	var self = this;
	$(this.n).animate({
		'opacity': 1,
		'width': this.sizeX+20,
		'height': this.sizeY+20,
	}, this.speed, 'linear');
};

Drop.prototype.kill = function() {
	$(this.n).remove();
	return this;
};

$(function(){
	var totalDrops = 10;
	var drops = [];
	for (i = 0; i < totalDrops; i++){  
		drops[i] = new Drop({ once: false });
	}
});
