$(function() {

	/* toelichting collapsible */
	$("div#kwaliteit td.toelichting").each(function() {
		if ($(this).text().length > 2) {

			var header = $("<span>toon toelichting</span>").collapsible({
				buttonText: {
					collapsed: "+",
					expanded: "-"
				},
				counterPrefix: "button-toelichting-",
				target: "$(this).parent().next('.toelichtingstekst')"
			});

			$(this).wrapInner($("<div class='toelichtingstekst'></div>").hide());
			$(this).prepend(header);
		}
	});

	$("div.truncate").each(function(index, group) {
		var $group = $(group);
		var cutoff = $.classToObject($group.attr("class")).cutoff;
		var height = (cutoff) ? cutoff + "px" : "150px";
		var $text  = $group.prev("h3:first").text().toLowerCase();
		var $button = $("<button class='switch'>Toon " + $text + " volledig</button>").toggle(function(e) {
			$group.css({
				height: "auto"
			});
			$button.html("Toon " + $text + " beperkt");
			e.preventDefault();
		}, function(e) {
			$group.css({
				height: height
			});
			$button.html("Toon " + $text + " volledig");
			e.preventDefault();
		});
		
		$group.css({
			height: height,
			overflow: "hidden"
		});
		$group.after($button);
	});
	
	if($(".switch:first").css('background-image') == "none") {
      $(".switch").remove();	
	}

	/* truncate long lists */
	$("div.detailview ul").each(function(index, list) {
		if ($(this).find("li").length > 20) {
			$(this).find("li:gt(19)").hide();
			//$.equalHeights(1);
			$(this).after($("<button>toon volledige lijst</button>").click(function(e) {
				$(list).find("li").show();
				$(this).hide();
				e.preventDefault();
			}));
		}
	});

});

