Fix error that halts rendering on Firefox due to different hoisting behavior

Declaring a function inside a condition is a non-standard, and it looks like Firefox handles it differently than Webkit or IE, which broke rendering on FF but not on other browsers.