(function($){
	$.fn.ellipsis = function(o){
		o = $.extend({}, $.fn.ellipsis.defaults, o);
		
		return this.each(function(){
			var a = $(this), text = a.text(), count = text.length;
			var h;
			
			//a.css({display: "block","word-wrap": "break-word"});
			
			// get the height of content
			// ie
			// line-height don't use % & px
			if (a.get(0).currentStyle) {
				h = parseInt(a.css("font-size")) * a.get(0).currentStyle.lineHeight * o.line;
			}
			// firefox or other browsers
			else {
				h = parseInt(a.css("line-height")) * o.line;
			}
			
			if (o.title) {
				a.attr("title", text);
			}
			if (a.height() <= h) {
				a.text(text);
			}
			else {
				run();
			}
			
			function run(){
				count--;
				var str = text.substring(0, count);
				a.text(str + o.instead);
				if (a.height() > h) {
					run();
				}
			}
		});
	};
	
	$.fn.ellipsis.defaults = {
		instead: "...",
		title: true,
		line: 1
	};
})(jQuery);

