Making windows snap to grid problem

I am attempting to get all the windows that are generated to snap to a grid at distances of 10 pixels. I am not sure how I could implement jquery-ui with this. Attached is a picture of the actual windows. Any help would be great.