jQuery(document).ready(function($) {





	// Platform checks.... sigh.
	// alert("Hello, you're running " + $.client.os + " today.");
	if($.client.os == "Mac") {
		$("body").addClass("os-mac");
	}
	if($.client.os == "Windows") {
		$("body").addClass("os-windows");
	}

	

	// Open links in external window
	if($('body a[rel="external"]').length != 0) {
    	$('a[rel="external"]').click( function() {
        	window.open( $(this).attr('href') );
        	return false;
    	});
	}

	// Odds and ends
	$("#utility li:first-child").addClass("first");
	$("nav ul li:first").addClass("first");
	$("footer .flats li:first").addClass("first");
	$(".termPicker li:last-child").addClass("last");


	// On Search Results that don't have pagination, hide the pagination box...
	if($("body").hasClass("search-results")) {
		if($(".intro a").length == 0) {
			$(".intro").hide();
		}
	}


	// Contact Form markup wrangling.
	if($('body').hasClass('page-id-42')) { // Yep, it's the Contact Page alright

		$('#clean_contact fieldset label').each(function(){
			$(this).wrap('<div class="formRow clearfix" />');
			$(this).parent('div').next().appendTo($(this).parent('div'));
			$(this).next().wrap('<div class="field" />');
			$(this).wrap('<div class="label" />');
		});
		
		$('#clean_contact .formRow:last').addClass('formRow-last');
		$('#clean_contact br').remove();

	}




	// Give the search field some default text
	$("#searchform #s").attr("value","SEARCH").focus(function(){
		$(this).attr("value","");
	});


	// MailChimp signup form needs love
	if($("#mailchimp").length != 0) {
		$("#mailchimp br").remove();
		$("#mc-indicates-required").remove();
		$("#mc_mv_EMAIL").attr("value","YOUR EMAIL (required)");
		$("#mc_mv_FNAME").attr("value","FIRST NAME");
		$("#mc_mv_LNAME").attr("value","LAST NAME");
		$(".mc_input").focus(function(){
			$(this).attr("value","");
		});
		$("#mc_signup_submit").mouseover(function(){
			$(".mc_signup_submit").addClass("hovered");
		}).mouseout(function(){
			$(".mc_signup_submit").removeClass("hovered");
		});
	}
	


	// Light up the search button
	$("#searchsubmit").mouseover(function(){
		$(this).parent("div").addClass("hovered");
	}).mouseout(function(){
		$(this).parent("div").removeClass("hovered");
	});



	// Nav sublist hovers
	$("nav ul li:has(ul)").mouseover(function(){
		$(this).find("ul").show();
	}).mouseout(function(){
		$(this).find("ul").hide();
	});


	// Taxonomy pickers
	$(".termPicker h2").each(function(){
		$(this).mouseover(function(){
			$(this).addClass("hovered");
		}).mouseout(function(){
			$(this).removeClass("hovered");
		});
	});

	$(".termPicker h2").each(function(){
		$(this).click(function(){
			if($(this).hasClass("active")) {
				$(".termPicker h2").removeClass("active");
				$(this).next().slideUp(150);
			} else {
				$(".termPicker h2").removeClass("active");
				$(this).addClass("active");
				$(".termPicker ul").hide();
				$(this).next().slideDown(150);
			}
		});
	});
	
/*
	
	if($(".alignleft").length != 0) {
		$(".alignleft").each(function(){
			$(this).closest("p").addClass("alignleft");
			$(this).removeClass("alignleft");
		});
	}
	if($(".aligncenter").length != 0) {
		$(".aligncenter").each(function(){
			$(this).closest("p").addClass("aligncenter");
			$(this).removeClass("aligncenter");
		});
	}
	if($(".alignright").length != 0) {
		$(".alignright").each(function(){
			$(this).closest("p").addClass("alignright");
			$(this).removeClass("alignright");
		});
	}

*/
	




});
