function selectWords(id, fn) {
    var objId = '#' + id;
    var callBack = typeof fn == 'function'? fn: null;

    function attachSelection() {
        $(objId).children('ul').children('li').each(function() {
            $(this).bind('click', function() {
                $(this).toggleClass('selected');
                return false;
            });
            $(this).hover(function(){
                $(this).addClass('mouseover');
                return false;
            }, function(){
                $(this).removeClass('mouseover');
                return false;
            });
        });
    }

    function getSelected() {
        var key = null;

        $(objId).children('ul').children('li.selected').each(function() {
            if (key == null) {
                if ($(this).html().indexOf(" ") >= 0){
                    key = ' \"' + $(this).html() + '\"';                
                }else {
                    key = $(this).html();
                }
            } else {
                if ($(this).html().indexOf(" ") >= 0){
                    key += ' \"' + $(this).html() + '\"';
                }else{
                    key += ' ' + $(this).html();
                }
            }
        });

        if (key == null) {
            alert(message['required']);
            return null;
        }

        if (key.length > 300) {
            alert(message['related_words_big']);
            return null;
        }

        return key;
    }

    attachSelection();

    return {
        bind: function() {
            attachSelection();
        },

        onActionClick: function(key) {
            var selected_items = getSelected();
            if (selected_items != null) {
                if (null != callBack) callBack(selected_items, key);
                return true;
            }
            return false;
        },

        onClearAllClick: function() {
            $(objId).children('ul').children('li').each(function() {
                $(this).removeClass('selected');
            });
            return false;
        }
    };
};
