DuplicateMovieClip to right and down

I can’t seem to find the answer to my problem, though I have a gut-feeling that the solution is overly simple…

I have a database with images and I want them to show up in a gallery-overview, like a matrix of images.
Through an XML file I get the total of images. Based on that number I want the overview to be built, stopping the duplication of movieclips when the total of images is reached. So you kinda get something like this:


See? It stops when the amount of 13 is reached and doesn’t continue to fill up the third row.

If anyone can help, I’d greatly appreciate it!