$(function(){
	// Open external links in new window
	$("a[href^='http']").each(
		function () {
			if (($(this).attr('href').indexOf('fixation') > 15) || ($(this).attr('href').indexOf('fixation') < 0)) {
				$(this).attr({"target": "_blank"});
			}
		}
	);
	// Form tooltip arrows
	var tooltips = $("div.tooltip");
	tooltips.each(
		function () {
			$(this).prepend($('<div class="arrow" />'));
		}
	);
	// IE fixes
	if ($.browser.msie) {
		// Float the last form elements in each row to the right
		$("#interior .primaryContent fieldset .widget").each(
			function () {
				$(".form_element:last", this).each(
					function() {
						$(this).css({float: "right", marginRight: 0});
					}
				);
			}
		);
		// Set the height of the interior sidebar to match the height of .primaryContent
		// In the css, absolutely positioning the sidebar and setting the top and bottom offsets works,
		// but of course IE6 has other ideas, so we need to use jQuery to grab the height of
		// .primaryContent and subtract 15px to account for the top padding on .interiorSidebar
		var primaryContent = $("#interior .primaryContent");
		var primaryContentHeight = primaryContent.innerHeight();
		$("div.contactSidebar", primaryContent).css({height: primaryContentHeight - 15, position: 'static'});
		if ($.browser.version == '6.0') {
			$("div.interiorSidebar", primaryContent).css({height: primaryContentHeight - 15});
			$("div#blogSidebar", primaryContent).css({height: primaryContentHeight});
			// Make subnavigation work in IE6, as it doesn't support :hover on non-anchor elements
			var navigation = $("#primaryNavigation ul.main");
			$("li:has(ul)", navigation).hover(function () {$(this).addClass("ie6_hover");}, function () {$(this).removeClass("ie6_hover");});
			// IE6 doesn't support CSS attribute selectors, but jQuery does, so we'll use that to add classes to the necessary elements
			$("#interior .primaryContent fieldset input[type='hidden']").addClass("hidden");
			$("#interior .primaryContent fieldset input[type='submit']")
				.addClass("submitButton")
				.bind("mouseenter focus active", function () {$(this).addClass("ie6_hover");})
				.bind("mouseleave",function () {$(this).removeClass("ie6_hover");});
		}
	}
	if ($.browser.safari) {$('body').addClass('safari');}
	$("#interior .primaryContent fieldset input").bind(
		"focus",
		function () {
			var parent = $($(this).parent("div.form_element").get());
			var showTooltip = false;
			var tooltipType = 'errors'
			if ((parent.hasClass("error")) || (parent.attr('id') == 'ZipField')) {
				showTooltip = true;
				if (parent.hasClass("error")) {
					tooltipType = 'errors';
				}
				else if (parent.attr('id') == 'ZipField') {
					tooltipType = 'hint';
				}
			}
			if (showTooltip) {
				var tooltip = $("div." + tooltipType, parent).show();
				$("div.arrow", tooltip).show();
				if ($.browser.msie) {$(parent.next("div.form_element")).css({zIndex: "-1"});}
			}
		}
	);
	$("#interior .primaryContent fieldset input").bind(
		"blur",
		function () {
			var parent = $($(this).parent("div.form_element").get());
			$("div.tooltip", parent).hide();
		}
	);
	$("#interior .primaryContent fieldset input").bind(
		"keyup",
		function () {
			var parent = $($(this).parent("div.form_element").get());
			if (parent.hasClass("valid")) {$("div.tooltip", parent).hide();}
		}
	);
	// Clear the newsletter signup box and stuff
	$('#newsletterSignup input[type="text"]')
	.bind('focus', function () {
		if (typeof $(this).data('original') == 'undefined') {
			$(this).data('original', $(this).val());
		}
		$(this).val('');
	})
	.bind('blur', function () {
		if ($(this).val() == '' && typeof $(this).data('original') != 'undefined') {
			$(this).val($(this).data('original'));
		}
		else {
			$(this).data('original', $(this).val());
		}
	});
});