// JavaScript Document
(function($) {
	
	$.switchLang = function(lang, fast, preFunc, postFunc) {
		if (preFunc) preFunc(lang);
		
		if (fast) {
			$("[lang]").hide();
		} else {
			$("[lang]").fadeOut("slow");
		}
		$('[lang]').promise().done(function() {
			$('[lang=' + lang + ']').fadeIn("slow");
			if (postFunc) postFunc(lang);
  	});
	}
	
	$.switchLang.init = function(defaultLang, preFunc, postFunc) {
		$.switchLang(defaultLang,true,preFunc,postFunc);
		
		var langs=['it','en','de','fr'];
		$.each(langs,function(index,item){
			$('[href$=#' + item + ']').click(function(e){
				e.preventDefault();
				$.switchLang(item,false,preFunc,postFunc);
			});
		});
	}
	
})(jQuery);
