
TextSizeController = function() {};
var t = TextSizeController;
var myTSC;

t.prototype.sizeList = ['small', 'medium', 'large'];
t.prototype.fontSizes = ['1em', '1.3em', '1.6em'];
t.prototype.h3Sizes = ['16px', '22px', '28px'];

t.prototype.init = function() {
	// Get the current size.
	var size = ($.cookie('textSize')!=null) ? $.cookie('textSize') : "small";
	
	// Set the size.
	this.setSize(size);
	
	// Set up callbacks.
	$("#textSizeControl a").bind("click", function(evt) {
		var id = $(evt.target).attr("rel");
		myTSC.setSize(id);
		evt.preventDefault();
	});
};

t.prototype.setSize = function(size) {
	var index;
	for (var i = 0; i < this.sizeList.length; i++) {
		if (this.sizeList[i] == size) {
			var index = i;
			this.activate(size);
		} else {
			this.deactivate(this.sizeList[i]);
		}
	}
	
	$(".zoomable").css("font-size",this.fontSizes[index]);
	$(".zoomable h3").css("font-size",this.h3Sizes[index]);
	$.cookie('textSize',size);
};

t.prototype.activate = function(size) {
	$("#textSizeControl a[rel='"+size+"']").each(function() {
			var p = $(this).parent();
			if (p.hasClass("inactive")) p.removeClass("inactive");
			if (!p.hasClass("active")) p.addClass("active");	
	});
};

t.prototype.deactivate = function(size) {
	$("#textSizeControl a[rel='"+size+"']").each(function() {	
			var p = $(this).parent();
			if (p.hasClass("active")) p.removeClass("active");	
			if (!p.hasClass("inactive")) p.addClass("inactive");
	});
	
};




// When DOM is ready.

$(document).ready(function(){
	// Center the main nav.
	var outerW = $("#mainNav").width();
	var innerW = $("#mainNav ul").width();
	var pad = Math.floor((outerW - innerW)/2);
	$("#mainNav ul").css({'float':'none',
						  'padding-left':pad + 'px'});
	
	// Set our font size zoom.
	myTSC = new TextSizeController();
	myTSC.init();
	
	// Draw the current year.
	$(".currentYear").text((new Date).getFullYear() + " ");				   
});