Take into account device rotation. Refactor as a proper jQuery plugin.