jQuery(document).ready(function($){
    if($('.alora_upload_button').length >= 1) {
        window.alora_uploadfield = '';

        $('.alora_upload_button').live('click', function() {
            window.alora_uploadfield = $('.upload_field', $(this).parent());
            tb_show('Upload', 'media-upload.php?type=image&TB_iframe=true', false);

            return false;
        });

        window.alora_send_to_editor_backup = window.send_to_editor;
        window.send_to_editor = function(html) {
            if(window.alora_uploadfield) {
                if($('img', html).length >= 1) {
                    var image_url = $('img', html).attr('src');
                } else {
                    var image_url = $($(html)[0]).attr('href');
                }
                $(window.alora_uploadfield).val(image_url);
                window.alora_uploadfield = '';
                
                tb_remove();
            } else {
                window.alora_send_to_editor_backup(html);
            }
        }
    }
});