try {
 document.execCommand('BackgroundImageCache', false, true);
} catch(e) {}

$(function() {
	// obfuscate e-mail addresses
	$("a.email:has(span.address)").each(function(i) {
		var encoded = $("span.address", this).attr("innerHTML");
		$(this).attr("href", encoded.replace(/(.+)<em>at<\/em>(.+)/i, "mailto:$1@$2"));
		$("span.address", this).attr("innerHTML", encoded.replace(/<em>at<\/em>/i, "@"));
	});
	// label handling in the contact form
	var loginIds = ["contact-name", "contact-email", "contact-message"];
	jQuery.each(loginIds, function() {
		var currentId = this;
		if ($("#" + currentId).attr("value")) {
			$("label[for=" + currentId + "]").hide();
		}
		$("label[for=" + currentId + "]").click(function() {
			$(this).hide();
		});
		$("#" + currentId).focus(function() {
			$("label[for=" + currentId + "]").hide();
		});
		$("#" + currentId).blur(function() {
			if (!$(this).attr("value")) {
				$("label[for=" + currentId + "]").show();
			}
		});
	});
	// sorting project table
	$("table.projects").tablesorter();
	$(".sorting li a").toggle(function() {
			return customSort($(this), 0);
		},
		function() {
			return customSort($(this), 1);
	});
	function customSort(sortLink, order) {
		$(".sorting li a").removeClass("active");
		sortLink.addClass("active");
		var sorting;
		if (sortLink.parent("li").hasClass("client")) {
			sorting = [[0, order]];
		} else if (sortLink.parent("li").hasClass("industry")) {
			sorting = [[2, order]];
		} else if (sortLink.parent("li").hasClass("scope")) {
			sorting = [[3, order], [4, order], [5,order], [6,order]];
		}
		$("table.projects").trigger("sorton", [sorting]);	
		return false;
	}
});