I'll tell you how you can set this up.
make a mysql table that stores the skin name / type / link to image / link to skin / id.
now here is your two queries:
"select distinct(type) from skins"
while (fetch (first query) ) {
"select * FROM skins where type = \"query1[type]\" ORDER BY RAND() LIMIT 1"
}
that should get you started. of course you'll have to modify it a bunch but you get the jist of those two queries.