/* Author: 
Mellifico pour Supercellule
*/
var balls = new Array();

var msec_frame = 33;
   
canvas = document.getElementById("home");

var canvas2d = canvas.getContext('2d');


function Ball(x, y, xsee, ysee, r, g, b, a) {

	this.x = x;
	this.y = y;
	this.xsee = xsee;
	this.ysee = ysee;
	this.r = r;
	this.g = g;
	this.b = b;
	this.a = 0.4 ;
	this.color = "rgba("+this.r+", "+this.g+", "+this.b+" ,"+this.a+")";

}

function draw() {
   
   var canvas = document.getElementById('home');
   var canvas2d = canvas.getContext('2d');
   canvas2d.fillStyle = "rgb(255, 255, 255)";
canvas2d.fillRect(0, 0, canvas.width, canvas.height);
      
   canvas2d.fillStyle = "rgb(255, 255, 255)";
   for(var i=0; i < balls.length; i++) {
      canvas2d.fillStyle = balls[i].color;
      canvas2d.beginPath();
    	canvas2d.arc(balls[i].x, balls[i].y, 30, 0, Math.PI*2, true);
    	canvas2d.closePath();
    	canvas2d.fill();
	}
	
}
   
function move() {
   
   for(var i=0; i < balls.length; i++) {
      var b = balls[i];
      
      if(b.x > (canvas.width-5)) {
			b.x = (canvas.width-5);
			b.xsee = -b.xsee;
      }  else  if(b.x < 5) {
			b.x = 5;
			b.xsee = -b.xsee;
      }

    	if(b.y > (canvas.height-5)) {
    		b.y = (canvas.height-5);
    		b.ysee = -b.ysee;
    	}  else if(b.y < 5)  {
    		b.y = 5;
    		b.ysee = -b.ysee;
    	}

    	b.x+= b.xsee;
    	b.y+= b.ysee;
      
   }
}
   
function clock() {
   var d = new Date();
   var start_time = d.getTime();

   move();
   draw();
      
   d = new Date();
   var time_diff = d.getTime() - start_time;
   if (time_diff >= msec_frame) time_diff = 0;
   else time_diff = msec_frame - time_diff;

   window.setTimeout('clock()', time_diff);
}
   
function init() {
   for(var i=0; i < 24; i++) {
      balls.push(new Ball(Math.random() * (canvas.width-10), Math.random() * (canvas.height-10), Math.random() * 5.5 - 2.75, Math.random() * 5.5 - 2.75, Math.round(Math.random()*200)+50, Math.round(Math.random()*200)+50, Math.round(Math.random()*200)+50));
   }
   window.setTimeout('clock()', 20);
}
   
init();

$("#brand h1").lettering();	


