$(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 remove all errors of a certain type
	// Find the td with class="name" in each tr in tbody
	$("#errors td.name").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 errorClass = $(this).closest("tr").attr("class").split(' ')[1];
	        $("#errors tr." + errorClass).each(function(){
	            // If the current row is the only visible one, remove the entire table
	            if ($(this).siblings().length == 0) {
	                $(this).closest("table").next().remove().end().remove();
	            } else {
	                $(this).remove();
	            }
	        });
	    });
	});
	// Insert checkboxes to toggle errors and warnings
	$("#errors:not('.by-error')").prepend('<div id="toggle-messages"><div class="checkbox"><input type="checkbox" name="toggle-group" id="toggle-errors" /><label for="toggle-errors">Dölj fel</label></div><div class="checkbox"><input type="checkbox" name="toggle-group" id="toggle-warnings" /><label for="toggle-warnings">Dölj varningar</label></div></div>');
	$("#toggle-errors").click(function() {
		$("#errors tr.error").toggleClass("hidden");
	});
	$("#toggle-warnings").click(function() {
		$("#errors tr.warning").toggleClass("hidden");
	});
	// Add custom checkboxes
	$(function(){
		if (jQuery().customInput) {
			$('#inspector-form input').customInput();
		}
	});
	//Add box shadows
	$('#page').addCorners();
	//Add text to search box
	$('#searchtext').populateValue();
});

