Ohhhh yeah, worked it out. Thank you Lynne for saying something that made me work it out.
Answer: Ok in order for custom Java to work in your pages you need to add the script into the global header. Because this is included in every page you need to make sure your variables are long and preferably complicated so there are no conflicts within the forum.
Admin CP -> Styles & Templates -> Style Manager ->
Expanding all the styles you want it to work in (<< >>) find in each one "headinclude" under "Forum Home Templates".
Make a backup of the old headinclude and add your Javascript to the bottom of headinclude after
ALL previous tags have closed.
If your variables are as I suggested then you should encounter no conflicts and all should work fine.