Your function, productfancybox
is scoped locally to the anonymous function called on window load. Once that occurs, it goes away and no longer exists.
Instead, you need to define your function in the global namespace (i.e. not inside a call like this), or and preferably, create a namespace and define your function there:
var MyAwesomeNamespace = MyAwesomeNamespace || {};
MyAwesomeNamespace.productfancybox = function (id) {
...
}
Then later, you can call:
MyAwesomeNamespace.productfancybox(1);
Anywhere in your code, after that script has run. This is just a simple example. There's better ways to set up a library for your application. Here's a basic primer you can work from: http://css-tricks.com/how-do-you-structure-javascript-the-module-pattern-edition/.