This is the main fix: move the extend of defaults from the bottom to options defined on top (similar to what we did for gallery.dialog.js).  The rest is basically formatting.