var t_hide_news_bottom;

$(function() {
	debugCss();
	
	$('#header .header-languages div h1').menuLanguages();
	
	$('#site').mouseenter(function() {
		hideNewsBottom();
	});
	
	$('#footer .footer-content-col,#footer-home .footer-content-col').hover(function() {
		clearTimeout(t_hide_news_bottom);
	
		var $$ = $(this);
	
		setTimeout(function() {
			var element_position = $$.position();
			var class_name = $$.find('span a').attr('rel');
			var bloc = $(class_name);
			var bloc_top = element_position.top - bloc.height() + 20;
			
			if (!bloc.hasClass('animate')) {
				bloc.addClass('animate');
				
				bloc.css({
					top: bloc_top + 100,
					left: element_position.left + 100,
					opacity: 0
				});
				
				bloc.show().animate({
					top: bloc_top,
					opacity: 1
				}, function() {
					bloc.removeClass('animate');
				});
			}
		}, 300);
	}, function() {
		var element_position = $(this).position();
		var class_name = $(this).find('span a').attr('rel');
		var bloc = $(class_name);
		var bloc_top = element_position.top;
		
		if (!bloc.hasClass('animate')) {
			bloc.addClass('animate');
			
			bloc.animate({
				top: bloc_top - 200,
				opacity: 0
			}, function() {
				bloc.removeClass('animate').hide();
			});
		}
	});
	
	$('#content').append($('#footer_bas'));
	
	positionFooter();
	
	$('.content-text').height($('.content-text').height() + $('#footer').height());
});

function positionFooter() {
	setTimeout(function() {
		$('#footer').css({
			left: ($(window).scrollLeft() + $(window).width() - $(window).width() / 2 - $('#footer').width() / 2) + 'px',
			width: $(window).width()
		});
		
		$('#footer #footer_bas').css('margin-top', 100);
		
		positionFooter();
	}, 100);
}

$.fn.menuLanguages = function() {
	var $$ = $(this);
	
	$$.each(function() {
		var bloc = $(this).next('div:first');
		
		bloc.find('ul').width($(this).width() );
		
		if ($(this).parent().hasClass('header-languages-pays')) {
			var bloc_width = ($(this).width() ) * bloc.find('ul').length;
		
			bloc.find('ul:last-child').css('border-right', 0);
		
			bloc.width(bloc_width + bloc.find('ul').length - 1).css('margin-left', -bloc_width + ($(this).width() ) - bloc.find('ul').length );
		}
		
		$(this).mouseenter(function() {
			bloc.show();
		});
		
		$(this).parent().mouseleave(function() {
			bloc.hide();
		});
	});
}

function hideNewsBottom() {
	t_hide_news_bottom = setTimeout(function() {
		$('.footer-pop_up').each(function() {
			if ($(this).is(':visible')) {
				$(this).removeClass('animate').hide();
			}
		});
		
		hideNewsBottom();
	}, 500);
}

function debugCss() {
	var ua = navigator.userAgent.toLowerCase();

	var col_right_height = $('#col-right').height();
	var content_height = $('#content .content-text').height();

	if (col_right_height > content_height) {
		$('#content .content-text').height(col_right_height);
	}
	
	if (/chrome/.test(ua)) {
		$('#menu-left h2').css('margin-top', -24);
	}
}
