// control highlight and font size in text selector
$(document).ready(
function() 
{
	$("a.textsize").click(function() 
	{
		$("a.textsize").removeClass("highlighted");
		
		// change font size
		if($(this).is(".small")) 
		{
			$('html').css('font-size', 16);
			$.cookie('textsize', 'small', { path: '/' });
			$('#small').addClass("highlighted");
		} 
		else if ($(this).is(".medium"))
		{
			$('html').css('font-size', 18);
			$.cookie('textsize', 'medium', { path: '/' });	
			$('#medium').addClass("highlighted");	
		}
		else if ($(this).is(".large"))
		{
			$('html').css('font-size', 20);
			$.cookie('textsize', 'large', { path: '/' });
			$('#large').addClass("highlighted");
		}
	});
		
	// recall which text size to use if already chosen (uses jquery cookie plugin)
	var textSize = $.cookie('textsize');
	//alert(textSize);
	
	if ((textSize != null) && (textSize != ''))
	{
		if (textSize == 'small')
		{
			$('html').css('font-size', 16);
			$('#topNav li a').css('font-size', 16);
			$('#small').addClass("highlighted");
		}
		else if (textSize == 'medium')
		{
			$('html').css('font-size', 18);
			$('#topNav li a').css('font-size', 15);
			$('#medium').addClass("highlighted");
		}
		else if (textSize == 'large')
		{
			$('html').css('font-size', 20);
			$('#topNav li a').css('font-size', 14);
			$('#large').addClass("highlighted");
		}
	}
	else
	{
		$('#small').addClass("highlighted");
	}
	
	
	// tag cloud
	var catContainer = $('ul#tagcloud');  
	// get an array of all the <li>'s  
	var categories = catContainer.find('li');  
	var cloudMarkup = '';  
	// set maxPercent/minPercent preferences  
	var maxPercent = 180, minPercent = 70;  
	// note that max is initialized to a number that I know is lower than the max count  
	// and that min is set to a number larger than the known min count  
	var max = 1, min = 999, count = 0;  
	// loop through each li and calculate statistics  
	categories.each(function(i) {  
	 count = parseInt($(this).find('span').text());  
	 max = (count > max ? count : max);  
	 min = (min > count ? count : min);  
	});  
	var total, link, size;  
	var multiplier = (maxPercent-minPercent)/(max-min);  
	// loop through each li and generate the markup for the new tag cloud  
	categories.each(function(i) {  
	 count = parseInt($(this).find('span').text());  
	 link = $(this).find('a');  
	 size = minPercent + ((max-(max-(count-min)))*multiplier) + '%';  
	 cloudMarkup += '<a class="cloud_link" style="font-size:' + size + '" href="' + link.attr('href') + '">' + link.text() + '</a> ';  
	});  
	// replace the html content of the parent container with the new tag cloud  
	catContainer.html(cloudMarkup);
});



