Thumbnail Fade In/Out in AS and Math Help Please

I am having thumbnail problems. Thanks to everyone on this board, I have a good XML gallery working, but I want to change some things and add some beauty.

To start out with, I want the thumbnails to load across, till they have no more room (22 photos) and then to make a new line below that, so I can have at least 3 lines if there are enough photos in each section. I have played with the math like crazy, but can’t get it to work, although I do get some interesting results sometimes!

Second, I want the thumbnails to fade up to 100% opacity when the mouse rolls over them, and fade out when the mouse goes away, with the ability to change the speed they fade. I think it has something to do with the AS I already have there, some kind of conflict, cause the AS I have used before just isn’t working.

Can anyone help me out? I at least need a good resource to figure out the math and what I’m doing wrong with the fades. Thank you!

Here is the file stuff: