jQuery(document).ready(function() {
	//Default Action
	jQuery(".tab_content").hide(); //Hide all content
	if ( jQuery(".tab_content:first").height() > 20 )
	{
		jQuery("ul.tabs li:first").addClass("active").show(); //Activate first tab
		jQuery(".tab_content:first").show(); //Show first tab content
		jQuery(".tab_content:first .tabbedSectionContents .tabbedSectionRows").each(function(){
			var maxh = 0;
			jQuery(this).find(".tabbedSectionElements").each(function() {
			  if (jQuery(this).height() > maxh)
				 maxh = jQuery(this).height();
			});
			jQuery(this).find(".tabbedSectionElements").height(maxh);
			jQuery(this).height(maxh);
		});
	}
	else
	{
		jQuery("ul.tabs li:eq(1)").addClass("active").show(); //Activate first tab
		jQuery(".tab_content:eq(1)").show(); //Show first tab content
		jQuery(".tab_content:eq(1) .tabbedSectionContents .tabbedSectionRows").each(function(){
			var maxh = 0;
			jQuery(this).find(".tabbedSectionElements").each(function() {
			  if (jQuery(this).height() > maxh)
				 maxh = jQuery(this).height();
			});
			jQuery(this).find(".tabbedSectionElements").height(maxh);
			jQuery(this).height(maxh);
		});
	}
	
	//On Click Event
	jQuery("ul.tabs li").click(function() {
		jQuery("ul.tabs li").removeClass("active"); //Remove any "active" class
		jQuery(this).addClass("active"); //Add "active" class to selected tab
		jQuery(".tab_content").hide(); //Hide all tab content
		var activeTab = jQuery(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		jQuery(activeTab).show(); //Fade in the active content

		jQuery(activeTab).find(".tabbedSectionContents .tabbedSectionRows").each(function(){
			var maxh = 0;
			jQuery(this).find(".tabbedSectionElements").each(function() {
			  if (jQuery(this).height() > maxh)
				 maxh = jQuery(this).height();
			});
			jQuery(this).find(".tabbedSectionElements").height(maxh);
			jQuery(this).height(maxh);
		});

		if ( jQuery("#itemRelatedNew").height() > 0 )
		{
			jQuery(activeTab).css("height","auto");
			jQuery("#itemRelatedNew").css("height","auto");
			jQuery("#tabcontents").css("height","auto");
			if ( jQuery(activeTab).height() > jQuery("#itemRelatedNew").height() )
			{
				jQuery("#itemRelatedNew").height( jQuery(activeTab).height() );
				jQuery("#tabcontents").height( jQuery(activeTab).height() + 40 );
			}
			else 
			{
				jQuery(activeTab).height( jQuery("#itemRelatedNew").height() - 19 );
				jQuery("#tabcontents").height( jQuery("#itemRelatedNew").height() + 20 );
			}
		}

		return false;
	});

});

function swapCont(tabnum) 
{
	jQuery("ul.tabs li:eq("+tabnum+")").click();
	jQuery('html,body').animate({scrollTop: jQuery("#tabbed-browsing").offset().top},'slow');
}
