Made several optimizations to reduce repeated JQuery selector statements, slower $.each and loop statements.  Reformatted code to get closer to JSLint friendly formatting.