
$(document).ready(function(){
	$(".submit-area input").removeAttr("disabled");
	$("#inspector-form form").submit(function(){
		if ($("#uri").val()!="") {
			$(".button", this).addClass("loading");
		} else {
			$("#uri").focus();
			return false;
		}
	});
	if(!$("#batch").attr("checked")) {
		$("#batch-test .text").hide();
	}
	$("#batch-test .checkbox input").click(function() {
		$("#batch-test .text").slideToggle("fast");
	});
		
	$(".explanation").hide().slideDown("fast");
	$("#result.errors-detected h2").after('<div id="toggle-results"><input type="button" id="toggle" value="Göm utökad information" /></div>');
	$("#result.errors-detected ul ul").each(function(){
		$(this).children("li:gt(10)").hide().parent("ul").after("<a href=\"#\" class=\"show-all\">Visa alla<\/a>");
	});
	$(".show-all").click(function(){
		$(this).prev("ul").find("li:hidden").show();
		$(this).remove();
		return false;
	});
	$("#toggle").toggle(
		function(){
			$(".explanation").slideUp("fast");
			$("#toggle").attr("value", "Visa utökad information");
		},
		function(){
			$(".explanation").slideDown("fast");
			$("#toggle").attr("value", "Göm utökad information");
		}
	);
	$("#content-3").append('<div class="m m-basic"><div class="m-h"><h2>Inspector favelet</h2></div><div class="m-c cf"><p>Dra denna länk till bokmärkesraden för enklare åtkomst.</p><a href="javascript:document.location.href=\'http://inspector.netrelations.se?uri=\'+encodeURIComponent(document.location.href);"><img src="http://www.netrelations.se/i/favelet.png" alt="Inspectorize this" \/><\/a><p>Gå sedan till valfri webbplats och klicka på "Inspectorize this" i bokmärkesraden för att granska den aktuella sidan.</p></div></div>');
	// Insert buttons to hide all errors of a certain type
	// Find the first td in each tr in tbody
	$("#errors tbody td:first-child").each(function(){
	    $(this).append("<button title=\"Dölj alla fel av denna typ\">Dölj</button>");
	    $(this).find("button").click(function(){
	        // Find all tr elements with the same class as the tr the clicked button is in
	        var currClass = $(this).closest("tr").attr("class");
	        $("#errors tr." + currClass).each(function(){
	            // If the current row is the only visible one, hide the entire table
	            if ($(this).siblings(":not(.hidden)").length == 0) {
	                $(this).closest("table").addClass("hidden").next().addClass("hidden");
	            } else {
	                $(this).addClass("hidden");
	            }
	        });
	    });
	});
	//Add checkboxes
	$(function(){
		$('#inspector-form input').customInput();
	});
	//Add box shadows
	$('#page').addCorners();
	//Add text to search box
	$('#searchtext').populateValue();
});
