changed functions so that it can be used with jQuery 1.4