var ctx, canvasHeight, canvasWidth;
        var ParticleArray = [];
   
        $(function() {
       
            SetupCanvas();
			
			if (ctx != null)
			{
				AddParticles(5);

				setInterval(Draw, 50);
			}
        });
       
        function SetupCanvas()
        {
            var thisCanvas = $('#thisCanvas')[0];
           
            if (thisCanvas && thisCanvas.getContext)
            {
                canvasHeight = $(thisCanvas).height();
                canvasWidth =  $(thisCanvas).width();
           
                ctx = thisCanvas.getContext('2d');
                ctx.globalCompositeOperation = "lighter";
            }
        }
       
        function Draw()
        {
            ctx.clearRect(0, 0, canvasWidth, canvasHeight);

            $(ParticleArray).each(function() {
                this.Draw();
            });
        }
		
		function AddParticles(i)
        {
			for (var index = 0; index < i; index++)
			{
				ParticleArray.push(new Particle(Math.rand(20, canvasWidth-20), Math.rand(20, canvasHeight-20)));
			}
        }
       
        function AddParticle()
        {
            ParticleArray.push(new Particle(Math.rand(0, canvasWidth), Math.rand(0, canvasHeight)));
        }
       
        function Particle(xCoord, yCoord)
        {
            var particleRadius = Math.rand(2, 12);
            var direction = Math.rand(1, 10);
            var speed = Math.rand(1,2);
            var startColor = "rgba(" + 228 + "," + 191 + "," + 129 + "," + Math.rand(1,40)/10 + ")";
            var endColor = "rgba(" + 201 + "," + 112 + "," + 18 + ",0)";
           
            var x = xCoord;
            var y = yCoord;
           
            this.Draw = function()
            {
                // Move the particle.
                x += Math.sin(direction) * speed;
                y += Math.cos(direction) * speed;
               
                // If the particle position is outside the canvas, move it to the opposite side.
                if (x > canvasWidth - 20)
                    direction -= 90;
                else if (x < 20)
                    direction -= 90;
                else if (y >= canvasHeight - 20)
                    direction -= 90;
                else if (y < 20)
                    direction -= 90;
               
                // Draw the particle.
                DrawGradient(x, y);
               
                // Add extra gradients temporarily so it appears the particle
                // is wrapping around the screen.
                if (x > canvasWidth - particleRadius)
                    DrawGradient(x - canvasWidth, y);
                else if (x < particleRadius)
                    DrawGradient(canvasWidth + x, y);
                   
                if (y > canvasHeight - particleRadius)
                    DrawGradient(x, y - canvasHeight);
                else if (y < particleRadius)
                    DrawGradient(x, y + canvasHeight);
            };
           
            function DrawGradient(a, b)
            {
                var p = ctx.createRadialGradient(a, b, 0, a, b, particleRadius);
               
                p.addColorStop(0, startColor);
                p.addColorStop(1, endColor);
           
                ctx.fillStyle = p;
                ctx.fillRect(a - particleRadius, b - particleRadius, particleRadius * 2, particleRadius * 2);
            }
        }
       
        Math.rand = function(l,u)
        {
            return Math.floor((Math.random() * (u-l+1))+l);
        }

