/*
 * jQuery FAIL @VERSION
 *
 * Copyright (c) 2009 AUTHORS.txt (http://query.designbyfail.com/about)
 * Dual licensed under GPL (GPL-LICENSE.txt) licenses.
 *
 * http://jquery.designbyfail.com/help
 */
;(function($) {

    var help_item = null;
    var help_items = new Object;

    $.fetch_help_item = function(help_id) {
        if (help_id == undefined) return false;

        // check if already retrieved
        var exists = help_items[help_id];
        if (exists !== undefined) {
            return process_help_item(help_id);
        }

        var url = 'http://'+window.location.hostname+'/help/js_get_help_item/' + help_id;

        $.ajaxSetup({
            async: false
        });

        var xhr = $.getJSON(url, function(json, status){
            var data = (status == 'success') ? json : false;
            help_item = data;
            if (data !== false) {
                help_items[help_id] = help_item;
            }
            return help_item;
        });
    }

    $.get_help_item = function(help_id) {
        var item = help_items[help_id];
        if (item == undefined) {
            $.fetch_help_item(help_id);
            return $.get_help_item(help_id);
        }
        return item;
    }

})(jQuery);

