transformed the code into jquery plugin