$(function(){


	//All Articles Filter Tabs
	$('a.articleTab').click(function() {

		$('a.articleTab.active').removeClass("active");
		$(this).addClass("active");

		var filterVal = $(this).text().toLowerCase().replace(' ','');

		if (filterVal == 'allarticles') {

			$('div#articleList div.brace div.hidden').show().removeClass('hidden');

		} else {

			$('div#articleList div.brace div').each(function() {
				if(!$(this).hasClass(filterVal)) {
					$(this).hide().addClass('hidden');
				} else {
					$(this).show().removeClass('hidden');
				}
			});

		}



    });

});


// Use window.onload so the sifr text fires first
window.onload = function() {

	// Check for hash tag (ie. #wellness)
	if (window.location.hash) {
		
		// Get the filter value
		var filterVal = location.hash.slice(1);
		// Build the tab id
		var filterTab = "#" + filterVal + "Tab";
		
		// Check for a value, just in case the url was /nutrition/articles/#
		if (filterVal) {
		
			// Remove active class from all tabs
			$('a.articleTab.active').removeClass("active");
			// Add active class to just the one tab
			$(filterTab).addClass("active");
		
			// Run through category groups, hide/show them based on filterVal (same as above)
			$('div#articleList div.brace div').each(function() {
				if(!$(this).hasClass(filterVal)) {
					$(this).hide().addClass('hidden');
				} else {
					$(this).show().removeClass('hidden');
				}
			});
		
		}
		
	}
 
};