Placed the functionality in a jquery plugin, updated changepic and upload widget with this functionality