$(document).ready(function(){
	
	//nav active states
	$("#primary>li>a").each( function() {
		if ($(this).attr("href")==window.location.href) {
			$(this).addClass("active_tab");
		}
		if ((/\/blogposts\//.test(window.location)) || (/\/blog\//.test(window.location))) {
			$("#blog").addClass("active_tab");
		}
		if (/\/index.php/.test(window.location)) {
			$("#home").removeClass("active_tab");
		}
	});
	
	//contact slide out
	$("#contact").toggle(
		function () {
			$("#contact>strong").stop().animate({width:"20ex"},{queue:false,duration:200});
			$("#contact>span").animate({marginRight: "8px"},{queue:false,duration:200});
			$("#contact>strong").animate({marginRight: "2px"},{queue:false,duration:200});
		},
		function () {
			$("#contact>strong").stop().animate({width:"1px"},{queue:false,duration:200});
			$("#contact>span").animate({marginRight: "0"},{queue:false,duration:200});
		}
	);
	
	//photo type filters
	$("#sort>li>a").bind("click", function () {
		var arr = [".aut", ".nat", ".por", ".sti"];
		var id = ('.'+ $(this).attr("id") +'');
		$("#sort>li>a").removeClass("active");
		jQuery.each(arr, function() {
			$(''+ this +'').find("a").removeAttr("rel", "portfolio");
		});
		$(this).addClass("active");
		if ($(this).attr("id") == "all") {
			jQuery.each(arr, function() {
				$(''+ this +'').fadeIn(500);
			});
			jQuery.each(arr, function() {
				$(''+ this +'').find("a").attr("rel", "portfolio");
			});
		} else {
			arr = jQuery.grep(arr, function(e) {
				return (e != id);
			});
			$(id).fadeIn(500);
			$(id).find("a").attr("rel", "portfolio");
			jQuery.each(arr, function() {
				$(''+ this +'').fadeOut(500);
			});
		}
		return false;
	});
		
	//info panel slideups
	$("ul.info_slide>li").hover(
		function(){
			$(this).find("div.hover").slideDown(100);
		},
		function(){
			$(this).find("div.hover").slideUp(200);
		}
	);
	
	//comment form validation
	$('#comment_form').submit( function(e){
		var name = $("#name").val().length;
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		var email = document.getElementById('email');
		var textarea = $("#comment_area").val().length;
		if (name < 1) {
			$('.name_missing').fadeIn(400);
		} else {$('.name_missing').hide();}	
		if (!filter.test(email.value)) {
			$('.email_missing').fadeIn(400);
		} else {$('.email_missing').hide();}
		if (textarea < 2) {
			$('.text_missing').fadeIn(400);
		} else {$('.text_missing').hide();}	
		if ((name < 1) || (!filter.test(email.value)) || (textarea < 2)){
			return false;
		}
	});
});