
$(function(){

	$("#tabContents .article").hide();

	var minHeight = $("#articlesContainer").height();
	
	// check tabs
	var $tabs = $("#tabSet a");
	var activeTab = $("#tabSet a.active").get(0);
	if(activeTab == undefined) {
		activeTab = $tabs.get(0);
		$(activeTab).addClass("active");
	} else {
		var top = $(activeTab).offset().top - 50;
		if (top < 0) top = 0;
		$("html,body").delay(300).animate({scrollTop:top},{easing:"easeInOutQuad",duration: 1000});
	}
	var	tabContentId = "#" + $(activeTab).attr("rel"); 
	$(tabContentId).show();
	
		
	var height = $(tabContentId).outerHeight();
	height = height < minHeight ? minHeight : height;
	$("#articlesContainer").height(height);
	    		
	$tabs.bind("click", function(){
		
		if(this == activeTab) return false;
		
		var	tabContentId;
		
		if(activeTab) {
			$(activeTab).removeClass("active");
			tabContentId = "#" + $(activeTab).attr("rel");
			$(tabContentId).fadeOut(100);
		}    			
		activeTab = this;
		$(activeTab).addClass("active");
		tabContentId = "#" + $(activeTab).attr("rel");
	
		var height = $(tabContentId).outerHeight();
		height = height < minHeight ? minHeight : height;
		$("#articlesContainer").delay(150).animate({"height":height},{duration:200,easing:"easeInOutQuad",complete:function(){
			$(tabContentId).fadeIn(100);
			$(this).css({"height":"auto"});
		}});
		
		var top = $(activeTab).offset().top;
		if (top < 0) top = 0;
		$("html,body").delay(300).animate({scrollTop:top},{easing:"easeInOutQuad",duration: 400});
		
		return false;
	});
	
});

$.extend( jQuery.easing,
	{
	easeInQuad: function (x, t, b, c, d) {
		return c*(t/=d)*t + b;
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	easeInOutQuad: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) {
			return c/2*t*t + b;
		}
		return -c/2 * ((--t)*(t-2) - 1) + b;
	}
});
