if (!leto.upload) leto.upload = {};

leto.upload.image = {
    change: function(f, n, w, h, src1, tn, tw, th, t1n, t1w, t1h) {
        n   = n.replace(/(\]|\[)/g, '\\$1');
        if (tn) tn = tn.replace(/(\]|\[)/g, '\\$1');
        if (t1n) t1n = t1n.replace(/(\]|\[)/g, '\\$1');
        src1 = src1.replace(/(\]|\[)/g, '\\$1');

        $.blockUI({ message: null });
        var ajax = new leto.ajax('/leto/upload/ajax/');
        var $input = $(f);
        ajax.onSuccess = function(r)
        {
            $('#' + n).val(r.image);
            if (tn) $('#' + tn).val(r.thumb);
            if (t1n) $('#' + t1n).val(r.thumb1);
            if (src1) {
                $('#' + src1).val(r.source);
            }
            $('#' + n + '_img').attr('src', r.thumb ? r.thumb : r.image);
            $.unblockUI();
        }

        var p = { file: f, width: w, height: h };

        if (tn) {
            p.thumb = { width: tw, height: th };
        }

        if (t1n) {
            p.thumb1 = { width: t1w, height: t1h };
        }

        if (src1) {
            p.source = src1;
        }

        ajax.query(p);
        return false;
    }
};

