Rafactored the js into cordova 3 style