(function($){
	$.fn.autosize = function(options) {
	
		var defaults = {};
		var options = $.extend(defaults, options);
		return this.each(function() {
			el = $(this);
			fs = el.css('font-size');
			target_width = el.attr('rel');
			content = el.text();
			if(content.length == 0) return true;
			el.empty();
			el.append('<span style="display:inline">'+content+'</span>');
			el = el.children();
			fs = fs.substr(0,fs.length-2);
			//alert(el.width());
			if(content.length > 0 && el.width() > target_width) {
				ct = 1;
				while(1 && ct < 25) {
					if(fs < 6) break;
					++ct;
					os = el.width();
					fs = fs-1;
					el.css('font-size',fs+'px');
					if(el.width() <= target_width) break;
					//if(el.width() >= os) break;
				}
			}
			else {
				if(false && el.width() < target_width) {
				ct = 1;
					while(1 && ct < 25) {
						if(fs > 200) break;
						++ct;
						os = el.width();
						fs = (fs-1)+2;
						el.css('font-size',fs+'px');
						if(el.width() >= target_width) break;
					}
				}
			}
		});
	};
})(jQuery);
