(function($) {	
    $.fn.fontSize = function(options) {
		var opts = $.extend($.fn.fontSize.settings, options);

		opts.baseEl=$(this).get(0).tagName;

		opts.originalFontSize = $(opts.baseEl).css('font-size');
		opts.originalFontSize = parseFloat(opts.originalFontSize);

		if($.browser.msie && opts.originalFontSize>100)
			opts.originalFontSize=(parseFloat(opts.originalFontSize)/1000)*16;

		if($('.'+opts.increaseClass).get(0)!=undefined){
			$('.'+opts.increaseClass).click(function(){
				$.fn.fontSize.increaseFont(opts);
			});
		}
		
		if($('.'+opts.decreaseClass).get(0)!=undefined){
			$('.'+opts.decreaseClass).click(function(){
				$.fn.fontSize.decreaseFont(opts);
			});
		}
		
		if($('.'+opts.resetClass).get(0)!=undefined){
			$('.'+opts.resetClass).click(function(){
				$.fn.fontSize.resetFont(opts);
			});
		}
/*		

		var originalFontSize = $(opts.baeEl).css('font-size');
		
		$('.'+opts.resetClass).click(function(){
			$.fn.fontSize.resetFont(opts);
		});
		
		// Increase Font Size
		$('.piuGrande').click(function(){
			var currentFontSize = $('body').css('font-size');
			var currentFontSizeNum = parseFloat(currentFontSize, 10);
			var newFontSize = currentFontSizeNum*1.2;
			$('body').css('font-size', newFontSize);
			return false;
		});
		// Decrease Font Size
		$('.piuPiccolo').click(function(){
			var currentFontSize = $('body').css('font-size');
			var currentFontSizeNum = parseFloat(currentFontSize, 10);
			var newFontSize = currentFontSizeNum*0.8;
			$('body').css('font-size', newFontSize);
			return false;
		});
*/		
	};

	$.fn.fontSize.resetFont=function(opts) {
		$(opts.baseEl).css('font-size', opts.originalFontSize);
	};
	
	$.fn.fontSize.increaseFont=function(opts) {
		return changeSize(opts,'inc');
	};
	
	$.fn.fontSize.decreaseFont=function(opts) {
		return changeSize(opts,'dec');
	};
	
	function changeSize(opts,type){
		newFontSize=calcNewSize(opts,type);

		$(opts.baseEl).css('font-size', newFontSize);
		
		return false;
	}
	
	function calcNewSize(opts,type){
		currentFontSize = $(opts.baseEl).css('font-size');
		currentFontSizeNum = parseFloat(currentFontSize, 10);

		if($.browser.msie && currentFontSizeNum>100)
			currentFontSizeNum=(currentFontSizeNum/1000)*16;
			

		switch(type){
			case 'inc':
				corr=(100+opts.perc)/100;
			break;
			
			case 'dec':
				corr=(100-opts.perc)/100;
			break;
		}
		
		newFontSize = currentFontSizeNum*corr;

return newFontSize;
	}
	
	$.fn.fontSize.settings = {
		baseEl: 'html',
		originalFontSize: 10,
		increaseClass: 'piuGrande',
		decreaseClass: 'piuPiccolo',
		resetClass: 'resetFont',
		perc: 20
	};

})(jQuery);	
