//  set up Text Resizer function....

$(document).ready(function(){
	// section is the selector for the elements you want to have the same height
	var section = "";
	// extsection is the section list, plus any containers that need resizing too
	var extsection = "";
	// since units are not specified, it defaults to pixels on all this stuff.
	var maxfont = 22;
	// original version used this: var originalFontSize = $(section).css('font-size');
	var basefont = 16;
	var minfont =14;
	var fontsteps = 2;
	var lineheight = 1.5;  // must reset this, else it is 1.5 of the original value
	//
	if ($('body').hasClass('home')) {
		section="#inner-content";
		extsection = "#inner-content,#sidebar";
	}
	else {
		section       = "#inner-content,#sidebar";
		extsection = "#inner-content,#sidebar";
	}

  	// Reset Font Size
  	$(".resetFont").click(function(){
		$(section).css('height','auto');
    	$(section).css('font-size', basefont); 
    	$(section).css('line-height', lineheight);
		resetpageheight();
  	});

  	// Increase Font Size
  	$(".increaseFont").click(function(){
		$(extsection).css('height','auto');
    	var currentFontSize = $(section).css('font-size');
    	var currentFontSizeNum = parseFloat(currentFontSize, 10);
		var newFontSize = currentFontSizeNum < (maxfont - fontsteps) ? currentFontSizeNum + fontsteps :  maxfont;
    	$(section).css('font-size', newFontSize);
    	$(section).css('line-height', lineheight);
		resetpageheight();
    	return false;
  	});

  	// Decrease Font Size
  	$(".decreaseFont").click(function(){
		$(extsection).css('height','auto');
    	var currentFontSize = $(section).css('font-size');
    	var currentFontSizeNum = parseFloat(currentFontSize, 10);
 		var newFontSize = currentFontSizeNum > (minfont + fontsteps) ? currentFontSizeNum - fontsteps :  minfont;
   		$(section).css('font-size', newFontSize);
    	$(section).css('line-height', lineheight);
		resetpageheight();
   		return false;
  	});
  
  	// reset heights
  	function resetpageheight () {
	  // This sets the elements to the tallest height of them. It optionally can take a list of
	  // other containers that need to be jogged to reset their height (position:absolute?)....
		var tmax = 0;
		$(section).each(function() { tmax = Math.max(tmax, $(this).height()); }).height(tmax);
		$(extsection).height(tmax);
	  }
});