﻿; (function($) {
	/**
	* Resizes an inner element's font so that the inner element completely fills the outer element.
	* @author Russ Painter WebDesign@GeekyMonkey.com
	* @version 0.1
	* @param {Object} Options which are maxFontPixels (default=40), innerTag (default='span')
	* @return All outer elements processed
	* @example <div class='mybigdiv filltext'><span>My Text To Resize</span></div>
	*/
	$.fn.textfill = function(options) {
		var defaults = {
			maxFontPixels: 40,
			innerTag: 'span'
		};
		var Opts = jQuery.extend(defaults, options);
		return this.each(function() {
			var fontSize = Opts.maxFontPixels;
			var ourText = $(Opts.innerTag + ':visible:first', this);
			var maxHeight = $(this).height();
			var maxWidth = $(this).width();
			var textHeight;
			var textWidth;
			do {
				ourText.css('font-size', fontSize);
				ourText.css('text-align','center');
				textHeight = ourText.height();
				textWidth = ourText.width();
				fontSize = fontSize - 1;
			} while ((textHeight > maxHeight || textWidth > maxWidth) && fontSize > 8);
		});
	};
})(jQuery);

//Jims Custom Code
	$(document).ready(function() {
			$('.jtextfill').textfill({ maxFontPixels: 22 });
			$('.jtextfill2').textfill({ maxFontPixels: 22 });
			shout('.dyntextval');
			shout('.dyntextval2');

			$('#dyntext').keyup(function() {
					$('.dyntextval').html(this.value);
					$('.jtextfill').textfill({ maxFontPixels: 22 });
					shout('.dyntextval');
			});
			
			$('#dyntext2').keyup(function() {
					$('.dyntextval2').html(this.value);
					$('.jtextfill2').textfill({ maxFontPixels: 22});
					shout('.dyntextval2');
			});
			
			$("#font").change(function (){
					$('.dyntextval').css('font-family',$(this).val());
					$('.dyntextval2').css('font-family',$(this).val());
					
					$('.jtextfill').textfill({ maxFontPixels: 22 });
					shout('.dyntextval');
					$('.jtextfill2').textfill({ maxFontPixels: 22 });
					shout('.dyntextval2');
			});
		});


	function shout(object){
		var parwidth = parseFloat($('.jtextfill').css('width'))
		var marginleft = parwidth - $(object).width();
		marginleft = marginleft / 2;
		$(object).css('margin-left',marginleft);
		//var fontmix = parseInt($(object).css('font-size')) *2;
		//$(object).parent().height(fontmix);
		//alert($(object).css('font-size'));
	}
