/* Copyright (c) 2009 Michal Valasek (http://michalvalasek.net)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) 
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 *
 * Version 1.0.0
 */

(function($) {
    
	$.fn.shortenHeight = function( options )
	{
		var defaults = {
			'tail': " ..."
		};
		var options = $.extend(defaults, options);
		
		return this.each(function()
		{
        	var obj = $(this);
			var myText = obj.html().split(" ");
			$(this).empty();
			var newText = new Array();
			while ( obj.height() < obj.parent().height() )
			{
				newText.push( myText[newText.length-1] );
				obj.html( newText.join(" ") );
			}
			newText.pop();
			obj.html( newText.join(" ") + options.tail );
		});
	}
	
	$.fn.shortenWidth = function( options )
	{
		var defaults = {
			'tail': " ..."
		};
		var options = $.extend(defaults, options);
		
		return this.each(function() {
            
			var obj = $(this);
			var myText = obj.html().split(" ");
			
			var maxWidth = null==options.maxWidth ? obj.parent().width() : options.maxWidth;
			
			while ( obj.width() > maxWidth )
			{
				myText.length = myText.length-1;
				obj.html( myText.join(" ") + options.tail );
			}
		});
	}
	
})(jQuery);

