/// class PD.BCL.Util

/*
    Debounce:
    http://unscriptable.com/2009/03/20/debouncing-javascript-methods/
    http://www.paulirish.com/2009/throttled-smartresize-jquery-event-handler/
*/

PD.BCL.Util = Class.extend({
});

PD.BCL.Util.debounce = function (func, threshold, execAsap) {

    var timeout;

    return function debounced() {

        var that = this,
            args = arguments;

        function delayed() {
            if (!execAsap) {
                func.apply(that, args);
            }
            timeout = null;
        };

        if (timeout) {
            clearTimeout(timeout);
        }
        else if (execAsap) {
            func.apply(that, args);
        }

        timeout = setTimeout(delayed, threshold || 100);

    };

};