try using an array for the variables
var cells = new Array();
var elements = new Array();
run a for loop to run it as many times you want
for(i=0;i<NUMBER_REQUIRED;i==0{
cells[i] = row.insertCell(0);
elements[i] = document.createElement("img");
elements[i].src = imagePath + (i+1)+"_tn.jpg";//since i starts from 0 and you require 1, hence (i+1);
cells[i].appendChild(elements[i]);
}
hope this helps