Hovering Caption Problem

I’m currently working on a thumbnail gallery for a site and I’m trying to modify the hovering caption tutorial here on kirupa so that I can have the size of the caption box change with the amount of text i have to put in for each thumbnail, but since i’m kinda new to this i’m not really sure how to accomplish this, so help would be extremely nice.