if you call the function:
get_random_cat_image(CATEGORY_ID)
you'll recive an random image of one nested produkt. If theres no produkt in that category, there will be searched in all sub-categorys until an produkt is found.
If theres no produkt found, it wil retun 'empty.gif'
Legend: 
Download

Report
* Optimized SQL-Querry
* Not showing the "empty" image when one subcategory has an image
* definig EMPTY_CAT_IMAGE in the random_cat_images.php for different "empty" image
http://forums.oscommerce.com/index.php?showtopic=249258
I have made a little speed fix...
Worked like an absolute charm.
For those who couldn't figure out how to install it, and due to the poor english, I've enclosed a new file for this contribution with the english improved upon, and the instructions better laid out for newbies. Yes, it actually contains instructions now!
Thank you VERY much, ComBo, for this excellent contribution.
*****NO File added******
How do u install this one? No instructions included. =(
*****NO File added******
if you call the function:
get_random_cat_image(CATEGORY_ID)
you'll recive an random image of one nested produkt. If theres no produkt in that category, there will be searched in all sub-categorys until an produkt is found.
If theres no produkt found, it wil retun 'empty.gif'