var Engine = {
	curves	: Array(),
	p		: 0,
	width	: 0,
	height	: 0,
	canvas	: null,
	ctx		: null,
    
    initialize: function() {
    	this.canvas = $('#Lines').get(0);

		setTimeout(this.call(function() {
	    	this.ctx    = this.canvas.getContext('2d');	

			this.reset();

			$(window).resize(this.call(this.reset));
			setInterval(this.call(this.render), 40);			
		}), 1000);
	},

	reset: function() {
		this.width  = $(window).width()+100;
		this.height =  $(window).height()+100;
		this.curves = Array();
		this.p		= 0.01;
		
		this.curves.push(new Curve(this));

	    $(this.canvas).attr('width', $(window).width()).attr('height', $(window).height());	
	},

	render: function() {
		this.ctx.clearRect(0,0, this.width, this.height);

		this.curves[this.curves.length-1].drawTo(this.p);
	
		if (this.curves.length > 1) {
  	  		for (var i = this.curves.length-2; i >= 0; i--) {
				this.curves[i].draw();
    		}  
  		}
  
		this.p += 0.005;

		if (this.p > 1) {
			this.p = 0.01;
			this.curves.push(new Curve(this));
    
			if (this.curves.length > 4) {
      			this.curves[0].remove();
    		}
		}
	}
};
Engine = Class.create(Engine);
