function check_descendants(elem, max_width)
{    
    var m = elem.childNodes;
    if (m)
    {
	for (var i=0; i<m.length; i++) 
	{	
	    if (m.item(i).tagName == "IMG")
	    { 
	    	//get image dimensions
	    	var img = new Image()
   		img.src = m.item(i).src
   		if (img.width > max_width) 
   		{
   		    //resize the image:
   		    ratio = img.height / img.width
   		    m.item(i).width = max_width;
   		    m.item(i).height = max_width * ratio;
   		    
   		}
	    }
	    check_descendants(m.item(i), max_width);	    
	}	
    }
}

