add ability to use a custom document

This makes it easily possible to use in node.js with jsdom, you can either globally set the `exports.document` to the jsdom document object, or just pass it in on a one-off basis.