(function($){
	
	
	$(function(){
	// initialize all
		//console.log ("in language handler");

		$('#nl').click (function (event) {
			event.preventDefault();
			$lang = "nl";
			// store using cookie plugin
			$.cookie("language", "nl", {path:"/", expires: 999 })
			window.alert ("U selecteerde NL als taal. Het is steeds mogelijk om de taalkeuze later te wijzigen. ");
			/// remove first chars string
			var current_path  =  $.url.attr("path").substr(3)
			
			//window.location = $lang + current_path
			
		}) // end click language selection
		
		

		  $('#fr').click (function (event) {
			  
			event.preventDefault();
			$lang = "fr";
			// store using cookie plugin
			$.cookie("language", "fr", {path:"/", expires: 999})
			window.alert ("Vous choisissez le langue FR. Il reste possible de changer votre langue de choix. ");
			/// remove first chars string
			var current_path  =  $.url.attr("path").substr(3)
			  
			//window.location = $lang + current_path
			}) //end click language selection
				
			
		$('a').click (function() {
			
			if ($(this).hasClass('reallink')) {
			// if menu link then jump to other language version							
				var str="";			
				var str = "/"+ $.cookie ("language");
				var destination = $(this).attr('href');
				$(this).attr('href',  str+destination);
			}
			
			else {
			
			/*  SOLUTION WHEN At INDEX PAGE OR FOOTER  */

	
			var current_pathname = $.url.attr("path");
						
			if (current_pathname  ==  ("/") || current_pathname  ==  ("/index.php") || current_pathname  ==  'null')  {
				//console.log ("path : " + current_pathname);
				$lang = $.cookie ("language");
				window.location = $lang + "/trafficinfo.html"
				} // end if
				else {
				// no action
				} 
				
			} // end else
					
			
			
		}) // end a click
		
	}) // end JQ function 
	

	
	/*
	$(document).bind("load", function() {
		
				window.alert("in languagehandler")
		
		var current_cookie = $.cookie ("language")
		if (current_cookie == undefined || null ) {
			
			window.alert ("The Touring Mobilis site requires your langauge preference. Please select your preference. You can always change this later on. " ) 
			}
			
			else {
				
				window.alert(" DO FORWARD HERE ")
				} 
				   
	});
	*/
	
		
})(jQuery);
