$(document).ready(function(){
	// doc filters
	/*
	$("#fad_sort_form select").change(function(){
		$('#results_table tbody tr').show();
		$('#fad_sort_form select').each(function(){
			if($(this).val() != '')
			{
				$('#results_table tbody tr:visible:not(.' + $(this).val() + ")").hide();
			}
		});
	});
	*/
	
	$('#community_docs_checkbox').change(function (){
		// toggle the community doctors and whether they are viewable
		if($(this).is(':checked')){
			$('#com-doc').hide();
			changeHref(/\/0\//,'/1/');
		}
		else {
			$('#com-doc').show();
			changeHref(/\/1\//,'/0/');
		}
	});

	function changeHref(regex,to){
		$("a[href]").each(function() {
			var href = $(this).attr("href");
			var match = regex.exec(href);
			// console.log("got " + regex + " " + href + " " + match);
			if ( match ) {
				$(this).attr("href", href.replace(regex, to));
			}
		});
	}
	
	$('#hidephotos').change(function(){
		if($(this).is(':checked')){
			$('.photo div').hide();
			// save a cookie to hide photos
			$.cookie('Ochsner_Find_A_Doctor', 'hideDocPhotos', { path: '/', expires: 1000 });
		}
		else{
			$('.photo div').show();
			// save a cookie to show photos
			$.cookie('Ochsner_Find_A_Doctor', null, { path: '/' });
		}
	});
	
	if($.cookie('Ochsner_Find_A_Doctor') == 'hideDocPhotos'){
		$('.photo div').hide();
		$('#hidephotos').attr("checked","checked");
	}
});
