Interface.profile = {
    id: 0,
    
    button: '',
    buttonSelector: '.uploader span.button',

    progress: {
        object: '',
        selector: '.progress',

        init: function() {
            this.object = $(this.selector);
        }, 

        show: function() {
            this.object.css('display', 'block');
        },

        hide: function() {
            this.object.css('display', 'none');
        }
    },

    errors: {
        selector: '.uploader-errors',

        removeAll: function() {
            $(this.selector).remove();
        }
    },

    init: function() {
        Interface.profile.button = $(Interface.profile.buttonSelector);
        Interface.profile.progress.init();

        new AjaxUpload(Interface.profile.button, {
            action: '/profile/ajax-logo-upload/' + Interface.profile.id,
            name: 'logo',
            
            onSubmit : function(file, ext){
                Interface.profile.button.hide();
                Interface.profile.progress.show();
                Interface.profile.errors.removeAll();
            },

            onComplete: function(file, response){
                Interface.profile.button.show();
                Interface.profile.progress.hide();
                
                $('div.uploader').replaceWith(response);
                Interface.profile.init();
            }
        });
    }
};

