/**
 * @author Klaus Hartl
 * @author modified by Krzysztof Kotowicz <koto at webworkers dot pl>
 * @see http://groups.google.com/group/jquery-ui/browse_thread/thread/c728b8464f669674/711a7b0dd4236190?lnk=gst&q=tabs+links+ajax#711a7b0dd4236190
 * @param fun function to always call after hijacking (will be run in the same context as hijack())
 */
jQuery.fn.hijack = function(fun) {
    var target = this;

    return this
        .find('a:not(.nohijack)').click(function() {
           $(target).load(this.href, function() {
               $(this).hijack(fun);

               if (jQuery.isFunction(fun)) {
                 fun.call(this);
               }

           });

           return false;
        })
        .end()
        .find('form:not(.nohijack)').each(function() {
            if (jQuery.fn.ajaxForm)
                $(this).ajaxForm({
                    target: target,
                    beforeSubmit: function(fdata, jqForm, options) {
                        if (jqForm.data('skip')) { // some submit handler (validation method?) told us to stop
                            jqForm.data('skip', false); // clear
                            return false;
                        }
                    },
                    success: function() {
                        $(target).hijack(fun);

   		                if (jQuery.isFunction(fun)) {
		                  fun.call(target);
		                }
                    }
                });
        });
};