Here is my HTML/JavaScript:
You're placing the function's scope within another function, basically.
Picture this:
That is the facsimile of what you're trying to accomplish. Just like variables defined within a function are off limits outside of it, function names take on the same characteristics.
Side-Note JavaScript doesn't require $ prefix on variable names (though is acceptable as far as names are concerned). I didn't know if you're coming from PHP and are just accustomed or were aware.
Thought I'd make my comment an answer.