/*****************************************************************************\
 * Atomic North
 * Font Resizing
 *
 * Functions contained here are used to resize the fonts on each page using 
 * the 'Large', 'Regular' and 'Small' links to adjust the size of the font in 
 * each element.
\*****************************************************************************/

/**
 * Keeps track of how many px the current font size is from the original in 
 * order to reset to the regular font size later.
 */
var an_font_offset = 0;

/**
 * This is the number of px to adjust the font size by with each increment or
 * decrement.
 */
var an_font_adjust = 1;

/**
 * This contains the elements which should be affected by the font resizing
 */
var an_font_elements = ".textbg, .text, .text a, .hometext, .hometext2, .hometext3, .hometext4, .texthome1, .texthome2, .texthome3, .texthome4, .texthome2 a, .texttitle, .MsoNormal span";

/**
 * This will be the type of font sizes used on the page, can switch between % 
 * and px.
 */
var an_font_size_type = "px";

/**
 * Adjusts the font size
 *
 * @string operator Can be "+", "-" or "*" for larger, smalller, regular
 */
function adjust_font_size(operator) {
	switch(operator) {
		case "+":
			an_font_offset++;
			break;
		case "-":
			an_font_offset--;
			break;
		default:
	}
	
	$(an_font_elements).each(function() {
		font_size_new = $(this).css("font-size").replace(an_font_size_type, "");
		font_size_current = parseInt($(this).css("font-size").replace(an_font_size_type, ""));
		switch(operator) {
			case "+":
				font_size_new = font_size_current += an_font_adjust;
				break;
			case "-":
				font_size_new = font_size_current -= an_font_adjust;
				break;
			case "*":
				if (an_font_offset != 0) {
					font_size_new = font_size_current - an_font_offset;
				}
				break;
		}
		$(this).css("font-size", font_size_new + an_font_size_type);
	});
	if (operator == "*") {
		an_font_offset = 0;
	}
}

$(document).ready(function() {
	$("#increase_font").click(function(e) {
		e.preventDefault();
		adjust_font_size("+");
	});

	$("#decrease_font").click(function(e) {
		e.preventDefault();
		adjust_font_size("-");
	});

	$("#reset_font").click(function(e) {
		e.preventDefault();
		adjust_font_size("*");
	});
});

