/* Author: Jason Gennaro
	Oct. 19, 2010
		
	collects current font size then changes it when the user clicks
	on the "bigger" or "smaller" links
	
	contains function within an object
	to ensure that it does not conflict with
	other javascript
	
	modified on Dec. 29, 2010
	added cookies so that font size changes persist over all pages of site.	
	
*/

var FontSizeChanger = 
	{	
		init: function() 
			{
			
				//checks to see if cookie exists.  If it exists, gets font size and applies it to page
				if($.cookie('fontSizerMag') != null){ 
				   var textToChangeNumber = $.cookie('fontSizerMag');
					var textToChange = $('div.onlyContent');
					$(textToChange).css("fontSize", textToChangeNumber + "px");
					$('div.onlyContent > *').css("lineHeight", textToChangeNumber + "px");
				}
			
				
				//locates links, fires script on click
				$('p#fontSize > a').click(function() 
					{
						//sets the text to change size (only that in the main content area)
						textToChange = $('div.onlyContent');
						
						//finds the current font size, in this case returns 14px
						$(textToChange).css("fontSize"); 
						
						//sets a variable with just the px # using parseInt						
						textToChangeNumber = parseInt($('div.onlyContent').css('fontSize'));
							
							//if user clicks on bigger link, 2 is added to the px size
							if (this.id == 'biggerText')
								{
									textToChangeNumber +=2;
								}
								
							//if user clicks on smaller link, 2 is removed from the px size								
							else if (this.id == 'smallerText')
								{
									textToChangeNumber -=2;
								}	
					
						//sets the final text size to the clicked #
						$(textToChange).css("fontSize", textToChangeNumber + "px");
						//sets line-height to equal font size
						$('div.onlyContent > *').css("lineHeight", "1em");
						
						//sets cookie with # for font size. expires in 7 days. path set for entire site.
						$.cookie('fontSizerMag', textToChangeNumber, {expires: 7, path: '/'} );
												
						//ensures pages doesn't refresh from dummy link
						return false;
					}
				);
			}
	};			

$(document).ready(function(){FontSizeChanger.init();});
