/* Check if JS on - Remove class 'off' on body */
function jsChecker(){
	if ($("body").hasClass("off")) {
		$("body").removeAttr("class");
	}
}

/* Menu animation */
function animateMenu(){
	$("#btm_nav>li").hover(function(){
		$(this).find("ul").css({
			"height": "auto"
		});
		$(this).find("ul").slideDown(120);
	}, function(){
		$(this).find("ul").stop();
		$(this).find("ul").slideUp(70);
	});	
	$("#btm_nav>li,.links-footer li")
		.mouseover(function(){
			$(this).children("a").stop().animate(
			{backgroundPosition:"0 -27px"},
			{duration:150})
		})
		.mouseout (function(){
			$(this).children("a").stop().animate(
			{backgroundPosition:"0 0"},
			{duration:150})
		});
	$("#btm_nav .nav_level2 li a")
		.mouseover(function(){
			$(this).parents("#btm_nav>li>a").css({
				"background-position": "-300px -27px"
			});
			$(this).stop().animate(
			{backgroundPosition:"0 0"},
			{duration:150})
		})
		.mouseout (function(){
			$(this).stop().animate(
			{backgroundPosition:"-300 0"},
			{duration:150})
		});	
}

/* Tabs navigation */
function tabsNav(){
	$("div[id^='tab_article']").hide();
	$("div[id^='text_next']").hide();
	$("ul.content_nav li:first").addClass("active").show();
	$("div[id^='tab_article']:first").show();	
	
	$(".content_nav li a").click(function(event){
		event.preventDefault();
		$("ul.content_nav li").removeClass("active");
		$(this).parent().addClass("active");
		$("div[id^='tab_article']").hide();
		var activeTab = $(this).attr("href");
		$(activeTab).show();
	});
}

/* News navigation */
function newsNav(){
	$("div[id^='actu']").hide();
	$("a.actu:first").addClass("active").show();
	$("div[id^='actu']:first").show();	
	
	$("a.actu").click(function(event){
		event.preventDefault();
		$("a.actu").removeClass("active");
		$("div[id^='actu']").hide();
		var activeTab = $(this).attr("href");
		$(activeTab).show();
		if(activeTab == "#actu1"){
			$("#imgActu1").attr("src", "/media/img/rond-actif.jpg");
			$("#imgActu2").attr("src", "/media/img/rond-inactif.jpg");
			$("#linkActu1").addClass("active");
			$("#flv-container").append('<object id="flv" type="application/x-shockwave-flash" data="/flash/swf/flvplayer.swf" width="460" height="260"><param name="movie" value="/flash/swf/flvplayer.swf" /><param name="FlashVars" value="flv=30s_vf_v2_as_WMV_16-9.flv&autoplay=1&playercolor=182C75&bgcolor=FFFFFF&showvolume=1&showplayer=1&margin=0&buffer=0" /></object>');
		}else{
			$("#imgActu1").attr("src", "/media/img/rond-inactif.jpg");
			$("#imgActu2").attr("src", "/media/img/rond-actif.jpg");
			$("#linkActu2").addClass("active"); 
			swfobject.removeSWF("/flash/swf/flvplayer.swf");
			$("#flv").remove();
		}
	});
}

/* Change Flash Content */
function flashChange(){
    $(".content_flash_nav a").click(function(event) {
        var swfPath = $(this).attr("href");
        var hSwfPath = swfPath.replace(/(#)/, "")
        var sSwfPath = "/media/flash/" + hSwfPath + ".swf";
        var params = {
            allowFullscreen: "false",
            allowScriptAccess: "always",
            bgcolor: "#FFFFFF",
			loop: "false"
        };
        var attributes = {
            id: "Flash ID",
			loop: "false"
        };
        swfobject.embedSWF(sSwfPath, "flash", "100%", "100%", "9.0.0", "/scripts/lib/swfobject/expressInstall.swf", params, attributes);
		$(".content_flash").show();
        $(".content_flash").addClass("withflash");
    });
}

/*	Called by flash	*/
function hideMyflash()
{
	$("#animation_flash2").hide();
	$("#actilea").show();
	$(".content_flash").hide();
}

/* Navigation de la page nos_egeries_2010.html */
function egeriesNav() {
    if ($('.nos_egeries_2010').length) {
        $('.nav_chat li').click(function() {
            $('.nav_chat li').removeClass('active');
            $(this).addClass('active');
            var indexChat = $('.nav_chat li').index($(this));
            $('.cat_detail > li').hide();
            $($('.cat_detail > li')[indexChat]).show();
            $('.side_steps img').hide();
            $($('.side_steps img')[indexChat]).show();
            return false;
        });
    }
}

/* Navigation de la page benefices.html */
function beneficesNav() {
    if ($('.benefices').length) {
        $('#aside_push a.benefices').click(function() {
        $('#aside_push a.benefices').removeClass('active');
            $(this).addClass('active');
            var indexChat = $('#aside_push a.benefices').index($(this));
            $('#aside_push').removeClass('programme-j1 programme-j7 programme-j14 programme-j21 programme-demain');
            $('#aside_push').addClass($(this).attr('id'));
            $('.text-steps > li').hide();
            $($('.text-steps > li')[indexChat]).show();
            return false;
        });
    }
}

$(document).ready(function () {	
	jsChecker();
	animateMenu();
	tabsNav();
	
	$("#imgActu1").attr("src", "/media/img/rond-actif.jpg");
	$("#imgActu2").attr("src", "/media/img/rond-inactif.jpg");
	$("#linkActu1").addClass("active");	
	newsNav();
	flashChange();
	egeriesNav();
	beneficesNav();	
	$("#actilea").hide();
	
	$('div.expandable p').expander({
	  slicePoint: 160,
	  expandText: '> Lire la suite',
	  widow: 10,
	  expandPrefix: '...',
	  expandEffect: 'show',
	  userCollapseText: '' 
	});	
 });