$(document).ready(function(){
	$("#search").focus(function(){
		if ($(this).val()=="Search") {
			$(this).val("");
		}
	});
	$("#search").blur(function(){
		if ($(this).val()=="") {
			$(this).val("Search");
		}
	});
	$(".comment:last").addClass("last");
	$('.news_post:last').addClass('last');
	$(".browse .links").hide();
	$(".browse .links:first").show();
	$(".page-id-85 .post .post_column_1").each(function(){
		$("p:last",$(this)).addClass("last");
		$("p:first",$(this)).addClass("last");
	});
	$(".jobDescription").hide();
	$(".careers td.expand a").click(function(){
		if ($(this).nextAll(".jobDescription").css("display")=="none") {
			$(".jobDescription").hide();		
			$(this).nextAll(".jobDescription").fadeIn();
		} else {
			$(".jobDescription").hide();		
		}
		return false;
	});
	$(".browse .show_links").click(function(){
		$(".browse .links").hide();		
		$(this).next().fadeIn();
	});
	function assignClose() {
		$("#mask, #closePopup").click(function(){
			$("#mask").remove();
			$("#popupWrap").remove();
			return false;
			
		});
	}
	function assignNext() {
		$("#nextPopup").click(function(){
			$(".currentBio").next(".bioThumb").addClass("currentBio");
			$(".currentBio:first").removeClass("currentBio");
			var img2 = $("img",$(".currentBio")).attr("src");
			var name2 = $("h2",$(".currentBio")).html();
			var title = $("p",$(".currentBio")).html();
			var content = $(".bioMore",$(".currentBio")).html();
			if ($(".currentBio").next(".bioThumb").length>0) {
			var nameN = $("h2",$(".currentBio").next(".bioThumb")).html();
			var titleN = $("p",$(".currentBio").next(".bioThumb")).html();

			var next = '<a href="" id="nextPopup"><strong>Next:</strong> '+nameN+': '+titleN+'</a>';
			} else {
			var next = "";
			}
			
			function hide () {
				$("#mask").remove();
				$("#popupWrap").remove();
				$("body").append('<div id="mask"></div><div id="popupWrap"><div id="popup"><div id="popupInner"><img src="'+img2+'" class="bigBio"/><h2>'+name2+' <small>'+title+'</small></h2>'+content+'</div><a href="#"><a href="#" id="closePopup"></a>'+next+'</div></div>');
				$("#mask").fadeTo(0, 0);
				height2 = $(document).height();
				$("#mask").css("height",height2+"px");
				$("#mask").css("display","block");
				$("#mask").fadeTo(0, 0.8);
				$("#popup").css("display","block").css("opacity",0);
				function nextev () {
					$("#popup").animate({
						opacity:1,
						left: 0
					}, 500);
					
				}
				$("#popup").animate({opacity:0,left:+100},0,nextev);
				top2 = $(document).scrollTop()+100;
				$("#popupWrap").css("top",top2+"px");



				assignNext();
				assignClose();
			}
			$("#popup").animate({
				opacity:0,
				left:-100
			},500,hide)
			
			return false;
		});
	}
	$(".bioThumb .more").click(function(){
		var img2 = $("img",$(this).parent()).attr("src");
		var name2 = $("h2",$(this).parent()).html();
		var title2 = $("p",$(this).parent()).html();
		var content2 = $(".bioMore",$(this).parent()).html();
		if ($(this).parent().next(".bioThumb").length>0) {
			var nameN = $("h2",$(this).parent().next(".bioThumb")).html();
			var titleN = $("p",$(this).parent().next(".bioThumb")).html();

			var next2 = '<a href="" id="nextPopup"><strong>Next:</strong> '+nameN+': '+titleN+'</a>';
		} else {
			var next2 = "";
		}
		$(".currentBio").removeClass("currentBio");
		$(this).parent().addClass("currentBio");
		$("body").append('<div id="mask"></div><div id="popupWrap"><div id="popup"><div id="popupInner"><img src="'+img2+'" class="bigBio"/><h2>'+name2+' <small>'+title2+'</small></h2>'+content2+'</div><a href="#"><a href="#" id="closePopup"></a>'+next2+'</div></div>');
		$("#mask").fadeTo(0, 0);
		var height2 = $(document).height();
		$("#mask").css("height",height2+"px");
		$("#mask").css("display","block");
		$("#mask").fadeTo(500, 0.8);
		$("#popup").fadeIn();
		top2 = $(document).scrollTop()+100;
//		top2 = 200;
		$("#popupWrap").css("top",top2+"px");
		$("#popup").fadeIn();
		assignClose();
		
		assignNext();
		return false;
	});
	$(".whatMore").hide();
	$(".whatBox1 .brownMore, .whatBox2 .brownMore, .whatBox3 .brownMore, .whatBox4 .brownMore").click(function(){
		if ($(this).parent().prev(".whatMore").css("display")=="none") {
			$(this).parent().prev(".whatMore").fadeIn();
			$(this).html("< Close");
			
		} else {
			$(this).parent().prev(".whatMore").fadeOut();
			$(this).html("More >");
		}

		return false;
	});
	$(".bubbleMore").hide();
	$(".bubble .more").click(function(){
		if ($(this).parent().prev(".bubbleMore").css("display")=="none") {
			$(this).parent().prev(".bubbleMore").css("display","inline");
			$(this).html("< Close");
			
		} else {
			$(this).parent().prev(".bubbleMore").css("display","none");
			$(this).html("More >");
		}

		return false;
	});
	$(".resourceHide").hide();
	$(".resourceCol1 .resourceLink strong,.resourceCol2 .resourceLink strong,.resourceCol3 .resourceLink strong,.resourceCol4 .resourceLink strong").click(function(){
			$(".resourceHide").hide();
		$(this).next(".resourceHide").show();
	});
});