Call function on timer
<p>I have a function that advances a slideshow image when a user clicks a link:</p>

<pre><code>jQuery("a.next").click(function(e) {
    return ngg_ajax_navigation(e, this);
});
</code></pre>

<p>I'd like to have this happen automatically every 3 seconds in addition to when the user clicks the link. What's the best way to accomplish this?</p>

<p>Broader code:</p>

<pre><code>function ngg_ajax_browser_navigation(e, obj) {


// try to find gallery number
if ("ngg-prev-" == jQuery(obj).attr("id").substr(0, 9) || "ngg-next-" == jQuery(obj).attr("id").substr(0, 9)) {

    // extract the image-id
    var imageNumber = jQuery(obj).attr("id").substr(9);

    // find the image-browser-container
    var currentNode = obj;
    while (null != currentNode.parentNode &amp;&amp; !jQuery.nodeName(currentNode.parentNode, "body") &amp;&amp; !jQuery(currentNode.parentNode).hasClass("ngg-imagebrowser")) {
        currentNode = currentNode.parentNode;
    }

    if (jQuery(currentNode.parentNode).hasClass("ngg-imagebrowser")) {
        var gallery = jQuery(currentNode.parentNode);

        // let's extract the post id &amp; gallery id
        var payload = gallery.attr("id").substring(17);
        var separatorPosition = parseInt(payload.indexOf("-"));

        var galleryId = payload.substr(0, separatorPosition);
        var postId = payload.substr(separatorPosition + 1);

        if ( (galleryId.length == 0) || (postId.length == 0) ) {
            return true;
        }

        ngg_show_loading(e);

        // get content
        jQuery.get(ngg_ajax.callback, {p: postId, galleryid: galleryId, pid: imageNumber, type: "browser"}, function (data, textStatus) {
            // delete old content
            gallery.children().remove();

            // add new content
            gallery.replaceWith(data);

            // add ajax-navigation, again
            jQuery("document").ready(function(){
                // remove old listeners to avoid double-clicks
                jQuery("a.ngg-browser-next").unbind("click");
                jQuery("a.ngg-browser-prev").unbind("click");

                // add shutter-listeners again
                shutterReloaded.init('sh');

                // register ajax browser-navigation listeners
                jQuery("a.ngg-browser-next").click(function(e) {
                    return ngg_ajax_browser_navigation(e, this);
                });
                jQuery("a.ngg-browser-prev").click(function(e) {
                    return ngg_ajax_browser_navigation(e, this);
                });

                setInterval(function(){
                    jQuery("a.ngg-browser-next").click();
                }, 3000);

                ngg_remove_loading();
            });
        });

        // deactivate HTML link
        return false;
    }
}

return true;
</code></pre>

<p>}</p>
