As I promised, here is the working demo (available from my webpage):
Download linkI was making it too complicated.. It's probably too complicated even now, but it's the simplest way I can think of right now.
I'll be really grateful if anyone will share his/her more elegant way of determining which side is facing upwards.
Best regards!