$(document).ready(function() {

	// if there's a sidebar, we need to narrow the post
	// nevermind, we're going to require the sidebar on all pages to save a headache
	// if($("#sidebar").length>0) { $("#chester .post").width(560); }
	
	// main menu action
	$("#main > li").hover(function() {
	 $(this).addClass("active");
	 $(this).find(".children").css("display","block");
	}, function() {
	 $(this).removeClass("active");
	 $(this).find(".children").css("display","none");
	});

	$("#main > li > .children > li").hover(function() {
	 $(this).addClass("active");
	}, function() {
	 $(this).removeClass("active");
	});
	
	$(".nav a").attr("title","");

	
	// oh hey, internet explorer version 6 doesn't care for our fancy transparent pngs
	// so we'll just replace them all with ugly bitter transparent gifs and be done with it
	if($.browser.msie) {

		var uwidth = 0;
		$("#utility li").each(function () {
		  uwidth += $(this).width();
		});
		$("#utility").width(uwidth);

		if($.browser.version=="6.0") {
		
		  $("#main a").css("height","auto").css("width","auto");
		
		  $(".logo img").attr("src",$(".logo img").attr("src").replace("png","gif"));
		  $(".yourlife").attr("src",$(".yourlife").attr("src").replace("png","gif"));
		  $("#footer .copyright img").attr("src",$("#footer .copyright img").attr("src").replace("png","gif"));
		  $("#utility").css("background-image",$("#utility").css("background-image").replace("png","gif"));
		  $(".logo .tagline").css("background-image",$(".logo .tagline").css("background-image").replace("png","gif"));
		} else {
		  $("#main li .children").css("overflow","hidden");
		}
	} else {
	  $("#main li .children").css("overflow","hidden");
	}

	// sidebar snazziness
	$("#sidebar h1.special").each(function() {
	  $(this).html("<span><span class='text'>"+$(this).html()+"</span><span class='left'></span><span class='right'></span></span>");
	});
	$("#sidebar h1.special2").each(function() {
	  $(this).html("<span><span class='text'>"+$(this).html()+"</span><span class='left'></span><span class='right'></span></span>");
	});
	
	$("#sidebar p.quote img").wrap("<span class='bordered' />");
	
	
	
	// FAQ functionality
	$(".answer").addClass("ghost");
	
	$(".answer").each(function() {
	 if ($(this).find("p").length<=0) $(this).wrapInner("<p></p>"); 
	});
	
	$(".question").click(function() {
	  if($(this).next().hasClass("ghost")) {
		$(".answer").addClass("ghost");
		$(this).next().removeClass("ghost");
		 freshChest();
	  } else {
	    $(this).next().addClass("ghost");
		 freshChest();
	  }
	});
	
});

function freshChest() {
  if($("#chester .post").height()<400) $("#chester .post").height(400);
  $("#chester").height($("#chester .post").height()+60);
  if($("#sidebar").height()>$("#chester").height()) {
    $("#chester").height($("#sidebar").height());
  } else {
    $("#sidebar").height($("#chester").height());
  }
}

function checkRequired() {
	var theForm = document.getElementById('form1');
	if(theForm.name.value!=""&&theForm.email.value!="") return true;
	else { alert('Please fill out all required forms.'); return false; }
}

$(window).load(function(){
 freshChest();
 var hash = location.hash.substring(1);
 if(hash) $.scrollTo($("a[name="+hash+"]"));
});
