Drag n drop, clone, rotate on one object

Drag n drop, clone, rotate on one object

Hello 

I have a problem. I am new in jquery. I neet do following things.

I have 10 square puzzles (unlimited quantity) wich i have put on a grid and then on mouse click rotate right 90 angle (unlimited times)

I found in the net this:


and this

http://jqueryui.com/draggable/#snap-to (I base on this script - last square)

and this


But i have no idea how put it together to one object.