Fix #1322

https://github.com/mybb/mybb/issues/1322
Also simplified the file a bit using chaining and variables so jQuery
won't have to look for selector multiple times for no reason.
http://stackoverflow.com/questions/2070097/jquery-bad-practices?answertab=votes#tab-top