var TextCompact = {
	compact : function(dest, max) {
		var destText = $(dest).text();
		var destTextArray = new Array();
		destTextArray = destText.split(" ");
		$(dest).empty();
		var currW = 0;
		for(var i=0; i<destTextArray.length; i++) {
			$(dest).append("<span class='dtA' id='dtA" + i + "' style='font-size:" + max + "'>" + destTextArray[i] + " </span>");
			currW += $("#dtA"+i).width();
			if (currW >= $(dest).parent().width()) {
				currW = $("#dtA"+i).width();
				if (i > 0) {
					$("#dtA"+(i-1)).append("<br/>");
				}
			}
		}
		
		for(var i=0; i<destTextArray.length; i++) {
			$("#dtA"+i).before($("#dtA"+i).html())	
			$("#dtA"+i).remove();
		}
		
		this.scale(dest, max);
	},
	
	scale : function(dest, max) {
		var thisWidth = ($(dest).width());
		var parentWidth = ($(dest).parent().width());	
		var compactFactor = thisWidth/parentWidth;
		var oldFontSize = ($(dest).css("font-size"));
		oldFontSize.replace("px", "");
		var newFontSize = (parseInt(oldFontSize)/compactFactor);
		(newFontSize > max) ? newFontSize = max : null;
		$(dest).css("font-size", newFontSize + "px");
		$(dest).parent().height(($(dest).parent().height() + ($(dest).height()-$(dest).parent().height())))
	}
}