(function ($) {

function delayedaction (action, time) {
    if (time === undefined) { time = 1000; }
    var timeout_id = null;
    var that = {};
    function cancel () {
        if (timeout_id !== null) {
            window.clearTimeout(timeout_id);
            timeout_id = null;
        }
    }
    that.cancel = cancel;
    function performAction () {
        action();
        timeout_id = null;
    }
    that.do_soon = function () {
        cancel();
        timeout_id = window.setTimeout(performAction, time);
    };
    that.do_now = function () {
        performAction();
    };
    return that;
}
$.delayedaction = delayedaction;

$.random_int = function (lo, hi) {
    return Math.floor(lo + (Math.random()*(hi-lo+1)));
}

$.random_choice = function (l) {
    return l[$.random_int(0, l.length-1)];
}

})(jQuery);


