window.addEvent("domready", function () 
{
	$$("div.result_findings_need_to_match").each(function (div) 
	{
		var ul = div.getElement("ul");
		var h6 = div.getElement("h6");

		var old_title = h6.get("text");
		var old_title_formatted = h6.get("text").toLowerCase().replace(/[^a-zA-Z ]/g, "");
		
		var not_matched = ul.getElements("li.result_finding_not_matched");
		var matched = ul.getElements("li.result_finding_matched");

		// if there are no key findings that match, then hide them all (inc. title)
			if (!matched || !matched.length)
			{
				// create link to display findings
					var a = new Element("a", { "href" : "#", "text" : "click here to show " + old_title_formatted } );
					a.setStyles({
						"display"		: "block",
						"padding-top"	: "0.5em"
					});

					a.addEvent("click", function (e) 
					{
						e.stop();
						div.removeClass("result_findings_dont_match");
						this.destroy();
					});

					a.inject(div, "before");

					div.addClass("result_findings_dont_match");
			}
		// if there are some that match then hide the ones that don't
			else
			{
				div.addClass("result_findings_match");

				//h6.set("text", "Matching " + old_title);

				var li = new Element("li");
				li.setStyles({
					"list-style-type"	: "none"/*,
					"padding-left"		: "0",
					"margin-left"		: "0"*/
				});

				if (not_matched.length)
				{
					var a = new Element("a", { "href" : "#", "text" : "click here to show other " + old_title_formatted } );
					a.setStyle("font-size", "85%");

					a.addEvent("click", function (e) 
					{
						e.stop();
						h6.set("text", old_title);
						div.removeClass("result_findings_match");
						li.destroy();
					});

					a.inject(li);
					li.inject(ul);
				}
			}

	});	
});
