jQuery(function(){

	/**
	 * Find language selector list, and modify links
	 * 
	 * Instead of relying on the server to set the lang cookie,
	 * set the cookie from JS and then reload the page, letting
	 * the server find the correct language page.	 
	 */
jQuery('#language-select a').click(function(){
		// Language Changing Link: location + ?lang [ + optional anchor ]
		var q = this.href.match(/\?(\w{2})(#.*)?$/);
		// must have found a 2 letter language code and cookies
		if (!q || !navigator.cookieEnabled) return true;
		// set the cookie to the desired language
		var date = new Date();
		var end = date.getTime() + (364 * 24 * 60 * 60 * 1000);
		date.setTime(end);
		document.cookie = "lang="+q[1]+";path=/;expires=" + date.toGMTString();
		// anchor in language link found? then update the anchor
		if (q[2]) window.location.hash = q[2];
		// and then simply refresh the page!
		window.location.reload();
		// prevent default action
		return false;
	});

});

// eof
