window.log = function ( string ) {
	if ( typeof console == 'object' ) { console.log ( string ) };
}

var expanded_deep = false;

LTG.start = function(){
	//console.log("LTG.start()");
	LTG.addLoadEvent(function(){							   
		// code in here gets executed once the page loads // begin section
		$("#lesson_spec_nav > div").each(function(i){
			//console.log(this.id);
			$(this).click(function() {
				if(this.className!="tabOn") {
					$("#lesson_spec_nav div").removeClass("tabOn").addClass("tabOff");
					this.className = "tabOn";
				}
				LTG.search_mode = this.id.replace("tab_","");
				location.hash = "#"+LTG.search_mode;
				//alert(LTG.search_mode);
				LTG.showResults(1);
			});
		});
		
		$("#search_hints").click(function() {
			$(window).scrollTo('#search_tips', 1000);
			$("#video_link_img").animate( { opacity:0.5 }, "slow", "swing", function() {
				//window.log("once");
				$("#video_link_img").animate( { opacity:1 }, "slow", "swing", function() {
					//window.log("twice");
					$("#video_link_img").animate( { opacity:0.5 }, "slow", "swing", function() {
						//window.log("thrice");
						$("#video_link_img").animate( { opacity:1 }, "slow", "swing", function() {
							//window.log("finally");																 
						});
					});							 
				});													 
			});
		});
		
		switch(location.hash) {
			case "#browse":
				$("#tab_browse").click();
				break;
			case "#academic_standard":
				$("#tab_academic_standard").click();
				break;
			case "#philanthropy_standard":
				$("#tab_philanthropy_standard").click();
				break;
			case "#text":
				$("#tab_text").click();
				break;
			default:
				$("#tab_keyword").click();
				break;    
		}
		
		$(".grade_buttons div").not("#unCheckAllGrades").not("#checkAllGrades").each(function() {
			$(this).click(function() {
				toggleClass(this, "grade");
				checkChecks(document.search_options_form.grades);
			});
		});
		$(".subject_buttons div").not("#unCheckAllSubjects").not("#checkAllSubjects").each(function() {
			$(this).click(function() {
				toggleClass(this, "subject");
				checkChecks(document.search_options_form.subjects);
			});
		});
		/*
		$("#subject_buttons div").each(function() {
			$(this).click(function() {
				if(this.className=="active") {
					$("#subject_buttons div").removeClass("active");
				} else {
					$("#subject_buttons div").removeClass("active");
					$(this).addClass("active");	
				}
				$("#subject").val($(this).text());
				LTG.showResults(1);
			});
		});
		*/
		$("#letter_buttons div").each(function() {
			$(this).click(function() {
				if(this.className=="active") {
					$("#letter_buttons div").removeClass("active");
					$("#string").attr("value","");
				} else {
					$("#letter_buttons div").removeClass("active");
					this.className = "active";
					$("#string").attr("value",this.id.replace("letter",""));
				}
				LTG.showResults(1);
			});
		});
		//ss_fixAllLinks();
		enterAsTab();
		
		$("#unCheckAllGrades").click(function() {
			$(this).hide();								  
		});
		$("#unCheckAllSubjects").click(function() {
			$(this).hide();								  
		});
		/*
		
		if(the_clicked_subject) {
			var tempSubjectDiv = document.getElementById("subject_" + the_clicked_subject);
			if(tempSubjectDiv) {
				//self.showResults(tempSubjectDiv);
				makeClickedOne(tempSubjectDiv);
			}
		}
		
		*/
		
		setClass("ajax_indicator","hidden");
		if(LTG.state!='') {
		//updateSupporters(LTG.state,'search','LTGsupporters');
		}
		//checkChecks(document.search_options_form.grades);
		// code in here gets executed once the page loads // end section
	});
}
LTG.showResults = function(pageNum) {
	//console.log("LTG.showResults()");
	//trace("showResults()");
	$("#the_search_results").html("...searching...");
	$("#stateSelection").hide();
	$("#gradeSelection").hide();
	$("#subjectSelection").hide();
	$("#letterSelection").hide();
	$("#subjectSelectionAcad").hide();
	$("#text_search").hide();
	//var counter = 0;
	if(pageNum) {
		if( IsNumeric(pageNum)) {
			if(pageNum>0) {
				$("#page").attr("value",pageNum);
			} else {
				alert("Please enter a valid page number");
			}
		} else {
			alert("Please enter a valid page number");	
		}	
	} else {
		pageNum = 1;
	}
	switch(LTG.search_mode) {
		case "academic_standard":
			//trace("acad. stan.");
			$("#video_link").attr("href","videos/"+LTG.search_mode+".asp");
			$("#stateSelection").show();
			var state = document.getElementById("standards_search_state");
			state.onchange = function() {
				LTG.showResults();
			}
			if(document.search_options_form.state[0].value=="choose") {
				//trace("remove choose");
				document.search_options_form.state.remove(0);
			}
			//trace("acad. stan. 2");
			LTG.academicResults();
			break;
		case "philanthropy_standard":
			//console.log("phil.");
			$("#video_link").attr("href","videos/"+LTG.search_mode+".asp");
			$("#gradeSelection").show();
			if(pageNum==1) {
				$("#the_search_results").html('<div class="instructions">Click the <img src="/_graphics/search/plus.gif" style="display: inline; cursor: default;"> buttons below to browse for lesson plans. Click the <img src="/_graphics/search/minus.gif" style="display: inline; cursor: default;"> buttons to collapse results.</div><div class="grade_subject"><div class="grade"><span>Grade:</span> <span id="phil_grade_span"></span></div><div class="subject"><span>Subject:</span> Philanthropy</div></div><div id="the_phil_themes">...loading Philanthropy Standards...</div>');
				LTG.philResults(0,'0');
			} else {
				var strArray = pageNum.split(":");
				LTG.philResults(strArray[0],strArray[1]);				
			}
			break;
		case "text":
			$("#video_link").attr("href","videos/"+LTG.search_mode+".asp");
			//trace("text");
			$("#gradeSelection").show();
			$("#keywords").focus();
			//$("#the_search_results").html("Text");
			LTG.textResults();
			break;
		case "browse":
			//$("#video_link").attr("href","videos/"+LTG.search_mode+".asp");
			$("#video_link").attr("href","videos/keyword.asp");
			LTG.browseResults();
			break;
		case "subject":
			$("#video_link").attr("href","videos/keyword.asp");
			LTG.browseResults();
			break;
		default:
			$("#video_link").attr("href","videos/keyword.asp");
			//trace("keyword");
			LTG.keywordResults();
			break;
	}
}

LTG.browseResults = function() {
	//console.log("LTG.browseResults()");
	$("#gradeSelection").show();
	if(LTG.gradeChosen()) {
		$("#subjectSelection").show();
		if(LTG.subjectChosen()) {
			var options = {
				error: function() {
					$("#the_search_results").html("Sorry, an error has occurred, search failed.");
				},
				success: function(responseText) {
					$("#the_search_results").html(responseText);
					setClass("ajax_indicator","hidden");
					makeLessonHovers(".lessons_indiv .blue img");
					setTabIndex("the_search_results");
				}
			};
			$("#the_search_results").html("...searching...");
			$("#search_options_form").attr("action","/lessons/search/ajax_search_results_browse.asp").ajaxSubmit(options);
			
		} else {
			$("#the_search_results").html("Please choose one or more subjects.");	
		}
	} else {
		$("#the_search_results").html("Please choose one or more grades.");	
	}
}

LTG.keywordResults = function() {
	//console.log("LTG.keywordResults()");
	$("#gradeSelection").show();
	if(LTG.gradeChosen()) {
		$("#subjectSelection").show();
		if(LTG.subjectChosen()) {
			$("#letterSelection").show();
			if(LTG.letterChosen()) {
				var options = {
					error: function() {
						$("#the_search_results").html("Sorry, an error has occurred, search failed.");
					},
					success: function(responseText) {
						$("#the_search_results").html(responseText);
					}
				};
				$("#the_search_results").html("...searching...");
				$("#search_options_form").attr("action","/lessons/search/ajax_show_keywords.asp").ajaxSubmit(options);
				
			} else {
				$("#the_search_results").html("Please choose a letter.");	
			}
		} else {
			$("#the_search_results").html("Please choose one or more subjects.");	
		}
	} else {
		$("#the_search_results").html("Please choose one or more grades.");	
	}
}

LTG.academicResults = function() {
	//console.log("LTG.academicResults()");
	if(LTG.stateChosen()) {
		//trace("show grades selection");
		$("#gradeSelection").show();
		if(LTG.gradeChosen()) {
			//trace("show subject selection");
			$("#subjectSelectionAcad").show();
			if(LTG.subjectChosenAcad()=="selected") {
				var options = {
					error: function() {
						$("#the_search_results").html("Sorry, an error has occurred, search failed.");
					},
					success: function(responseText) {
						//trace("success");
						var strArray = responseText.split("|");
						$("#the_search_results").html(strArray[1]);
					}
				};
				//trace("load the standards");
				$("#the_search_results").html("...loading academic standards...");
				$("#search_options_form").attr("action","/lessons/search/ajax_search_results_lvl1.asp").ajaxSubmit(options);
				
			} else if(LTG.subjectChosenAcad()=="unselected") {
				$("#the_search_results").html("Please choose one or more subjects.");
			} else {
				LTG.getSubjects();
			}
		} else {
			$("#the_search_results").html("Please choose one or more grades.");	
		}
	} else {
		//trace("Please choose a state");
		$("#the_search_results").html("Please choose a state.");
	}
}

LTG.philResults = function(the_id,the_level) {
	//console.log("LTG.philResults()");
	if(LTG.gradeChosen()) {
		$("#subjectSelection").show();
		document.getElementById("the_id").value = the_id;
		document.getElementById("the_level").value = the_level;
		setPhilGrades();
		field = document.search_options_form.subjects;
		var subject_selection = document.getElementById("subjectSelection");
		var any_checked = false;
		for (i = 0; i < field.length; i++) { // check all grades
			if(field[i].checked==true) {
				any_checked = true;
				break;
			}
		}
		
		if(any_checked==false) {
			$("#the_search_results").html("Please select at least one subject.");	
		} else {
			var the_form = document.getElementById("search_options_form");
			if(the_level=='0') {
				the_form.action = '/lessons/search/ajax_search_phil_strands.asp';
			} else if(the_level=='1') {
				the_form.action = '/lessons/search/ajax_search_phil_standards.asp';
			} else if (the_level=='2') {
				the_form.action = '/lessons/search/ajax_search_phil_benchmarks.asp';
				expanded_deep = true;
			} else if (the_level=='3') {
				the_form.action = '/lessons/search/ajax_search_phil_lessons.asp?id=';
				expanded_deep = true;
			} else {
				//console.log("Something went wrong..."+the_level);
			}
			var options = {
				error: function() {
					$("#the_search_results").html("Sorry, an error has occurred, search failed.");
				},
				success: function(str) {
					//$("#the_search_results").html(str);
					var strArray = str.split("|");
					if(strArray[0]=="Error") {
						alert("Error: " + strArray[1]);
					} else {
						var the_id = strArray[0];
						var the_level = strArray[1];
						var the_results = "";
						if(the_level==0) {
							expanded_deep = false;
							the_results = document.getElementById("the_phil_themes");
							if(the_results) {
								the_results.innerHTML = strArray[2];
							} else {
								//console.log("Hmmm...nowhere to put these themes.");
							}
						} else {
							the_results = document.getElementById("temp_"+the_level+"_"+the_id);
							//console.log("...looking for element with the id 'temp_"+ the_id + "'...");
							if(the_results) {
								//the_results.id = "";
								the_results.innerHTML = strArray[2];
								for (i =0 ; i < the_results.childNodes.length; i++) {
									var nodeToClone = the_results.childNodes[i];
									var clonedNode = nodeToClone.cloneNode(true)
									the_results.parentNode.insertBefore(clonedNode,the_results);
								}
								the_results.parentNode.removeChild(the_results);
							} else {
								//console.log("Hmmm...don't know where to put these results!"+the_id);
							}
						}
					}
					//setClass("ajax_indicator","hidden");
					makeLessonHovers();
				}
			};
			$("#search_options_form").ajaxSubmit(options);
		}
	} else {
		$("#the_search_results").html("Please choose one or more grades.");	
	}
}

LTG.textResults = function() {
	//console.log("LTG.textResults()");
	$("#gradeSelection").show();
	if(LTG.gradeChosen()) {
		$("#subjectSelection").show();
		$("#text_search").show();
		var options = {
			error: function() {
				$("#the_search_results").html("Sorry, an error has occurred, search failed.");
			},
			success: function(responseText) {
				$("#the_search_results").html(responseText);
				var keyword = document.getElementById("keywords");
				keyword.focus();
				if(keyword.value) { keyword.select(); }
			}
		};
		$("#the_search_results").html("...searching...");
		$("#search_options_form").attr("action","/lessons/search/ajax_search_results_text.asp").ajaxSubmit(options);
	} else {
		$("#the_search_results").html("Please choose one or more grades.");	
	}
}

LTG.showAcademicResults = function(the_id,the_level) {
	//console.log("showAcademicResults("+the_id+","+the_level+")");
	$.get('/lessons/search/ajax_search_lesson_results.asp',
		{ id: the_id, level: the_level },
		function(str){
			var strArray = str.split("|");
			if(strArray[0]=="Error") {
				//
				alert("Error:"+strArray[1]);
			} else {
				var the_id = strArray[0];
				var the_results = document.getElementById("temp"+the_id);
				if(the_results) {
					//the_results.id = "";
					the_results.innerHTML = strArray[1];
					for (i =0 ; i < the_results.childNodes.length; i++) {
						var nodeToClone = the_results.childNodes[i];
						var clonedNode = nodeToClone.cloneNode(true)
						the_results.parentNode.insertBefore(clonedNode,the_results);
					}
					the_results.parentNode.removeChild(the_results);
				} else {
					//console.log("Hmmm...don't know where to put these results!"+the_id);
				}
			}
			setClass("ajax_indicator","hidden");
			makeLessonHovers();
		}
	);
}

LTG.getSubjects = function() {
	//console.log("LTG.getSubjects()");
	$("#subject_select").html("...loading subjects...");
	var options = {
		error: function() {
			$("#the_search_results").html("Sorry, an error has occurred, search failed.");
		},
		success: function(responseText) {
			var the_results = document.getElementById("the_search_results");
			var strArray = responseText.split("|");
			if(strArray[0]=="Error") {
				//trace("got subjects::ERROR");
				$("#the_search_results").html(strArray[1]);
			} else {
				//trace("got subjects::SET EM UP");
				var subject_select = document.createElement("select");
				subject_select.name = "subject_select";
				subject_select.size = 1;
				subject_select.id = "subject_select_select";
				subject_select.onchange = function() {
					var me = this;
					if(me[0].value=="choose") {
						me.remove(0);
					}
					if(me.value=="choose") {
						// remove existing results
						the_results.innerHTML = "";
					} else {
						LTG.showResults(1);
					}
				}
				if((subjectCookie=="") || (subjectCookie=="choose")) {
					var subject_option;
					subject_option = document.createElement("option");
					subject_option.value = "choose";
					subject_option.appendChild(document.createTextNode("Choose Subject"));
					subject_select.appendChild(subject_option);
				}
				for (i = 0; i < strArray.length; i++) {
					subject_option = document.createElement("option");
					subject_option.value = strArray[i];
					subject_option.appendChild(document.createTextNode(strArray[i]));
					if(subject_option.value==subjectCookie) {
						subject_option.selected = true;
					}
					subject_select.appendChild(subject_option);
				}
				var loader_span = document.getElementById("subject_select");
				loader_span.innerHTML = "";
				loader_span.appendChild(subject_select);
				$("#subject_select select").attr("name","subject_select");
				if(subject_select.value!="choose"){
					//trace("SHOW RESULTS AGAIN::"+subject_select.value);
					LTG.showResults(1);
				} else {
					$("#the_search_results").html("Please choose a subject.");
				}
			}
		}
	};
	//trace("DO AJAX Submit");
	$("#search_options_form").attr("action","/lessons/search/ajax_show_subjects.asp").ajaxSubmit(options);
}

LTG.stateChosen = function() {
	//console.log("LTG.stateChosen()");
	if(document.search_options_form.state.selectedIndex.value!="choose" 
	   	&& document.search_options_form.state.selectedIndex.value!="") {
		return true;
	} else {
		return false;
	}
}
LTG.gradeChosen = function() {
	//console.log("LTG.gradeChosen()");
	var any_checked = false;
	var grades = document.search_options_form.grades;
	for (i = 0; i < grades.length; i++) { // check all grades
		if(grades[i].checked==true) {
			any_checked = true;
			break;
		}
	}
	if(any_checked==false)
		return false;
	else
		return true;
}
LTG.subjectChosen = function() {
	//console.log("LTG.subjectChosen()");
	var any_checked = false;
	var subjects = document.search_options_form.subjects;
	for (i = 0; i < subjects.length; i++) { // check all grades
		if(subjects[i].checked==true) {
			any_checked = true;
			break;
		}
	}
	if(any_checked==false)
		return false;
	else
		return true;
}
LTG.subjectChosenAcad = function() {
	//console.log("LTG.subjectChosenAcad()");
	var the_select = document.getElementById("subject_select_select");
	if(the_select) {
		//trace("yes");
		if(the_select.selectedIndex.value!="choose" 
			&& the_select.selectedIndex.value!="") {
			return "selected";
		} else {
			return "unselected";
		}
	} else {
		//trace("no select");
		return "";	
	}
}
LTG.letterChosen = function() {
	//console.log("LTG.letterChosen()");
	var letter = document.search_options_form.string.value;
	var val = letter.length;
	if((val == 1) || (val==2) || (val==3)) {
		return true;
	} else {
		return false;
	}
} 

LTG.setGradesCookie = function() {
	//console.log("LTG.setGradesCookie");
	var the_form = document.getElementById("search_options_form");
	the_form.action = '/lessons/search/ajax_set_grade_cookie.asp';
	var options = {
		error: function() {
			alert("Sorry, an error has occurred attempting to set grade cookie.");
		},
		success: function(responseText) {
			setClass("ajax_indicator","hidden");
		}
	};
	$(the_form).ajaxSubmit(options);
	setClass("ajax_indicator","");
}

LTG.setSubjectsCookie = function() {
	//console.log("LTG.setSubjectsCookie");
	var the_form = document.getElementById("search_options_form");
	the_form.action = '/lessons/search/ajax_set_subjects_cookie.asp';
	var options = {
		error: function() {
			alert("Sorry, an error has occurred attempting to set subject cookie.");
		},
		success: function(responseText) {
			setClass("ajax_indicator","hidden");
		}
	};
	$(the_form).ajaxSubmit(options);
	setClass("ajax_indicator","");
}

LTG.addLoadEvent = function(func){
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

LTG.start();
		
function IsNumeric(sText) {
	//console.log("IsNumeric("+sText+")");
	var ValidChars = "0123456789.";
	var IsNumber=true;
	var Char;

	for (i = 0; i < sText.length && IsNumber == true; i++) { 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) {
		 IsNumber = false;
		}
	}
	return IsNumber;
}

	/*----------------------------------------------------------------------------
		Checks or unchecks all of the checkboxes in the collection passed
		field = the collection
		check = check-->checked, anything else--> unchecked
	-------------------------------*/
	function checkAllGrades(check) {
		//console.log("checkAll("+check+")");
		var grade = "";
		var button = "";
		var field = document.search_options_form.grades;
		for (i = 0; i < field.length; i++) {
			grade = field[i].id.replace("check_","");
			button = document.getElementById("grade" + grade);
			if(check=="check") {
				field[i].checked = true;
				button.className = "active";
				//console.log("check:" + button);
			} else {
				field[i].checked = false;
				button.className = "";
				//console.log("uncheck:" + button);
			}
		}
		LTG.setGradesCookie();
	}
	
	/*----------------------------------------------------------------------------
		Checks or unchecks all of the checkboxes in the collection passed
		field = the collection
		check = check-->checked, anything else--> unchecked
	-------------------------------*/
	function checkAllSubjects(check) {
		//console.log("checkAllSubjects("+check+")");
		var subject = "";
		var button = "";
		var field = document.search_options_form.subjects;
		for (i = 0; i < field.length; i++) {
			subject = field[i].id.replace("check_","");
			button = document.getElementById("subject" + subject);
			if(check=="check") {
				field[i].checked = true;
				button.className = "active";
				//console.log("check:" + button);
			} else {
				field[i].checked = false;
				button.className = "";
				//console.log("uncheck:" + button);
			}
		}
		LTG.setSubjectsCookie();
	}
	
	/*----------------------------------------------------------------------------
		Set all of the grades to checked or unchecked
		depending on what button is calling the function
	-------------------------------*/
	function toggleChecks(the_button) {
		//console.log("toggleChecks("+the_button+")");
		if((the_button.title=="Select All Grades")||(the_button.title=="Select All Subjects")) {
			if(the_button.id=="checkAllSubjects") {
				checkAllSubjects("check");
			} else {
				checkAllGrades("check");
			}
		} else {
			if(the_button.id=="unCheckAllSubjects") {
				checkAllSubjects("uncheck");
			} else {
				checkAllGrades("uncheck");
				$("#subjectSelection").hide();
			}
		}
		if(the_button.id=="checkAllSubjects") {
			checkChecks(document.search_options_form.subjects);
		} else {
			checkChecks(document.search_options_form.grades);
		}
	}
	/*----------------------------------------------------------------------------
		Checks to see if any fields are checked.
		Gets subjects if so.
	-------------------------------*/
	function checkChecks(field) {
		//console.log("checkChecks('"+$(field).attr("name")+"')");
		$("#page").attr("value",1); // reset page number to 1
		var any_checked = false;
		var got_results = false;
		var subject_selection = document.getElementById("subjectSelection");
		for (i = 0; i < field.length; i++) { // check all grades
			if(field[i].checked==true) {
				any_checked = true;
				subject_selection.className = "active";
				//if( (LTG.search_mode=="browse") || (LTG.search_mode=="keyword") || (LTG.search_mode=="text") || (LTG.search_mode=="academic_standard") ) {
					if(got_results==false) {
						LTG.showResults(1);
						got_results = true;
					}
				//} else {
				//	$("#subjectSelection").show();
				//	$("#the_search_results").html("<span class=\"red\">Please select a subject.</span>");
				//}			
				break;
			}
		}
		if(any_checked==false) { // no grades checked
			if($(field).attr("name")=="subjects") {
				$("#the_search_results").html("<span class=\"red\">Please select at least one subject.</span>");
				$("#unCheckAllSubjects").hide();
			} else {
				subject_selection.className = "hidden";
				$("#the_search_results").html("<span class=\"red\">Please select at least one grade.</span>");
				$("#subjectSelection").hide();
				$("#unCheckAllGrades").hide();
			}
		} else {
			if($(field).attr("name")=="subjects") {
				$("#unCheckAllSubjects").show();
			} else {
				$("#unCheckAllGrades").show();
			}
		}
	}
	
	/*----------------------------------------------------------------------------
		Sets the class of the element with the id passed to the class passed
	-------------------------------*/
	function setClass(the_id,the_class) {
		//console.log("setClass(" + the_id + "," + the_class + ")");
		var the_element = document.getElementById(the_id);
		if(the_element) {
			the_element.className = the_class;
		}
	}
	
	/*----------------------------------------------------------------------------
		Toggles the class of the grade buttons between checked and unchecked
		Toggles the hidden corresponding checkboxes
		Calls checkChecks to see if any of the grades are checked
		Calls setGradesCookie to update the grades cookie
	-------------------------------*/
	function toggleClass(theElement, grade_subj) {
		//console.log('toggleClass("'+theElement.id+'")');
		var theOne= theElement.id.replace("grade", "");
		theOne= theOne.replace("subject", "");
		//console.log("theGrade:"+theGrade);
		var theCheckbox= document.getElementById("check_"+theOne);
		if(theElement.className=="active") {
			theElement.className="";
			theCheckbox.checked=false;
		} else {
			theElement.className="active";
			theCheckbox.checked=true;
		}
		if(grade_subj=="grade") {
			//checkChecks(document.search_options_form.grades);
			LTG.setGradesCookie();
		} else {
			LTG.setSubjectsCookie();
			//checkChecks(document.search_options_form.subjects);
		}
		
	}
	
	/*----------------------------------------------------------------------------
		Sets the class of the subject that was clicked
		and removes the class of the previously active subject
	-------------------------------*/
	function makeClickedOne(the_element) {
		//console.log("makeClickedOne");
		var the_other_clicked_one = document.getElementsBySelector(".the_clicked_one");
		if(the_other_clicked_one[0]) {
			the_other_clicked_one[0].className = "";
		}
		the_element.className = "the_clicked_one";
		the_clicked_subject = the_element.id.replace("subject_","");	
	}
	
	function showLessons(the_div,the_selector) {
		//console.log("showLessons()");
		var the_lessons = the_div.nextSibling;
		if(the_lessons) {
			$(the_lessons).slideToggle();
			/*
			if(the_lessons.className=="lessons hidden") {
				the_lessons.className="lessons";
			} else {
				the_lessons.className="lessons hidden";
			} 
			*/
			makeLessonHovers(the_selector);
			//$("#clickPosText").remove();
		} else {
			alert("NO next sibling");
		}
	}

/* Academic Standards Search */
	function showChildren(the_id,the_div,the_level) {
		//console.log(showChildren);
		var tr = the_div.parentNode;
		var the_image = the_div.childNodes[0];
		if(the_image.title=="Collapse Results") {
			// delete kids and toggle image
			the_image.src = "/_graphics/search/plus.gif";
			the_image.title="Search Here";
			removeResults(the_level,the_div);
		} else {
			// perform search and toggle image
			the_image.src="/_graphics/search/minus.gif"
			the_image.title="Collapse Results";
			var tmp_div = document.createElement("div");
			tmp_div.id = "temp"+the_id;
			tmp_div.appendChild(document.createTextNode("...loading..."));
			tr.parentNode.insertBefore(tmp_div,tr.nextSibling);
			LTG.showAcademicResults(the_id,the_level);
		}
	}
	function removeResults(the_level,the_div) {
		//console.log("removeResults()");
		var doneKilling = false;
		var tmpDivLevel = ""
		while (doneKilling == false) {
			var nextDiv = the_div.parentNode.nextSibling;
			if(nextDiv) {
				//console.log("nextDiv"+nextDiv);
				$(".nothing_found").remove();
				tmpDivLevel = nextDiv.className.replace("result lvl","");
				//alert(tmpDivLevel);
				if((parseInt(tmpDivLevel)>the_level)||(tmpDivLevel=='acad_lessons')) {
					//alert(tmpDivLevel + ":" + the_level);
					nextDiv.parentNode.removeChild(nextDiv);
				} else {
					doneKilling = true;
				}
			} else {
				doneKilling = true;
			}
		}
	}
// End Academic Standards extra functions


/* ----------------------------------------
Philanthropy Theme Functions */

	function setPhilGrades() {
		//console.log("setPhilGrades()");
		var phil_grade_span = document.getElementById("phil_grade_span");
		var the_grades = "";
		var gradeK = document.getElementById("check_K");
		if(gradeK.checked == true) the_grades = the_grades + " " + "K,";
		var grade1 = document.getElementById("check_1");
		if(grade1.checked == true) the_grades = the_grades + " " + "1,";
		var grade2 = document.getElementById("check_2");
		if(grade2.checked == true) the_grades = the_grades + " " + "2,";
		var grade3 = document.getElementById("check_3");
		if(grade3.checked == true) the_grades = the_grades + " " + "3,";
		var grade4 = document.getElementById("check_4");
		if(grade4.checked == true) the_grades = the_grades + " " + "4,";
		var grade5 = document.getElementById("check_5");
		if(grade5.checked == true) the_grades = the_grades + " " + "5,";
		var grade6 = document.getElementById("check_6");
		if(grade6.checked == true) the_grades = the_grades + " " + "6,";
		var grade7 = document.getElementById("check_7");
		if(grade7.checked == true) the_grades = the_grades + " " + "7,";
		var grade8 = document.getElementById("check_8");
		if(grade8.checked == true) the_grades = the_grades + " " + "8,";
		var grade9 = document.getElementById("check_9");
		if(grade9.checked == true) the_grades = the_grades + " " + "9,";
		var grade10 = document.getElementById("check_10");
		if(grade10.checked == true) the_grades = the_grades + " " + "10,";
		var grade11 = document.getElementById("check_11");
		if(grade11.checked == true) the_grades = the_grades + " " + "11,";
		var grade12 = document.getElementById("check_12");
		if(grade12.checked == true) the_grades = the_grades + " " + "12,";	
		the_grades = the_grades.substr(1,the_grades.length-2);
		phil_grade_span.innerHTML = the_grades;
	}
	
	function getPhilResults(the_id,the_div,the_level) {
		//console.log("getPhilResults()");
		var tr = the_div.parentNode;
		var the_image = the_div.childNodes[0];
		if(the_image.title=="Collapse Results") {
			// delete kids and toggle image
			the_image.src = "/_graphics/search/plus.gif";
			the_image.title="Search Here";
			removeResults(the_level,the_div);
		} else {
			// perform search and toggle image
			the_image.src="/_graphics/search/minus.gif"
			the_image.title="Collapse Results";
			var tmp_div = document.createElement("div");
			tmp_div.id = "temp_" + the_level + "_" + the_id;
			tmp_div.appendChild(document.createTextNode("...loading..."));
			tr.parentNode.insertBefore(tmp_div,tr.nextSibling);
			LTG.philResults(the_id,the_level);
		}
	}

/* -------------------------------------*/

/* ----------------------------------------
Test Search Functions */
	//+ Jonas Raoni Soares Silva
	//@ http://jsfromhell.com/forms/enter-as-tab [v1.0]
	//========================================================
	// REQUIRES http://www.jsfromhell.com/geral/event-listener
	//========================================================
	
	enterAsTab = function(){
	    function next(e){
		   var l, i, f, j, o = e.target;
		   if(e.key == 13 && !/textarea|select/i.test(o.type)){
			  for(i = l = (f = o.form.elements).length; f[--i] != o;);
			  for(j = i; (j = (j + 1) % l) != i && (!f[j].type || f[j].disabled || f[j].readOnly || f[j].type.toLowerCase() == "hidden"););                
			  e.preventDefault(), j != i && f[j].focus();
			  LTG.showResults(1);
		   }
	    }
	    for(var f, i = (f = document.forms).length; i; addEvent(f[--i], "keypress", next));
	};
	
	/*
	**************************************
	* Event Listener Function v1.4       *
	* Autor: Carlos R. L. Rodrigues      *
	**************************************
	*/
	addEvent = function(o, e, f, s){
	    var r = o[r = "_" + (e = "on" + e)] = o[r] || (o[e] ? [[o[e], o]] : []), a, c, d;
	    r[r.length] = [f, s || o], o[e] = function(e){
		   try{
			  (e = e || event).preventDefault || (e.preventDefault = function(){e.returnValue = false;});
			  e.stopPropagation || (e.stopPropagation = function(){e.cancelBubble = true;});
			  e.target || (e.target = e.srcElement || null);
			  e.key = (e.which + 1 || e.keyCode + 1) - 1 || 0;
		   }catch(f){}
		   for(d = 1, f = r.length; f; r[--f] && (a = r[f][0], o = r[f][1], a.call ? c = a.call(o, e) : (o._ = a, c = o._(e), o._ = null), d &= c !== false));
		   return e = null, !!d;
	    }
	};
/* -------------------------------------*/	
	

////////////////////////Smooth Scrolling\\\\\\\\\\\\\\\\\\\\\\\

function ss_fixAllLinks() {
	//console.log("ss_fixAllLinks()");
 // Get a list of all links in the page
 var allLinks = document.getElementsByTagName('a');
 // Walk through the list
 for (var i=0;i<allLinks.length;i++) {
   var lnk = allLinks[i];
   if ((lnk.href && lnk.href.indexOf('#') != -1) &&  
       ( (lnk.pathname == location.pathname) ||
   ('/'+lnk.pathname == location.pathname) ) &&  
       (lnk.search == location.search)) {
     // If the link is internal to the page (begins in #)
     // then attach the smoothScroll function as an onclick
     // event handler
     ss_addEvent(lnk,'click',smoothScroll);
   }
 }
}

function smoothScroll(e) {
 // This is an event handler; get the clicked on element,
 // in a cross-browser fashion
 if (window.event) {
   target = window.event.srcElement;
 } else if (e) {
   target = e.target;
 } else return;
 
 // Make sure that the target is an element, not a text node
 // within an element
 if (target.nodeType == 3) {
   target = target.parentNode;
 }
 
 // Paranoia; check this is an A tag
 if (target.nodeName.toLowerCase() != 'a') return;
 
 // Find the <a name> tag corresponding to this href
 // First strip off the hash (first character)
 anchor = target.hash.substr(1);
 // Now loop all A tags until we find one with that name
 var allLinks = document.getElementsByTagName('a');
 var destinationLink = null;
 for (var i=0;i<allLinks.length;i++) {
   var lnk = allLinks[i];
   if (lnk.name && (lnk.name == anchor)) {
     destinationLink = lnk;
     break;
   }
 }
 
 // If we didn't find a destination, give up and let the browser do
 // its thing
 if (!destinationLink) return true;
 
 // Find the destination's position
 var destx = destinationLink.offsetLeft;  
 var desty = destinationLink.offsetTop;
 var thisNode = destinationLink;
 while (thisNode.offsetParent &&  
       (thisNode.offsetParent != document.body)) {
   thisNode = thisNode.offsetParent;
   destx += thisNode.offsetLeft;
   desty += thisNode.offsetTop;
 }
 
 // Stop any current scrolling
 clearInterval(ss_INTERVAL);
 
 cypos = ss_getCurrentYPos();
 
 ss_stepsize = parseInt((desty-cypos)/ss_STEPS);
 ss_INTERVAL = setInterval('ss_scrollWindow('+ss_stepsize+','+desty+',"'+anchor+'")',10);
 
 // And stop the actual click happening
 if (window.event) {
   window.event.cancelBubble = true;
   window.event.returnValue = false;
 }
 if (e && e.preventDefault && e.stopPropagation) {
   e.preventDefault();
   e.stopPropagation();
 }
}

function ss_scrollWindow(scramount,dest,anchor) {
	wascypos = ss_getCurrentYPos();
	isAbove = (wascypos < dest);
	window.scrollTo(0,wascypos + scramount);
	iscypos = ss_getCurrentYPos();
	isAboveNow = (iscypos < dest);
	if ((isAbove != isAboveNow) || (wascypos == iscypos)) {
		// if we've just scrolled past the destination, or
		// we haven't moved from the last scroll (i.e., we're at the
		// bottom of the page) then scroll exactly to the link
		window.scrollTo(0,dest);
		// cancel the repeating timer
		clearInterval(ss_INTERVAL);
		// and jump to the link directly so the URL's right
		location.hash = anchor;
	}
}

function ss_getCurrentYPos() {
 if (document.body && document.body.scrollTop)
   return document.body.scrollTop;
 if (document.documentElement && document.documentElement.scrollTop)
   return document.documentElement.scrollTop;
 if (window.pageYOffset)
   return window.pageYOffset;
 return 0;
}

function ss_addEvent(elm, evType, fn, useCapture)
// addEvent and removeEvent
// cross-browser event handling for IE5+,  NS6 and Mozilla
// By Scott Andrew
{
 if (elm.addEventListener){
   elm.addEventListener(evType, fn, useCapture);
   return true;
 } else if (elm.attachEvent){
   var r = elm.attachEvent("on"+evType, fn);
   return r;
 }
}  

var ss_INTERVAL;
var ss_STEPS = 25;
//\\\\\\\\\\\\\\\\\\\\\\\\////////////////////////