var tire_rows=20;
var tire_cols=15;
var cell_size =100;
function   test(rows,cols,cellwidth,cellheight){
	
	var table =document.createElement("table");
	for(var i=0;i<rows;i++)
	{
		var row=table.insertRow(i);
		for(var j=0;j<cols;j++)
			{
			   var cell =row.insertCell(j);
			   cell.style.cellwidth+"px";
			   cell.style.cellheight+"px";
			}
	}

	return table;
	
}


var tire_table;
var currentfall =[
                  {x:tire_cols/2-1,y:0},
                  {x:tire_cols/2,y:0},
                  {x:tire_cols/2,y:1},
                  {x:tire_cols/2+1,y:1},
                  
                  ];


 window.onload =function()
 {
	var tire_table= test(tire_rows,tire_cols,800,600);
	 tire_table.border=1;
	 tire_table.style.borderCollapse="collapse"; 
	document.body.appendChild(tire_table);
	
	for(var i=0;i<currentfall.length;i++)
	{
	
	  var cur =currentfall[i];
	  tire_table.rows[cur.y].cells[cur.x].style.backgroundColor ="blue";
	
	}
		
	setInterval(fall,1000);
	
 };



function fall()
{
	
	for(var i=0;i<currentfall.length;i++)
	{	  
	  var cur =currentfall[i];	  
	  tire_table.rows[cur.y].cells[cur.x].style.backgroundColor ="white";
	  
	}
	
	
	var canfall=false;
	
	for(var i=0;i<currentfall.length;i++)
	{
	  var cur =currentfall[i];
	  if(cur.y>=tire_rows-1)
	  {
		  canfall =false;
		  
		  break;
	  }
	}
	

	if (canfall) {
		for ( var i = 0; i < currentfall.length; i++) {
			var cur = currentfall[i];
			cur.y++;
			
		}
	}
	

	
	for(var i=0;i<currentfall.length;i++)
	{
	
	  var cur =currentfall[i];
	  
	  tire_table.rows[cur.y].cells[cur.x].style.backgroundColor ="blue";
	  
	}
}