(function(){
    var arr = [];

    jQuery.extend({
        anchorHandler: {
            add: function(regexp, callback) {
                arr.push({'regexp': regexp, 'callback': callback});
                window.onhashchange = function(){$.anchorHandler.compile()};
                return this;
            },
            compile: function() {
                // new anchor
                anchor = document.location.hash;
                $.each(arr, function(){
                    var match = anchor.match(this.regexp) || false;
                    if (match) {
                        this.callback.apply(this, [anchor.replace('#', '')]);
                    }
                });
            }
        }
    });
})();