	var cwidth=640;
		var cheight=480;
		
		var stararray = new Array();
		
		function square(value)
		{
			return value*value;
		}
		
		function Star()
		{
			this.speed = 3;
			
			this.norm_x = 0;
			this.norm_y = 0;
			
			this.x = 0;
			this.y = 0;
			this.starsize = 3;
			
			this.get_normalized = get_normalized;
			this.move = move;
			this.reset = reset;
			
			function get_normalized(centerx,centery)
			{
				var x1 = cwidth/2;
				var y1 = cheight/2;
				var x2 = this.x;
				var y2 = this.y;
				
			
				var length = Math.sqrt((square(x2 - x1)) + (square(y2 - y1)));


				
				this.norm_x = (x2 - x1) / length;
				this.norm_y = (y2 - y1) / length;
				

				
			}
			
			function reset()
			{
				this.x = Math.floor(Math.random() * cwidth);
				this.y = Math.floor(Math.random() * cheight);
				this.get_normalized(cwidth/2,cheight/2);
				this.speed = Math.random() * 20 + 5
			}
			
			function move()
			{
				
				//this.x++;
				//this.y++;
				this.x += this.norm_x * this.speed;
				this.y += this.norm_y * this.speed; 
				
				if(this.x < 0 || this.x > cwidth)
				{
					this.reset();
				}
				
				if(this.y < 0 || this.y > cheight)
				{
					this.reset();
				}
				
				
			}
			
			
		}
		
		function genstars(amount)
		{
			var i;
			for(i=0;i<amount;i++)
			{
				stararray[i] = new Star();
				stararray[i].reset();
				//stararray[i].starsize = 3;
				
			}
			
			
		}
		
		function timer()
		{
			
			//move stars
			for(i=0;i<stararray.length;i++)
			{
				stararray[i].move();
			}
			
			drawstars();
			
		}
		
		
		function drawstars() {
		 var canvas = document.getElementById("canvasbg");
		 var ctx = canvas.getContext("2d");
		
		ctx.fillStyle = "rgb(0,0,0)";
		ctx.fillRect(0,0,cwidth,cheight);
		

		 for(i=0;i<stararray.length;i++)
		 {
		 	var x = stararray[i].x;
		 	var y = stararray[i].y;
		 	var starsize = stararray[i].starsize;
			ctx.fillStyle = "rgb(255,255,255)";
		 	ctx.fillRect(x,y,starsize,starsize);
		 }
		 
		}
		
		
		function body_onload()
		{
			genstars(100);
			drawstars();
			
			setInterval("timer()",100);
			
		}
