Ok let's say I'd have two main categories men and women but also brand based product listings. I'd need to be able to sort products on the basis of man or woman regardless of what page I'm in.

This would be easy to achieve with jquery and some cookies, however what I'd need for it is right product classes. So is there a way to query product category names or number ids to every product on product listing page?

So let's say if a product is linked to categories brand, accessory, women, then the product listing product wrapper would query these to classes so that

<div id="product-wrapper" class="brand accessory women">
<img>
<title>
etc.
</div>

Please help! And many thanks for all answers!