jQuery.fn.extend({
    disableCtrlKeys: function(key, callback) {
        if(typeof key != 'object') key = [key];
        callback = callback || function(){ return false; }
        return $(this).bind('keydown',function(e) {
            var ret = true;
            $.each(key,function(i,k){
                if(e.keyCode == k.toUpperCase().charCodeAt(0) && e.ctrlKey) {
                    ret = callback(e);
                }
            });
            return ret;
        });
    },

    enableCtrlKeys: function() {
        return $(this).unbind('keydown');
    },

    disableSelection: function() {
        $(window).disableCtrlKeys(['a','s','c']);
        return this.each(function() {
            $(this).attr('unselectable', 'on')
                   .css({
                       '-moz-user-select':'none',
                        '-o-user-select':'none',
                        '-khtml-user-select':'none',
                        '-webkit-user-select':'none',
                        '-ms-user-select':'none',
                        'user-select':'none'
                   })
                   .each(function() {
                       this.onselectstart = function() { return false; };
                   });
        });
    },

    enableSelection: function() {
        $(window).enableCtrlKeys();
        return this.each(function() {
            $(this).removeAttr('unselectable')
                   .css({
                       '-moz-user-select':'',
                        '-o-user-select':'',
                        '-khtml-user-select':'',
                        '-webkit-user-select':'',
                        '-ms-user-select':'',
                        'user-select':''
                   })
                   .each(function() {
                       this.onselectstart = function() { return true; };
                   });
        });
    }
});
