$(
	function(){
		$("#language_switcher .enabler").click(
			function(oEvent){
				if($(".lang", $(this).parent()).hasClass("opened"))
				{
					$(".lang", $(this).parent()).fadeOut("fast").removeClass("opened");
					$("#enabler_back").animate({opacity:0.1});
					$("#menu_back").fadeOut("fast");
					$("#pointer_to_bottom").show();
					$("#pointer").appendTo($("#language_switcher")).hide();
				}
				else
				{
					$(".lang", $(this).parent()).show().addClass("opened");
					$("#pointer").appendTo($("#language_switcher li.current")).show();
					$("#pointer_to_bottom").hide();
					$("#enabler_back").hide();
					$(this).hide();
					//$("#language_switcher .enabler").hide();
					$("#menu_back").show().css({opacity:0.3});
				}
				oEvent.cancelBubble = true;
				oEvent.returnValue = false;

				if(oEvent.cancelable){
					oEvent.preventDefault();
					oEvent.stopPropagation();
				}
				return false;
			}
		);
		
		
		
		$("#pointer_to_bottom").click(
			function(oEvent){
				if($(".lang", $(this).parent()).hasClass("opened"))
				{
					$(".lang", $(this).parent()).fadeOut("fast").removeClass("opened");
					$("#enabler_back").animate({opacity:0.1});
					$("#menu_back").fadeOut("fast");
					$("#pointer_to_bottom").show();
					$("#pointer").appendTo($("#language_switcher")).hide();
				}
				else
				{
					$(".lang", $(this).parent()).show().addClass("opened");
					$("#pointer").appendTo($("#language_switcher li.current")).show();
					$("#pointer_to_bottom").hide();
					$("#enabler_back").hide();
					$("#language_switcher .enabler").hide();
					//$("#language_switcher .enabler").hide();
					$("#menu_back").show().css({opacity:0.6});
				}
				oEvent.cancelBubble = true;
				oEvent.returnValue = false;

				if(oEvent.cancelable){
					oEvent.preventDefault();
					oEvent.stopPropagation();
				}
				return false;
			}
		);
		
		$("#language_switcher li").hover(
			function(){
				$("#highlighter").appendTo($(this)).show();
			},
			function(){
				
			}
		);
		
		var enablerAnimates = false;
		$("#language_switcher .enabler").hover(
			function(){
				if(enablerAnimates){ $("#enabler_back").stop().dequeue(); }
				$("#enabler_back").show().css({opacity:0.3});
			},
			function(){
				if($("#language_switcher .lang").hasClass("opened") == false)
				{
					enablerAnimates = true
					$("#enabler_back").animate({opacity:0.1}, function(){enablerAnimates = false});
				}
			}
		);
		
		$("#pointer_to_bottom").hover(
			function(){
				if(enablerAnimates){ $("#enabler_back").stop().dequeue(); }
				$("#enabler_back").show().css({opacity:0.3});
			},
			function(){
				if($("#language_switcher .lang").hasClass("opened") == false)
				{
					enablerAnimates = true
					$("#enabler_back").animate({opacity:0.1}, function(){enablerAnimates = false});
				}
			}
		);
		
		$(document).click(
			function(){
				if($("#language_switcher .lang").hasClass("opened"))
				{
					$("#language_switcher .lang").fadeOut("fast").removeClass("opened");
					$("#menu_back").fadeOut("fast", function(){
						$("#pointer").appendTo($("#language_switcher")).hide();
						$("#enabler_back").animate({"opacity":"0.1"}).show();
						//$("#language_switcher .enabler").show();
						$("#pointer_to_bottom").show();
						$("#language_switcher .enabler").show();
					});
					
				}
			}
		);
	}
);
