Rewrite of plugin to work with jquery 1.9.1 and to be easier to understand/extend