/**
 * For telling the world how awesome i am ;) Q: But why do you need this script?
 * A: Because i want to make the footer universal-usable
 */
( function($) {
	function openW3Check(loc) {
		var newwindow = window.open(loc, '_blank');
		if(window.focus){
			newwindow.focus();
		}
	}
	function bindW3Check(item) {
		$item = $(item);
		var loc = encodeURIComponent(window.location);
		loc = loc.replace("(", "%28");
		loc = loc.replace(")", "%29");
		loc = loc.replace("*", "%2A");
		loc = loc.replace("!", "%21");
		loc = loc.replace("~", "%7E");
		loc = loc.replace("'", "%27");
		loc = "http://validator.w3.org/check?uri=" + loc + ";verbose=1";
		if(item.nodeName == "A"){ // only do this on links
			$item.attr("href", loc); // do this just for DOM ;)
		}
		bindW3CheckEvent($item, loc);
	}
	function bindCSSW3Check(item) {
		$item = $(item);
		var loc = encodeURIComponent(window.location);
		loc = loc.replace("(", "%28");
		loc = loc.replace(")", "%29");
		loc = loc.replace("*", "%2A");
		loc = loc.replace("!", "%21");
		loc = loc.replace("~", "%7E");
		loc = loc.replace("'", "%27");
		loc = "http://jigsaw.w3.org/css-validator/validator?uri=" + loc
				+ "&profile=css3&usermedium=all&warning=1&vextwarning=";
		if(item.nodeName == "A"){ // only do this on links
			$item.attr("href", loc); // do this just for DOM ;)
		}
		bindW3CheckEvent($item, loc);
	}
	function bindW3CheckEvent($item, loc) {
		$item.on('click', function() {
			openW3Check(loc);
			return false;
		});
	}
	$(function() {
		$(".w3c").each(function(index, item) {
			bindW3Check(item);
		});
		$(".w3c_css").each(function(index, item) {
			bindCSSW3Check(item);
		});
	});
} )(jQuery);
