/*
lessonPlans
Author:					Matthew Cobbs
Last Updated:		8/13/2008
Description:		jQuery function to retrieve lesson plan details from data.xml,
then display filtered categories and descriptions in three columns: subject,
lesson plans and details.
*/
function lessonPlans () {
	
	var XML;
	
	$.ajax({
		type: "GET",
		url: "data.xml",
		dataType: "xml",
		async: false,
		success: function (xml) {
			XML = xml;
		}
	}); //close $.ajax(
	
	
	$("#col1 li").filter(".alsoflagged").each(function () {  //for each subject and product...
															
		$(this).click(function (e) {	//on click, clear col2 add filtered list of lesson plans
			$("#col2 ul").html("");	
			$("#col3 div").addClass("hidden");
			//$("#col3 div").html("");	
			
			var subject = $(this).children("a").attr("title");
			
			$(XML).find("lesson").filter(function (index) {  //filter lesson plans by subject
				return $("subject", this).text() == subject;
				
			}).each(function () {	 //create a link on each lesson plan to the description in col3
				
				var name_text = $(this).find("name").text();
				var theme_text = $(this).find("theme").text();		
				
				$("<li></li>").html("<a class='sec' href='#'>" + name_text + '</a>').click(function (e) {
					
					$(XML).find("lesson").filter(function (index) {  //filter lesson plans by theme
						return $("theme", this).text() == theme_text;
						
					}).each(function () {  //set col3 values for lesson plan description
						
						$("#RESULT1").html($(this).find("name").text());
						$("#RESULT2").html($(this).find("subject").text());
						$("#RESULT3").html($(this).find("description").text());
						$("#RESULT4").attr("href", $(this).find("address").text());
						
					});  //close each
					
					$("#col3 div").removeClass("hidden");
					
				}  //close click
				).appendTo("#col2 ul");
				
			});  //close each
		
			//bold the selected subject
			$("#col1 li").filter(".alsoflagged").removeClass("bold2");
			$(this).addClass("bold2");	
			
			//show col2
			$("#col2").removeClass("hidden");
			$("#tab2").removeClass("hidden");
			
		});  //close click
	});  //close each
	
} //close lessonPlans