$(document).ready(function()
{
	$('#navigation .menu-item').hover(
	function()
	{
		var $submenu = $(this).find('.sub-menu');
		if ($submenu.size() != 0)
		{
			if ($submenu.width() < $(this).width())
				$submenu.width($(this).width());
			$submenu.show();
		}
	},
	function()
	{
		var $submenu = $(this).find('.sub-menu');
		if ($submenu.size() != 0)
		{
			$submenu.hide();
		}
	});
	
	var animating = false;
	
	$('#languageBackground').fadeTo(0, 0.0);
	$('#languageWrapper').fadeTo(0, 0.0);
	
	$('#flags a').click(function()
	{
		if (!animating)
		{
			var rel = $(this).attr('rel');
			$.get('/special/'+rel, {}, function(data)
			{
				animating = true;
				$('#languageBackground').show().fadeTo('slow', 0.5, function() { animating = false; });
				$('#languageContent').html(data);
				$('#languageWrapper').animate({opacity: 1, height: 'show'}, 'normal');
			});
		}
		return false;
	}); 
	
	$(window).scroll(function() {
		$('#languageBackground,#languageWrapper').css('top', $(window).scrollTop());
	});
	
	$('#languageBox').click(function() {
		return false;
	}); 
	
	$('#languageBackground, #languageWrapper, #closeButton').click(function()
	{
		if (!animating)
		{
			$('#languageBackground').animate({opacity: 0}, 'slow', function() { $(this).hide(); animating = false;  });
			$('#languageWrapper').animate({opacity: 0, height: 'hide'}, 'normal');
		}
	});
});

