Javascript: How to resize the image to content width

[javascript]
<script>
$(‘#article_page_{$article_id}’).live( ‘pagecreate’,function(event)
{
var my_w=$(‘#article_page_{$article_id}’).width() – 40;

$(‘.article_text img’).each(
function(){
$(this).css(‘width’, ($(this).width() > my_w?$(this).width():my_w) +’px’);
});
});

</script>";
[/javascript]