Optimise tight loop on foundation.js

We should avoid jQuery selector repeats. Here I have cached the $('head') calls occurring on lines 17 and 18
Merge pull request #4426 from jackmahoney/master

Optimise tight loop on foundation.js