/*!
 * jQuery Font Resizer
 * http://www.blitzgamesstudios.com
 *
 * Copyright 2011, James Kirby jkirby@blitzgamesstudios.com
 * Licensed under the GPL Version 3 license.
 * Version 0.2
 *
 */

(function( $ )
{
	/* Default Settings, (Leave as integers, do not include the 'px') */
	var settings = {
		'default_size'	: 11,	/* Default font size */
		'max_size'		: 13,	/* Maximum size the font can be increased to */
		'min_size'		: 9		/* Minimum size the font can be decreaseed to */
	};
	
	/* Plugin Methods */
	var methods = {
		builder : function(options)
		{
			/* Build the elements and apply the bindings */
			$('<a/>', {
				id:		'fontdecrease',
				class:	'block decrease',
				href:	'#',
				title:	'Smaller Text Size',
				text:	'-'
			}).click(function() { $(this).fontResizer('decreasesize'); }).appendTo(this);
			
			$('<a/>', {
				id:		'fontdefault',
				class:	'block default',
				href:	'#',
				title:	'Default Font Size',
				text:	'A'
			}).click(function() { $(this).fontResizer('defaultsize'); }).appendTo(this);

			$('<a/>', {
				id:		'fontincrease',
				class:	'block increase',
				href:	'#',
				title:	'Bigger Text Size',
				text:	'+'
			}).click(function() { $(this).fontResizer('increasesize'); }).appendTo(this);
		},
		decreasesize : function(options)
		{
			/* Function specific variables */
			var currentFontSize = $('html').css('font-size');
			var currentFontSizeNum = parseFloat(currentFontSize, 10);
			var newFontSize = (currentFontSizeNum - 1) + 'px';

			/* Determine if the current font size is above the minimum size */
			if ( currentFontSizeNum > settings['min_size'] )
			{
				$('html').css('font-size', newFontSize);
			};
		},
		defaultsize : function(options)
		{
			/* Reset the default font size to whats defined in the settings */
			$('html').css('font-size', settings['default_size']);
		},
		increasesize : function(options)
		{
			/* Function specific variables */
			var currentFontSize = $('html').css('font-size');
			var currentFontSizeNum = parseFloat(currentFontSize, 10);
			var newFontSize = (currentFontSizeNum + 1) + 'px';

			/* Determine if the current font size is above the minimum size */
			if ( currentFontSizeNum < settings['max_size'] )
			{
				$('html').css('font-size', newFontSize);
			};
		}
	}
	
	$.fn.fontResizer = function( method, options ) {
	
		/* Call the function combining the option above */
		return methods[method].apply(this);

	}
})( jQuery );
