function resize_images(o){
    if ( $(document.body).data('image_resize') ) {
        o.delayed = true;
        $(document.body).one('resized', o,function(e){
            resize_images(e.data);
        });
    }
    else {
        instance = $(document.body).data('current_resize_instance') || 0;
        $(document.body).data('current_resize_instance', ++instance);
        $(document.body).data('image_resize',true);
    	var imgs = $(o.selector ? o.selector + ' img' : '.postbody img').not('.signature_div img').addClass('resize_img');
    	refs = {
    	   'imgs' : jQuery.makeArray(imgs),
    	   'max_width' : o.max_width,
    	   'max_height' : o.max_height
    	};

        $(document.body).data('refs_' + instance, refs).bind('load', function(e){
            current_instance = $(document.body).data('current_resize_instance');
            var refs = $(this).data('refs_' + current_instance);
            index = jQuery.inArray(e.target, refs.imgs);
            if ( index != -1 && ! $(this).data('img_' + current_instance + '_' + index) ){
                img_el = e.target;
                var img = $(img_el);
                img.attr('style', 'display:inline');
                img_width = img_el.width;
                img_height = img_el.height;
                img.removeAttr('style');
        		if ( ( img_width > refs.max_width && refs.max_width != 0 ) || ( img_height > refs.max_height && refs.max_height != 0 ) ) {
        		    $(this).data('img_' + current_instance + '_' + index,true);
        			img_el.style.width = '100%';
        			img_el.removeAttribute('width');
        		}
        		else img.removeClass('resize_img');
        		delete(img_width);
        		delete(img_height);
        		delete(img_el);
            }
            delete(index);
        });

        $(window).bind('load', function(e){
            current_instance = $(document.body).data('current_resize_instance');
            tmp = $(document.body).data('refs_' + current_instance).imgs;
            ref_url = window.location.href;
            for ( i = 0, j = tmp.length; i < j; ++i )
            {
                if ( ! $(document.body).data('img_' + current_instance + '_' + i) ){
                    window.setTimeout("$($(document.body).data('refs_" + current_instance + "').imgs[" + i + "]).trigger('load');", i * 1);
                }
            }
            window.setTimeout("$(document.body).data('image_resize',false).trigger('resized');" + ( ref_url.indexOf('#') > 0 ? 'window.location.href="' + ref_url + '";' : '' ), 500);
            delete(tmp);
        });
        if ( o.delayed ){
            tmp = $(document.body).data('refs_' + instance).imgs;
            ref_url = window.location.href;
            for ( i = 0, j = tmp.length; i < j; ++i )
            {
                if ( ! $(document.body).data('img_' + instance + '_' + i) ){
                    window.setTimeout("$($(document.body).data('refs_" + instance + "').imgs[" + i + "]).trigger('load');", i * 1);
                }
            }
            window.setTimeout("$(document.body).data('image_resize',false).trigger('resized');" + ( is_ie ? "$('table').css('zoom',1);" : '' ) + ( ref_url.indexOf('#') > 0 ? 'window.location.href="' + ref_url + '";' : '' ), is_ie ? 500 : 100);
            delete(tmp);
        }
        delete(refs);
    }
}