From the jQueryUI website, the example with snap on draggable() has the following code:
<script type="text/javascript">
$(function() {
$("#draggable").draggable({ snap: true });
$("#draggable2").draggable({ snap: '.ui-widget-header' });
$("#draggable3").draggable({ snap: '.ui-widget-header', snapMode: 'outer' });
$("#draggable4").draggable({ grid: [20,20] });
$("#draggable5").draggable({ grid: [80, 80] });
});
</script>
So I think snap: '#mainwindow'
might do the trick. Also, I haven't tried this so I'm not sure if its possible (others can correct me since I'm not familiar with jQueryUI, although it looks awesome) but what if you create a callback function to handle the snap event:
$($element).draggable({
snap: function(event, ui) {/* insert functionality */}
});