
jQuery.fn.keyboard = function(options){
    options = jQuery.extend({
        push:   'kb-push',      // класс при нажатии
        over:   'kb-over',      // класс при наведении
        output: 'kb-out',       // класс инпута куда будем выводить, елси класс дефолтный то будет в первый найденный в контейнере инпут
        revert: 'kb-revert',    // класс дива или ссылки с 
        toHtml: false,          // пишем в html или в val
        allowedArray: []
    },options);
    return this.each(function() {
        // код
        var container = $(this);
        container.find('li').mousedown(function(){
            $(this).addClass(options.push);
        });
        container.find('li').mouseup(function()
        {
            $(this).removeClass(options.push);
            if(options.output=='kb-out' && container.find('input:text').first().size())
                container.find('input:text').first().val(container.find('input:text').first().val()+$(this).html());
            else
            if(options.toHtml)
                container.find('.'+options.output).first().html(container.find('.'+options.output).first().html()+$(this).html());
            else
                container.find('.'+options.output).first().val(container.find('.'+options.output).first().val()+$(this).html());
        });
        container.find('li').mouseover(function(){
            $(this).addClass(options.over);
        });
        container.find('li').mouseout(function(){
            $(this).removeClass(options.over);
            $(this).removeClass(options.push);
        });
        container.find('.'+options.revert).click(function(){
            if(options.output=='kb-out' && container.find('input:text').first().size())
                container.find('input:text').first().val(container.find('input:text').first().val().substr(0, container.find('input:text').first().val().length-1));
            else
            if(options.toHtml)
                container.find('.'+options.output).first().html(container.find('.'+options.output).first().html().substr(0, container.find('.'+options.output).first().html().length-1));
            else
                container.find('.'+options.output).first().val(container.find('.'+options.output).first().val().substr(0,container.find('.'+options.output).first().val.length-1));
        });

        if(container.find('input:text').first().size())
            container.find('input:text').first().keypress(function(e,ui){
                //console.log(options.allowedArray.indexOf(String.fromCharCode(e.keyCode)));
                //console.log(String.fromCharCode(e.keyCode));
                //console.log(e.keyCode);
                if(e.keyCode==46 || e.keyCode==8) return true;


                if(options.allowedArray.indexOf(String.fromCharCode(e.keyCode))==-1) return false;
                return true;
            });
    });
};

