// JavaScript Document, by tGDA
function FlyingObj(parent) {
	this.Parent=parent;
	this.htmlHandle=document.createElement('DIV');
	this.htmlHandle.className=this.Parent.Settings.ClassName;
	this.htmlHandle.innerHTML=this.Parent.Settings.AvailableContent[Math.rnd(0, this.Parent.Settings.AvailableContent.length-1, true)]; 
	//this.step=(this.diaMeter/5)+1;
	
	
	return this;
}



FlyingObj.prototype.reset=function() {
	
	this.size=Math.rnd(5, 15, true);
	this.step=0.006*this.size;
	//this.htmlHandle.style.opacity=Math.rnd(0.4, 0.7, false);
	this.htmlHandle.style.fontSize=this.size+'em';
	this.currentBottom=87+Math.rnd(this.size, this.size*2, false);
	this.currentLeft=Math.rnd(10, 101, false);
	
	
	this.Timeout=200;
	if (this.Parent.Settings.changeObj) {
		this.Parent.Settings.changeObj(this);
	}
	this.updateHTMLPos();
	if (this.Parent.Settings.showObj) {
		this.Parent.Settings.showObj(this);
	}
}
FlyingObj.prototype.updateHTMLPos=function() {
	this.htmlHandle.style.bottom=this.currentBottom+'%';
	this.htmlHandle.style.left=this.currentLeft+'%';
}

FlyingObj.prototype.Fly=function() {
	this.currentBottom+=this.step*this.Parent.Settings.Speed.Y;
	this.currentLeft+=this.step*this.Parent.Settings.Speed.X;
	this.htmlHandle.style.bottom=this.currentBottom+'%';
	this.htmlHandle.style.left=this.currentLeft+'%';
	
	if (this.currentBottom<=-25) {
		this.reset();		
	}
	var theFlake=this;
	setTimeout(function() {
		theFlake.Fly();
	},
	this.Timeout);
}

Math.rnd=function(min, max, intWanted) {
	var num=(Math.random()*max)%(max-min)+min;
	return intWanted? Math.round(num) : num;
}

FlyingObjects=function(settings) {
	this.Settings=settings;
	this.FlyingObjects=[];
	this.ToFlyNext=0;
}

FlyingObjects.prototype.createFlyingObjects=function(total_objs) {
	for(var i=0; i<total_objs; i++) {
		this.FlyingObjects[i]=new FlyingObj(this);
	}
}
FlyingObjects.prototype.FlyNextObject=function() {
	
	var CurrObj=this.FlyingObjects[this.ToFlyNext++];
	
	if (this.Settings.FlyingHandler) {
		this.Settings.FlyingHandler(CurrObj, this);
	} else {
		this.Settings.Container.appendChild(CurrObj.htmlHandle);
		CurrObj.reset();
		CurrObj.Fly();
	}
	
	
	if (this.ToFlyNext<this.FlyingObjects.length) {
		var theObj=this;
		setTimeout(function(){
			theObj.FlyNextObject();
		}, this.Settings.getNewObjInterval());
	}
}
FlyingObjects.prototype.StartFlying=function() {
	this.FlyNextObject();
}

/* FlyingObjectsSettings */
function FlyingObjectsSettings(container, class_name, available_content, speed_ratio, speedx, speedy) {
	this.AvailableContent=available_content;
	this.Container=$(container);
	this.ClassName=class_name;
	this.Speed={
		X:speedx*speed_ratio,
		Y:speedy*speed_ratio
	}
	this.getNewObjInterval=function(){
		return Math.rnd(7777, 9999, true);
	}
}