$(document).ready(function(){

	//hides all records by default
	$("li.indivRecord").hide();
	
	//hides title details paragraphs by default
	$(".indivRecord div").hide();
	
	//shows "show title details"
	$(".showDetails, .mark").css("display","inline");
	
	//sets the title attribute of each menu link to match its text contents
	$("#subjectMenuContainer a").attr("title", function(){return (this).text});
	
	//allows users to highlight individual records for easy reference
	$("#English .mark").toggle(function(){
	
		$(this).addClass("unMark").text("remove mark");
		$(this).parent(".indivRecord").css("background-color","#ff9");
		
	}, function(){
	
		$(this).removeClass("unMark").text("mark this title");
		$(this).parent(".indivRecord").css("background-color","#fff");
	
	});
	
	//allows users to toggle descriptions of each title	
	$("#English .showDetails").toggle(function(){
	
		$(this).siblings("div").slideDown();
		$(this).addClass("hide").text("hide title details");
	
	}, function(){
	
		$(this).siblings("div").slideUp();
		$(this).removeClass("hide").text("show title details");
	
	});
	
	//allows users to highlight individual records for easy reference - SPANISH
	$("#Spanish .mark").toggle(function(){
	
		$(this).addClass("unMark").text("quite la marca");
		$(this).parent(".indivRecord").css("background-color","#ff9");
		
	}, function(){
	
		$(this).removeClass("unMark").text("marque este título");
		$(this).parent(".indivRecord").css("background-color","#fff");
	
	});
	
	//allows users to toggle descriptions of each title - SPANISH	
	$("#Spanish .showDetails").toggle(function(){
	
		$(this).siblings("div").slideDown();
		$(this).addClass("hide").text("haga los detalles invisibles");
	
	}, function(){
	
		$(this).siblings("div").slideUp();
		$(this).removeClass("hide").text("demuestre los detalles");
	
	});
		
	//shows all listings when user clicks the link in the introductory paragraph
	$(".showAll").click(function(){
	
		$(".indivRecord").show();
		
	});
	
	//assigns each titles subjects to a title attribute
	
	$(".indivRecord").each(function(){
	
		var subjectTitle = $(this).children("span.subjectFlags").text();
	
		$(this).attr("title",subjectTitle);
	
	});
	
	//shows title listings based on user clicking links in menu and hides all listings not related to selected subject
	$("#subjectMenuContainer a").click(function(){
	
		var subjectContent = $(this).text();
		
		$(".indivRecord").hide();
		$(".indivRecord[title*='" + subjectContent + "']").show();
		$(this).addClass("menuSelected");
		$("#subjectMenuContainer a").not(this).removeClass("menuSelected");
	
	});

});
