$(function() {


	/*$.address.change(function(event) {  
	
		$('p#content-filter a').removeClass('active');
		  
		var urlHash = window.location.hash.substr(1);
	
		if(urlHash){
	
		if($('ul.content-to-filter li.' + urlHash).length > 0){
			
			// hide physicians that do not match the filter
			$('ul.content-to-filter li:visible').hide();
		
			// show physicians that do match the filter
			$('ul.content-to-filter li.' + urlHash).show();
			
			$("p#content-filter a[hash='#" + urlHash + "']").addClass('active');
			
		};
		
		} else {
	
		$('a#reset-filter').addClass('active');
	
		};
		  
	}); */


	
	// find the count for each specialty and add that value to the filter links
	// won't need this after EE temp setup
	$('p#content-filter a').each(function(){
	
		var thisId = $(this).attr('href').substr(1);
		
		var countValue = $('ul.content-to-filter li.' + thisId).length;
		
		$(this).children('em').text(countValue);
	
	});
	
	// show what is in the hash if it exists
	var urlHash = window.location.hash.substr(1);
	
	if(urlHash){
	
		/*if($('ul.content-to-filter li.' + urlHash).length > 0){*/
			
			// hide physicians that do not match the filter
			$('ul.content-to-filter li').fadeTo('medium',0.4);
		
			// show physicians that do match the filter
			$('ul.content-to-filter li.' + urlHash).fadeTo('medium',1.0);
			
			$("p#content-filter a[hash='#" + urlHash + "']").addClass('active');
			
		/*};*/
		
	} else {
	
		$('a#reset-filter').addClass('active');
	
	};
	
	
	//var url = location.href.split('/')[5];
	//var x = url[5];
	
	
	url = location.href.split('/');
	segment = url[5]; 
	
	$('ul#main-navigation li#' + segment).addClass('filter-this');

	// filter click function
	$('p#content-filter a , ul#main-navigation li.filter-this ul li a').click(function(){

		var thisId = this.hash.substr(1);
		
		//alert(thisId);
		
		// remove class active
		$('p#content-filter a').removeClass('active');
		
		// hide physicians that do not match the filter
		$('ul.content-to-filter li').fadeTo('slow',0.4);
		
		/*var lastSlash = $(this).attr('href').lastIndexOf("/");
		
		var thisId = $(this).attr('href').substr(1);
		
		var url=this.href.split('/');
		var v = url[7];
		
		alert(v);*/
		
		if(thisId == "view-all") {
		
		$('ul.content-to-filter li').fadeTo('medium',1.0);
		
		} else {
		
		// show physicians that do match the filter
		$('ul.content-to-filter li.' + thisId).fadeTo('medium',1.0);
		
		};
		
		window.location.hash = "#" + thisId;
		
		// add class active to this
		$("p#content-filter a[hash='#" + thisId + "']").addClass('active');
		
		$("ul#main-navigation li.filter-this ul").hide();
		
		return false;
	
	});

});