Reorder JS code so that JQuery conflicts won't occur