Using platform.js to get this working on Firefox

Had to make some compromises to get this to work, but it runs on
Firefox 30 and Chrome 36! \o/
Able to move the templates back!

By using both the real document and the shimmed ownerDocument, this works again! Much closer to the original version :)
whitespace fixes to make the diffs nicer
and more whitespace fixes
Now works in both Chrome & Firefox!

Feature detection FTW!