var faq_form = {
    settings: {
        fileType_autocomplete_url: '',
    },
    init: function() {
        this.initAutocomplete();
        this.bindElements();
        this.fileField_arrangeIndexes();
        this.fileField_bindRemove();
    },
    initAutocomplete: function() {
        global.autocomplete.bind(this.settings.fileType_autocomplete_url, '#faq_fileType_desc', '#faq_fileType');
    },
    bindElements: function() {
        jQ('#href-new-file-field').unbind('click').bind('click', this.newFileField);
    },
    newFileField: function() {
        var div_ig = jQ('<div/>'),
            div_igb = jQ('<div/>'),
            btn = jQ('<button/>'),
            input_file = jQ('<input/>');

        div_ig.addClass('input-group').addClass('no-margin-bottom');
        div_igb.addClass('input-group-button');
        btn.attr('type', 'button').addClass('button secondary').addClass('file-field-remove').html('<i class="fa fa-remove"></i>');
        input_file.attr({
            type:'file',
            accept : ''
        }).addClass('input-group-field');

        div_igb.append(btn);
        div_ig.append(input_file).append(div_igb);

        jQ('#file-field-container').append(div_ig);

        faq_form.fileField_arrangeIndexes();
        faq_form.fileField_bindRemove();
    },
    fileField_arrangeIndexes: function() {
        jQ('#file-field-container .input-group').each(function(key){
            jQ(this).attr('id', 'file-field-input-group-' + key).data('key', key);
            jQ(this).find('input[type=file]').attr('name', 'files[' + key + ']');
            jQ(this).find('button').data('key', key);
        });
    },
    fileField_bindRemove: function() {
        jQ('.file-field-remove').unbind('click').bind('click', function(){
            jQ('#file-field-input-group-' + jQ(this).data('key')).remove();
            patient_letter_form.fileField_arrangeIndexes();
        });
    },
};