How to include php-generated javascript?

You can either not use wp_enqueue_script (which loads a JS file, where you won’t be able to use PHP) and instead simply print the script out on the wp_head or wp_footer hooks…. or you can use wp_localize_script()

wp_enqueue_script( 'some_handle' );

$instance = // not sure how you are fetching this value

$array = array( 'thumbs' => $instance["hasThumbs"], 
                'history' => $instance["historyEnabled"],
                'time' => $instance["transitionTime"] * 1000,
                'autoplay' => $instance["autoplayEnabled"]),
                'loop' => $instance["isLooped"]),
                'counter' => $instance["hasCounter"]),
                'zoomable' => $instance["zoomable"]),
                'hideFlash' => $instance["hideFlash"] );

wp_localize_script( 'some_handle', 'object_name', $array );

and then you’d modify your JS file to pull the values from the JS object called ‘object_name’ where the object’s properties correspond to the array keys from `wp_localize_script’

(function ($) {
                "use strict";
                $(function () {
                    var $gallery = $("#gallery").photogallery(
                            "a",
                            {
                                thumbs: object_name.hasThumbs,
                                history: object_name.history,
                                time: object_name.time,
                                autoplay: object_name.autoplay,
                                loop: object_name.loop,
                                counter: object_name.counter,
                                zoomable: object_name.zoomable,
                                hideFlash: object_name.hideFlash
                            }
                        );
                });
            }(jQuery));

error code: 523