$(document).ready(function() {
    
    
    // Change the style of the save button if an input in the
    // form has been changed
    $(".talent_category input[type=text]").keyup(function() {
        $(this).doTimeout('typing', 400, function() {
            var form = $(this).closest('form');
            var submit = form.find('.save_profile_changes');
            submit.show().removeClass('saved').addClass('changed').val('Save Changes');
        });
        
    });
    
    // Submit each form in an ajaxy manner, change save button
    // when done.
    $('.talent_category form').ajaxForm({
        
        dataType : 'json',
        success  : function(json) {
            
            var form = $(this).closest('form');
            var submit = form.find('.save_profile_changes');
            if(json.success) {
                var talent_header = $('#talent_header');
                var success_message = $('<h1 id="ajax_feedback" class="positive_feedback">Changes to talents saved</h1>')
                talent_header.append(success_message);
            } else {
                submit.val('Try Again');
            }
        }
    });
    
});
