jQuery(function($) {
	
	//******************************//
	//  		GESTION MENU  	//
	//******************************//
	var menu_ok = 0;
	$('#menu li').each(function () {
		var text_li = $(this).html();
		var menu = $(this).attr('name');
		$(this).append('<span class="hover"></span><div class="hoverlink">'+text_li+'</div>'); 
		var span = $('span.hover', this);
		var hoverlink = $('.hoverlink', this);
		hoverlink.css({'display': 'none'});
		$(this).mouseover(function () {
			hoverlink.css({'display': 'block'});
			span.stop().animate({
				marginTop : -100
				},100, function() {
					span.animate({
				  		marginTop : -110
						},100);
				});
		});
		$(this).mouseout(function () {
                    hoverlink.css({'display': 'none'});
                    span.stop().animate({
                        marginTop : -240
                    },100);
		});
		if(menu==check_url()){
                    $(this).find('a').addClass('actif');
                    menu_ok++;
		}
		
		$('.hoverlink a').removeClass('actif');
	});
	
	if(menu_ok==0) {
            $('#menu a:first').addClass('actif');
	}
	
	function check_url() {
        url = document.location.href;
        reg = /^http:\/\/www.tctf.fr\/([a-z0-9]+)/;
        reg.exec(url);
        return RegExp.$1;
	}
	
	//******************************//
	//  	SCROLL TOP        	//
	//******************************//
	$("cite[name^=#]").click(function() {
		allervers=$(this).attr("name");
		if($(allervers).length>=1){
			h=$(allervers).offset().top;
		}
		else {
			h=$("a[name="+allersvers.substr(1,allervers.length-1)+"]").offset().top;
		}
		$("html,body").animate({scrollTop:h},1000)
		return false;
	});	
	
	//******************************//
	//  	ARCHIVES LI SLIDE  	//
	//******************************//
	$('#archives-3 h3').append('<div class="archives_accordeon"></div>');
	$('.archives_accordeon').click(function() {
		if($('#archives-3 li').is(':visible')) {
			$(this).css('background-position', '-255px -130px');
			$('#archives-3 li').slideUp();
		}
		else {
			$(this).css('background-position', '-244px -130px');
			$('#archives-3 li').slideDown();
		}
	});
	
	//******************************//
	//    INPUT RECHERCHE ANIM  	//
	//******************************//
	$('#searchsubmit').val('');
	$('#searchsubmit').click(function() {
		$('#search input[type=text]').stop().css({'background': 'url(static.png) no-repeat -260px -248px'})
	});
	
	//******************************//
	//    		TWEETS		//
	//******************************//
	$('#twitter-widget-3 ul').prepend('<div id="logotwitter"></div>');
	
	//******************************//
	//    		GALERIE OVER	//
	//******************************//
	$('.galerieover').mouseover(function() {
		$(this).stop().animate({
			opacity:0
		})
	});
	
	$('.galerieover').mouseleave(function() {
		$(this).stop().animate({
			opacity:0.5
		})
	});
	
	
	$('.galerieover').click(function() {
		var num = $(this).find('input[type=hidden]').val();
		$('#rg-gallery').empty();
		$('#slider_bg_lan').animate({
			height:60
		},500, function() {
			$('#slider_bg_lan').animate({
                            height:470
			},500, function() {
                            $('#slider_bg_lan').load('../blog/wp-content/themes/TCTF/inc/gallery/index.php?ID='+num);
                            $("html,body").animate({scrollTop:0},1000)
			});
		});
	});
        
        //******************************//
	//   COULEUR TEXTE TS SKIN MOON	//
	//******************************//
        function moon_change_couleur_ts(color1,color2){
            $('#teamspeak').html($('#teamspeak').html().replace(color1,color2));
        }
        if($.cookie("css")=='main-moon.css' && $('#teamspeak').length) {
           moon_change_couleur_ts(/3f3f3f/g,'B8B8B8'); 
        }
//        if($('#teamspeak').length) {
//            alert('est')
//        }
});
