$(document).ready(function() {
	$('a.fontsize_increase').fontsize('+');
	$('a.fontsize_decrease').fontsize('-');
	
	$('.menu_v, .menu_h, #menu_main').menueffect({ effectOn : 'dropDown', effectOff : 'fade', effectOnDuration : 'fast', effectOffDuration : 'fast' });
	$('#submenu').menuaccordion();
	
	// Apparition de l'image de fond du niveau 1
 	$('#menu_main ul:first > li').mouseenter(function(){
 		if(!$(this).hasClass('current')){
			domElem = $(this).children('a:first');
			domElem.children('img.active').css({ position: 'absolute', top: '0', left: '0' }).fadeIn('normal');
			//domElem.children('img.normal').hide();					
 		}
	}).mouseleave(function(){
 		if(!$(this).hasClass('current')){
			domElem = $(this).children('a:first');
			domElem.children('img.active').hide();
			//domElem.children('img.normal').show();
 		}
 	});
 	
 	// Initialisation de l'image de fond de l'élément courant
 	$('#menu_main ul:first > li.current').each(function(){
		domElem = $(this).children('a:first');
		domElem.children('img.active').show();
		domElem.children('img.normal').hide();
 	});
 	$('#menu_main ul:first > li.last').each(function(){
 		li = $(this)
 		ul = li.children('ul');
 		ul.left = 82 - ul.width() + 'px';
 		ul.css({ left: ul.left });
 	});
	
	$('#homepage_carousel').maincarousel({ transitionEffect : 'fade', durationEffect : '1000', durationPause : '5000', transitionMode : 'hide' });
	
	// Hide footer
	$('.hidefooter_head').click(function(){
		$(this).toggleClass('show');
		$('.hidefooter_body').e('blindVertical', 'slow');
	});
	
	// Hide header
	$('.hideheader_body table td:first').addClass('first');
	$('.sitemap').click(function(e){
		e.preventDefault();
		title = $(this).attr('title');
		if(title == 'Show sitemap'){
			$(this).attr('title', 'Hide sitemap');
		} else if(title == 'Hide sitemap'){
			$(this).attr('title', 'Show sitemap');
		}
		$('.hideheader_body').e('blindVertical', 'slow');
	});
	
	// Positionnement de l'image de fond
	bgposition = function(){
		/*
		NAME		:	SANS	AVEC
		Chrome		:	X		OK
		Firefox 4	:	OK		OK
		IE8			:	OK		OK
		IE7			:	X		OK
		IE6			:	X		OK
		Safari		:	X		OK
		Opéra		:	X		OK
		*/
		
		bg = {};
		samewidth = {};
		html = {};
		
		bg.w = 1670;
		samewidth.w = $('.same_width:first').width();
		html.w = $('html').width();
		
		samewidth.left = Math.round(html.w / 2) - Math.round(samewidth.w / 2) + 'px';
		bg.left =  Math.round(html.w / 2) - Math.round(bg.w / 2) + 'px';
				
		$('.same_width').css('margin-left', samewidth.left);
		//$('#content_body').css('backgroundPosition', bg.left + ' top');
		$('#columns_all_inner2_fw').css('backgroundPosition', bg.left + ' -110px');
		
	}
	
	$(window).resize(bgposition);
	bgposition();
	
	// Application de la classe active au survol de souris
	$('#homepage_box .morelink, #homepage_box .media .text').mouseenter(function(){
		$(this).addClass('active');
	}).mouseleave(function(){
		$(this).removeClass('active');
	});
	
	// Application de la classe active à tous les liens enfants de l'élément survolé
	$('#homepage_box .events .link, #homepage_box .media .text, #homepage_box .news .item, .contentElement_grey .rub_link').mouseenter(function(){
		$(this).css('cursor', 'pointer').addClass('active');
		$(this).find('a').addClass('active');
	}).mouseleave(function(){
		$(this).removeClass('active');
		$(this).find('a').removeClass('active');
	}).click(function(){
		var href = $(this).find('a').first().attr('href');
		window.location.href = href;
	});
	
	$( ".jquery_accordion" ).accordion({
		autoHeight: false,
		active: 0
	});
	
	$( ".jquery_tabs" ).tabs();
	$("input.type_checkbox").uniform();
	
	// Ajout de la croix bleue en début de paragraphe
	$('p.bluecross').prepend('<span class="bluecross"></span>');
	
	// Application de la classe active aux items de la liste des événements
	$('#events_list .item').mouseenter(function(){
		$(this).find('.title, .info, .more a, .visual').addClass('active');
		$(this).css('cursor', 'pointer');
	}).mouseleave(function(){
		$(this).find('.title, .info, .more a, .visual').removeClass('active');		
	}).click(function(){
		var href = $(this).find('a').first().attr('href');
		window.location.href = href;
	});
	
	$("a[rel='popin_img']").colorbox();
	$("a[rel='popin_imgInColumn']").colorbox();
	var videoW = 480 + 80;
	var videoH = 320 + 40;
	$("a[rel='popin_video']").colorbox({iframe: true, innerWidth: videoW, innerHeight: videoH});
	
	$("a[rel='popin_diaporama']").colorbox({iframe: true, innerWidth: 1024, innerHeight: 576});
	
	$('.eventslide').eventslide({ posLeftHide: '-261', posLeftShow: 0 });

	$('#homepage_links .headline_news').rsscarousel({speed: 3000});
	
	$('.thumbnail_list.player_01 a').click(function(e){
		e.preventDefault();
		$(this).addClass('current').siblings().removeClass('current');
		href = $(this).attr('href');
		$('.video_player iframe.player_01').attr('src', href);
	});
});

