Converted into jquery plugin