$(document).ready(function() {
	// show full thesaurus JS functionality
	var table = $("table.eparl");
	var groups = table.find("tr.group");
	groups.css("cursor", "pointer");
	
	$(table).before('<a href="#" id="eparl-collapsible-toggle">'+i18n.togglesections+'</a><br/>&nbsp;');
	$("#eparl-collapsible-toggle").click(function(event) {
		var selected = !$(this).hasClass("selected");
		$(this).toggleClass("selected");
		if (selected) {
			table.find("tr.group").addClass("expanded");
			table.find("tr.borderbottom").show();
		} else {
			table.find("tr.group").removeClass("expanded");
			table.find("tr.borderbottom").hide();
		}
		event.preventDefault();
	});
	
	
	groups.each(function() {
		var td = $(this).find("td");
		var text = td.text();
		td.text("");
		td.append('<span>'+text+'</span>');
		var group = td.parent().attr("id");
		if (group == "Aktuell") {
			td.parent().addClass("expanded");
		} else {
			table.find("tr.borderbottom."+group).hide();
		}
	});
	groups.click(function(e) {
		$this = $(this);
		var group = $this.attr("id");
		if ($this.hasClass("expanded")) {
			table.find("tr.borderbottom."+group).hide();
			$this.removeClass("expanded");
		} else {
			table.find("tr.borderbottom."+group).show();
			$this.addClass("expanded");
		}
	});
});

