// custom class will generate a font resizing widget and add events so
// users can make the fonts larger
var resizer = 
{
	font: 'arial, sans-serif',
	
	makeActive: function(jqObject)
	{
		// change classes to show the new active font size
		$('.activeFontSize').attr('class','');
		jqObject.attr('class', 'activeFontSize');		
	},
	
	changeFontSize: function(type, size, sessionUpdate)
	{
		this.makeActive($('#'+type));
		
		// update css font size
		$('body').css('font', size+' '+resizer.font );
		
		// init ajax to save size to session
		if(sessionUpdate)
		{
			$.ajax(
			{
				type: 'post',
				dataType: 'json',
		   		url: 'webservice/ajaxFont.php',
		   		data: 'action=setSize&size='+size,
		   		success: function(jsonObject)
				{		
					// empty								
		   		}
				// end success
		 	});
		}
		// end ajax	call
	},
	
	init: function()
	{
		// generate resizing widget
		var html = 
		'Text Size <span id="defaultFont" class="activeFontSize" title="Default Text Size: Selected">A</span> '+
		'<span id="mediumFont" title="150% Default Text Size">A</span> '+
		'<span id="largeFont" title="200% Default Text Size">A</span>';
		
		$('#textSize').html(html);
		
		// add events to resizing widget
		$('#defaultFont').bind('click', function() { resizer.changeFontSize('defaultFont', '100%', true) });
		$('#mediumFont').bind('click', function() { resizer.changeFontSize('mediumFont', '150%', true) });
		$('#largeFont').bind('click', function() { resizer.changeFontSize('largeFont', '200%', true) });
		
		// init ajax to get size from session
		$.ajax(
		{
			type: 'post',
			dataType: 'json',
	   		url: 'webservice/ajaxFont.php',
	   		data: 'action=getSize',
	   		success: function(jsonObject)
			{	
				//blendDebugger.log(jsonObject.font.type+' '+jsonObject.font.size);
				resizer.changeFontSize(jsonObject.font.type, jsonObject.font.size, false);								
	   		}
			// end success
	 	});
		// end ajax	call	
	}
}

// add to document after dom is loaded
$(document).ready(function() { resizer.init(); });
