$(document).ready( function() {
	
	// #lang_selector is present ?
	if( $("div#lang_selector").attr('id') != undefined ) {

		// binds #lang_selector click()
		$("div#lang_selector").click(function(){
			$("div#lang_selector_choices").show(); // show choiches
		});
		
		// binds lang selector item click()
		$("li.lang_selector_opt").click(function(){
			var new_lang = $(this).attr("xt:value"); // new language selected
			$("div#lang_selector_choices").hide(); // hide choiches   
			// set new language via ajax call
			$.ajax({
				async: false,
				type: "POST",
				url: "setgetinfo.php",
				data: "a=setlang&v="+new_lang,
				success: function(msg){
					window.location.reload();
				}
			});
			
			
		});
	
		// reads current language via ajax and set the right flag image
		$.ajax({
			async: false,
			type: "POST",
			url: "../../../menu/app/default/setgetinfo.php",
			data: "a=getlang",
			success: function(msg){
				$('img#lang_current_selection').attr("src", "../../../img/flags/"+msg+".png");
				$('img#lang_current_selection').show();
			}
		});
		
	}
	
	
});

