// When DOM is loaded
$(document).ready(function(){
	
	// -----------------------------------------
	// Add "at" state to active subnav page
	// -----------------------------------------
	$("#subnav a").each(function() {
		if(this.href == window.location || this.href == document.location.protocol + "//" + window.location.hostname + window.location.pathname) {
			$(this).addClass("at");
		}
	});

	// -----------------------------------------
	// Keep content from wrapping around
	// column-right
	// -----------------------------------------
	var content_height = $("#content").height();
	var rcol_height = $("#col_right").height();
	if (content_height > rcol_height) {
		if (content_height > 400) {
			content_height = content_height + (content_height/10);
		}
		$("#col_right").css("height",content_height);
	}
	
	
	// -----------------------------------------
	// De-jumble email addresses
	// -----------------------------------------
	function decryptemail() {
	   var pattern = /^mail:(.+):(.+)$/i;
	   var elms = document.getElementsByTagName("A");
	   for (var i=0;i<elms.length;i++) {
		  var elm=elms[i];
			var str = new String(elm.href);
			if (str.match(pattern)) {
			   elm.href = str.replace(pattern,"mailto:$1@$2");
			   if (elm.hasChildNodes) {
				  var node=elm.childNodes[0];
				  if(node.nodeValue) node.nodeValue = node.nodeValue.replace(pattern,"$1@$2");
			   }
			}
		}
	}
	decryptemail();
	
	// -----------------------------------------
	// Month Select for Updates page
	// -----------------------------------------
	$("#update_month select").change(function(){
		$(".show").each(function(){
			$(this).removeClass("show");
		});
		var selected_year = Number($('#update_month select option:selected').text());
		$("#" + selected_year).addClass("show");
	});	
	
	// -----------------------------------------
	// Get rid of col_right on full-frame pages
	// -----------------------------------------
	$("#content_wrapper:has(.full_frame)").addClass("no-col_right");	
	
	// -----------------------------------------
	// Switch right column to left for Team Bios
	// -----------------------------------------
	$("#col_right:has(#team_subnav)").addClass("switch-to-left");
	
	// -----------------------------------------
	// Performance Rollovers
	// -----------------------------------------
	
	/* Non-Webkit browsers need it to be at doc.ready */
	performance_rollovers();
	
	$("#performance_thumbs li a img").load(function(){
		/* Webkit browsers need it on load */
		performance_rollovers();
	});
	
    $(".no_click").click(function(){return false});

	
	
});
	
function performance_rollovers() {
	$("#performance_thumbs li a").each(function(){
		var img = $(this).children("img.perf_thumb");
		var pos = img.position();
		var div = $(this).children("div.perf_hover");
		div.css("width",img.width());
		div.css("height",img.height());
		div.css("top",(pos.top - 5));
		div.css("left",(pos.left - 5));
	});
};


