function refresh_image(field, img, block) {

    $('input[name="' + field + '"]').val(img).parent().css('display', 'none').parent().prepend(block);
    refresh_fancybox();
}

function refresh_fancybox() {
    $("a.image-thumbnail").fancybox({
        'speedIn': 600,
        'speedOut': 200,
        'overlayShow': true
    });
}
function remove_image(self, field) {
    $.post('{actions_link}', {upload_action: 'delete_image', img_delete: $('input[name="' + field + '"]').val(), field: field}, function(){
        self.parent().remove();
        $('input[name="' + field + '"]').val('').parent().css('display', '');
    });
}
$(function() {
    
    refresh_fancybox();
    
    $(document).on('click', '.delete-anchor', function(){
        var self = $(this);
        var field = self.attr('rel');
        
        if (confirm('{confirm_del}')) {
            
            remove_image(self, field);
            
        } else {
            
            return false;
        }
    });
});