function mapRefresh() { $('.mapdata').load('game.php?cmd=viewmap', mapDraw()); setTimeout('mapRefresh()', <?=$cfg['view_refresh']?>); } function mapDraw() { //array of coords+imagefiles for our viewing area... var mapdata = $(".mapdata").text().substr(5).split(','); var i = 0; //iterate through all table cells with class 'map'... $('td').each(function () { var classes = $(this).attr('class').split(' '); for (var c in classes) { c = classes[c]; if (c.match('^map')) { //put the appropriate image in that cell along with some coordinates info. $(this).text('<img class="xxx' + mapdata[i++] + ' yyy' + mapdata[i++] + '" src="img/' + mapdata[i++] + '" />'); } } }); //delete the mapdata text when we're done. $(".mapdata").text(""); }