Setting-up Thumbnail Grid Load Order

I am trying to get my thumnails to load in rows, 22 across, and up to 3 rows down. However, I can’t seem to get my math right. I can get them to load up and down 3 rows, but not across first. Can anyone explain the math required to accomplish this?

Here is the file I am working with:

http://www.jbnight.com/flash/gallery.zip

Thanks!