refactored for legibility

added comments
removed optimization tricks for legibility purposes
cleaned up to pass jshint
changed type checking methods (don't use instanceof)
add alternate optimized version

this is the same as previous commit's demibox.js - it's hard to read but
has tricks to reduce minified size.