(function($) {
	$.fn.ellipsis = function(enableUpdating){
		
		var s = document.documentElement.style;
		//if (!('textOverflow' in s || 'OTextOverflow' in s)) {
			return this.each(function(){	
								  
				var el = $(this);
				var textElement = $('A',$(this));
				
				if(el.css("overflow-y") == "hidden"){
					var originalText = textElement.html();
					var w = el.width();
					var t = $(this.cloneNode(true)).css('position', 'absolute').hide()
					.css('height', 'auto').css('overflow-y', 'visible');
					var cloneA = $('A',t);
					el.after(t);
					var text = originalText;
					while(text.length > 0 && t.height()-3 > el.height()){
						text = text.substr(0, text.length - 3);
						cloneA.html(text + "...");
					}	
					el.html(t.html());
					t.remove();
					if(enableUpdating == true){
						var oldW = el.width();
						setInterval(function(){
							if(el.width() != oldW){
								oldW = el.width();
								el.html(originalText);
								el.ellipsis();
							}
						}, 200);
					}
				}
			});
		//} else return this;
	};
})(jQuery);
