function getlastsegment(){
	var pathArray = window.location.pathname.split( '/' );
	return pathArray[pathArray.length-1];
}

// get last segment :
var lastsegment = getlastsegment();
var currenturl = window.location.toString(); // get the current url

$(document).ready(function(){
	
	// get the last segment of the url (the file name part) :
	// lastsegment = getlastsegment();
	// set cookie according to the file suffix (index_en.html) :
	// if (/_fr\./.test(lastsegment)) {
	// 	$.cookie('lang', 'fr');
	// }else if(/_en\./.test(lastsegment)){
	// 	$.cookie('lang', 'en');
	// }
	// get cookie :
	// alert($.cookie('lang'));

	// when we click on the language link :
	$('#noslash a').click(function(){
		
		var newurl ='';
		
		if (/_fr\./.test(lastsegment)){ // if we are in a _fr file : 
			newurl = currenturl.replace(/_fr\./,'_en.'); // replace the language abbrev into the file name
			$.cookie('lang', 'en'); 	// set cookie
		}else if(/_en\./.test(lastsegment)){
			newurl = currenturl.replace(/_en\./,'_fr.');
			$.cookie('lang', 'fr'); 
		}
		
		window.location = newurl; // proceed to the redirection
return false;
	});
});

// Hide emails from spiders
function formatAddress(address,label) {
	var parts = address.split(/#[^#]*#/);
	var moc = parts[0].split("").reverse();
	parts[0] = moc.join("");
	var email = parts[3] + "@" + parts[1] + parts[2] + "." + parts[0];
	if(label=="") label = email;
	var emAddLink = "<a class='links' href='ma" + "il" + "to" + ":" + email +"'>" + label + "</a>";
	return emAddLink;
}

