Drag & drop - stateful behaviour

Drag & drop - stateful behaviour

Hello,

I have an application in which a user can drag a div within a main div.  Every time the inner div is moved I capture it's position the "main div".  The coordinates are saved in a database.  Once the user navigates away and back to the page, I'm trying to position the "moved div" to the position stored in the database.

Unfortunately, I'm not having much success in doing this.  Here's what I'm doing:

<div id="mainbox" style="width: 800; height: 400"><div id="dragme">drag me</div></div>

var mainBoxOffSet = $("#mainbox").offset();
var newY = dbY + mainBoxOffSet.top;
var newX = dbX + mainBoxOffset.left;
$("#dragme").offset({ top: newY, left:newX });

Have any of you ever done what I'm trying to accomplish (with cross-browser compatibility) or do you have suggestions on what I can do to make it work.  You can safely assume that I'm storing the right positions in the db (that much I know works).

Thanks you for your insight.