$(document).ready(function(){
	var max_height = getMaxHeight();
	$("#tabbed-resources ul li a").each(function(i){
		var anchor = this.href.split("#")[1];
		if (i == 0) {
  		activateTab(anchor, max_height);
		}
  	if (anchor == location.href.split('#')[1]) {
  		activateTab(anchor, max_height);
  	}
  	$(this).click( function() {
  		activateTab(anchor, max_height);
  		this.blur();
  		return false;
  	});
	});
});

function getMaxHeight(){
	var max_height = 0;
	$("#tabbed-resources > div").each(function(i){
		var height = Math.max(this.scrollHeight,this.offsetHeight);
		if (height > max_height) {
			max_height = height;
		}
	});
	return max_height;
}

function activateTab(anchor, max_height){
	$("#tabbed-resources > div").css("visibility", "hidden");
	$("#tabbed-resources > div").css("height", "0");
	$("#tabbed-resources #"+anchor).css("visibility", "visible");
	//$("#tabbed-resources #"+anchor).css("height", "auto");
	$("#tabbed-resources #"+anchor).css("height", max_height);
	
	$("#tabbed-resources ul li a").each(function(i){
  	var str = this.href.split("#")[1];
  	if (str == anchor) {
  	  $(this.parentNode).addClass('active');
  	}
  	else $(this.parentNode).removeClass('active');
	});
}


