// wrapper for print function
function printPage() {
	window.print();
	return false;
}

// start of every document
$(document).ready( function () {
	
	// hover for 1st level menu images
	$("#nav img").bind("mouseover", function () {
		highlight1stLevelMenuItem($(this));
	})
	.bind("mouseout", function () {
		if(!$(this).hasClass("active")) {
			a = $(this).attr("src");
			$(this).attr("src", a.replace(/-high/, ""));
		}
	});
	
	// also activate the current active menu item
	// this only works for one-level navigations
	var curFilename = location.href.replace(/^.*\/(.*\.php)/, '$1');
	var active1stLevelItem = $("ul.nav-level1 li a[href$='"+curFilename+"'] img");
	highlight1stLevelMenuItem(active1stLevelItem.addClass("active"));
	
	// ... put other actions here ... 
});

function highlight1stLevelMenuItem(item) {
	a = $(item).attr("src");
	if(a) {
		$(item).attr("src", a.replace(/(-high)?\.gif/, "-high.gif"));
	}
}

// ----- BEGIN spam protection -----
function UnCryptMailto(s) {
	var n=0;
	var r="";
	for(var i=0;i<s.length;i++) { 
		n=s.charCodeAt(i);
		// 45 is * which allows special treatment of the letters x to z
		if (n == 45)
		{
			n=s.charCodeAt(i+1);
			r += String.fromCharCode(n);
			++i;
		}
		else
		{
			if (n>=8364) {n = 128;}
			r += String.fromCharCode(n-3);
		}
	}
	return r;
}
function linkTo_UnCryptMailto(s)	{
	location.href=UnCryptMailto(s);
}
// ----- END spam protection -----
