Profile JS refactor, use JQuery cookie

@AlasdairSwan please review.  (I've included your commits in this PR -- once you merge that branch, I'll rebase so this includes only my changes).