Converted some javascript into Jquery