var TypeHelpers = new function(){
	var me = this;

	me.hasSmoothing = function(){
		// IE has screen.fontSmoothingEnabled - sweet!
		if (typeof(screen.fontSmoothingEnabled) != "undefined") {
			return screen.fontSmoothingEnabled;
		} else {
			try {
			// Create a 35x35 Canvas block.
				var canvasNode = document.createElement("canvas");
				canvasNode.width = "35";
				canvasNode.height = "35"

				// We must put this node into the body, otherwise
				// Safari Windows does not report correctly.
				canvasNode.style.display = "none";
				document.body.appendChild(canvasNode);
				var ctx = canvasNode.getContext("2d");

				// draw a black letter "O", 32px Arial.
				ctx.textBaseline = "top";
				ctx.font = "32px Arial";
				ctx.fillStyle = "black";
				ctx.strokeStyle = "black";

				ctx.fillText("O", 0, 0);

				// start at (8,1) and search the canvas from left to right,
				// top to bottom to see if we can find a non-black pixel. If
				// so we return true.
				for (var j = 8; j <= 32; j++) {
					for (var i = 1; i <= 32; i++) {
						var imageData = ctx.getImageData(i, j, 1, 1).data
						var alpha = imageData[3];

						if (alpha != 255 && alpha != 0 && alpha > 180) {
							return true; // font-smoothing must be on.
							}
						}

					}

					// didn't find any non-black pixels - return false.
					return false;
				}
				catch (ex) {
					// Something went wrong (for example, Opera cannot use the
					// canvas fillText() method. Return null (unknown).
					return null;
				}
			}
		}

	$(document).ready(function() {
		var result = me.hasSmoothing();
		if (result == true) {
			$('html').addClass('hasFontSmoothing-true');
		} else if (result == false) {
			$('html').addClass('hasFontSmoothing-false');
		} else { // result == null
			$('html').addClass('hasFontSmoothing-unknown');
		}
	});
}


$(document).ready(function(){

	var highlightColor = '#9E4715',
		defaultColor,
		linkSibling,
		linkSiblingColor;

	$('#nav a:not(.landing)').hover(
		function () {
			defaultColor = $(this).css('color');
			$(this).animate({ color: highlightColor }, { queue: false }, 400);
		},
		function () {
			$(this).animate({ color: defaultColor }, { queue: false }, 400);
		}
	);

	$('#nav h2 .landing').hover(
		function () {
			$linkSibling = $(this).parent().parent().find('li a').first();

			if ($linkSibling.parent().hasClass('current')) {
				linkSiblingColor = '#0e2d40';
			} else {
				linkSiblingColor = '#0C669F';
			}

			if ($(this).parent().parent().hasClass('current')) {
				// $navCurrentColor in screen.scss
				defaultColor = '#0e2d40';
			} else {
				defaultColor = '#0C669F';
			}
			$(this).parent().parent().find('.landing').animate({ color: highlightColor }, { queue: false }, 400);
		},
		function () {
			$(this).animate({ color: defaultColor }, { queue: false }, 400);
			$linkSibling.animate({ color: linkSiblingColor }, { queue: false }, 400);
		}
	);

	$('#nav li .landing').hover(
		function () {
			if ($(this).parent().hasClass('current')) {
				linkSiblingColor = '#0e2d40';
			} else {
				linkSiblingColor = '#0C669F';
			}

			if ($(this).parent().parent().parent().hasClass('current')) {
				defaultColor = '#0e2d40';
			} else {
				defaultColor = '#0C669F';
			}
			$(this).parent().parent().parent().find('.landing').animate({ color: highlightColor }, { queue: false }, 400);
		},
		function () {
			$(this).parent().parent().parent().find('h2 .landing').animate({ color: defaultColor }, { queue: false }, 400);
			$(this).animate({ color: linkSiblingColor }, { queue: false }, 400);
		}
	);
});

