
function autoscale(selectors)  {

	for(s = 0; s < selectors.length; s++) {
	
		selector = selectors[s];
	
		$(selector).each(function(){

			var width = $(this).width();
			var height = $(this).height();
			
			if(!width) width = $(this).attr('width');
			if(!height) height = $(this).attr('height');

			var target_width = $(this).parent().width();

			if (width < target_width || width > target_width) {
				var ratio = (height / width);
				var new_width = target_width;
				var new_height = (new_width * ratio);

				$(this).height(new_height).width(new_width);
			}
		}
		);
	
	}

}
