var Pixelspark = {
	timerInterval: 60, // 1/(Aantal FPS) voor de bewegende bubbeltjesdinges
	particlesHeight: 500,
	particlesWidth: 500,
	particlesTick: function() {
		for(var a=0;a<Pixelspark._particles.length;a++) {
			var p = Pixelspark._particles[a];
			
			var x = parseFloat(p.style.left);
			var y = parseFloat(p.style.top);
			
			var dir = p.getAttribute('dir');
			var speed = p.getAttribute('speed');
			var nx = x+(speed*Math.cos(dir));
			var ny  = y+(speed*Math.sin(dir));
			//var ny = y;
			
			if(nx>(Pixelspark.particlesWidth+150) || ny>(Pixelspark.particlesHeight+150) || ny < -150 || nx < -150) {
				var size = Math.random()*150;
				p.style.width = p.style.height = size+"px";
				nx = (Pixelspark.particlesWidth/2 - size/2) + 20;
				ny = (Pixelspark.particlesHeight/2 - size/2) - 40;
				p.style.opacity = 0.0;
				p.lifetime = 0.0;
			}
			
			p.lifetime += 0.003;
			p.style.left = nx+"px";
			p.style.top = ny+"px";
			var opacity = 5*(Math.pow(p.lifetime,2)-Math.pow(p.lifetime,3));
			p.style.opacity = opacity*0.3;

		}
		setTimeout("Pixelspark.particlesTick()", Pixelspark.timerInterval);
	},

	initializeParticles: function(paths) {
		var particles = document.getElementById('particles');
		this.particlesHeight = particles.clientHeight;
		this.particlesWidth = particles.clientWidth;		
		Pixelspark._particles = new Array();
		for(var a=0;a<20;a++) {
			var p = document.createElement("img");
			p.src = paths[Math.floor(Math.random()*paths.length)];
			var size = Math.random()*100 + 50;
			p.style.left = (this.particlesWidth/2-size/2+20) + "px"; //(Math.random()*this.particlesWidth)+"px";
			p.style.top = (this.particlesHeight/2-size/2-40) + "px"; //(Math.random()*this.particlesHeight)+"px";
			p.style.width = size+"px";
			p.style.height = size+"px";
			p.style.opacity = 0.0;
			p.lifetime = 0.0;
			p.setAttribute('dir', Math.random()*6.282);
			p.setAttribute('speed',Math.random()*1.5);
			
			particles.appendChild(p);
			Pixelspark._particles[a] = p;
		}
		
		Pixelspark.particlesTick();
	}
}

