(function ($) {
    $.field_tags = function (element, options) {
        var defaults = {
            tags: [],
            tags_selected: []
        }
        var plugin = this;
        plugin.settings = {}
        var $element = $(element), 
            element = element;
        plugin.init = function () {
            plugin.settings = $.extend({}, defaults, options);
            
            $element.find('select.list-tag').select2({tags: plugin.settings.tags});
            $element.find('select.list-tag').val(plugin.settings.tags_selected).trigger('change')
        };
        plugin.example_function = function () {
        };
        plugin.init();
    }
    
    $.fn.field_tags = function (options) {
        
        return this.each(function () {
            
            if (undefined == $(this).data('field_tags')) {
                var plugin = new $.field_tags(this, options);
                $(this).data('field_tags', plugin);
            }
        });
    }
})(jQuery);
