$(document).ready(function() {
	
	$("a#in").click(function(event){
		$("div#box").fadeIn("slow");
	});
	$("div#box").click(function(event){
		$("div#box").hide();
	});
	
	$("#section_all").click(function(){
		if ($(this).is(":checked")) {
			$("input[id^=section_]:not(#section_all)").attr('checked', true );
		}
	});
	
	$("input[id^=section_]:not(#section_all)").click(function(){
		if ($(this).not(":checked")) {
			$("#section_all").attr('checked', false);
		}
	});
	
	$("#searchForm").submit(function() {
		
		var searchText = $("#searchText", this).val();
		
		var sections = [];
		$("input[id^=section_]:checked:not(#section_all)").each(function(){
			sections[sections.length] = $(this).val();
		});
		sections = sections.join(",");
		
		var newURL = window.location.protocol + "//" + window.location.host + "/Search2" 
		if (searchText) {
			newURL += "/(searchText)/" + searchText;
		}	

		if (sections) {
			newURL += "/(sections)/" + sections;
		}
		
		window.location = newURL;
		
		return false;
	});
	
	$(".showPerPageLink").click(function() {
		
		$.cookie("perPage", $(this).attr("href"), { path: '/'});
		$("#searchForm").submit();
		
		return false;
	});
	
	if ((typeof(searchText) != "undefined") && searchText) {
		$(".searchResults").highlight(searchText);
	}
});
