window.Processing.data = {
	mouseX: 0,
	mouseY: 0
};

$(document).ready(function(){

	$("html").removeClass("noJS");

	// $.gridbase();
	
	$("body").mousemove(function(e){
		window.Processing.data.mouseX =  e.pageX;
		window.Processing.data.mouseY =  e.pageY;
	});
	
	function over(){
		$("#nav").addClass("open");
		$(".slider").stop(true,true).animate({ opacity: 1, height: "show" },800,"swing");
		$("#s").focus();
	}
	function out(){
		$("#nav").removeClass("open");
		$(".slider").stop(true,true).animate({ opacity: 0, height: "hide" },800,"swing");
	}
	
	$("#nav ul,#nav form").wrapAll('<div class="slider"></div>');
	/*$("#nav").hoverIntent({
		sensitivity: 3,
		interval: 300,
		timeout: 600,
		over: over,
		out: out
	});*/
	$("#nav h2").click(function(){
		if ( $("#nav").hasClass("open") ) {
			out();
		} else {
			over();
		}
	});
	
	if ( $("body").hasClass("blog") ) $("#nav h2").click();
	
	// keep images within vertical rhythm
	var baseline = parseInt($("body").css("line-height"));
	$("img").each(function(){
		$(this).wrap('<div class="image-wrap" style="overflow:hidden;width:'+ $(this).width() +'px;height:'+ ($(this).height() - ($(this).height() % baseline)) +'px;"></div>');
	});
	
	// nine circles numberify dates
	$("time").each(function(){
		var nums = $(this).attr("datetime").split("-");
		$(this).ncn({
			colours: ["#e7e7e7","#c8c8c8","#a6a6a6","#FF2C16"],
			numbers: [nums[1],nums[2],nums[0]],
			size: 3*8,
			gap: 8
		});
	});
	
	// poor man's contact form validation
	if ( $("#contactform").length ) {
		$("#contactform").submit(function(){
			var ok = false;
			var author = $("#author");
			var email = $("#email");
			var comment = $("#comment");
			
			if ( author.val() != "" && email.val() != "" && comment.val() != "" ) ok = true;
			
			if (ok) {
				return true;
			} else {
				if ( !$(".error",this).length ) {
					$('<p class="error msg" style="display:none;">Please fill in all the fields. You know it makes sense.</p>').prependTo("#contactform fieldset").show("slow","swing");
				} else {
					$(".error",this).animate({
						fontSize: "+=4px"
					},"fast","swing");
				}
				return false;
			}
		});
	}
	
	$(window).resize(function(){
		$("iframe").width($(this).width());
	}).resize();
	
});