$(document).ready(function(){

    var codeInvit = 'Code avantage';
    $("#codeInvit").attr('value',codeInvit);

    $("#codeInvit").attr('value',codeInvit).focus(function () {
        if (this.value == codeInvit) this.value = '';
    }).blur(function () {
        if (this.value == '') this.value = codeInvit;
    });


    $('#menu>li').hover(function() {
        $(this).addClass('jHover');
        if ($.browser.msie && ($.browser.version.substr(0,1) == 6)) {
            $("#content form select").css('visibility','hidden');
        }
    }, function() {
        $(this).removeClass('jHover');
        if ($.browser.msie && ($.browser.version.substr(0,1) == 6)) {
            $("#content form select").css('visibility','visible');
        }
    });
    
    $('#menu>li>a').focus(function() {
        $('#menu>li').removeClass('jHover');
        $(this).parent().addClass('jHover');
    });
    

    /* Gestion des Carroussels */

    var animationActive = false;

    $("#content .carroussel").each(function() {

        // initialisation variables        
        var item = $(this).find(".slider .item");
        var marge = item.outerWidth(true);
        var vitesse = 700;
        
        // on détermine la taille du slider
        item.parent().css("width",((item.length + 1) * marge)+"px");
        
        if (item.is("div")) vitesse = 1000;
        
        $(this).find("a.prec").click(function(){
            
            if (!animationActive)
            {
                currentSlider = $(this).parent().find(".slider");
                animationActive = true;
                
                if ($(this).parent().is('.fondu')) {
                    currentSlider.find(".item:first").animate({"opacity": 0}, vitesse, "swing", function() {
                        currentSlider.find(".item:last").clone(true).insertBefore(currentSlider.find(".item:first"));
                        currentSlider.find(".item:first").css("opacity", 0).animate({"opacity": 1}, vitesse, "swing").next().css("opacity", 1);
                        currentSlider.find(".item:last").remove();
                        animationActive = false;
                    });
                }
                else {
                    currentSlider.find(".item:last").clone(true).insertBefore(currentSlider.find(".item:first"));
                    currentSlider.css("left", "-"+marge+"px");
                    currentSlider.animate({"left": "+="+marge+"px"}, vitesse, "swing", function() {
                        currentSlider.find(".item:last").remove();
                        animationActive = false;
                    });
                }
            }
            this.blur();
            return false;
        });
        
        $(this).find("a.suiv").click(function(){
        
            if (!animationActive)
            {
                currentSlider = $(this).parent().find(".slider");
                animationActive = true;
                
                if ($(this).parent().is('.fondu')) {
                    currentSlider.find(".item:first").clone(true).insertAfter(currentSlider.find(".item:last"));
                    currentSlider.find(".item:first").animate({"opacity": 0}, vitesse, "swing", function() {
                        $(this).next().css("opacity", 0).animate({"opacity": 1}, vitesse, "swing");
                        $(this).remove();
                        animationActive = false;
                    });
                }
                else {
                    currentSlider.find(".item:first").clone(true).insertAfter(currentSlider.find(".item:last"));
                    currentSlider.animate({"left": "-="+marge+"px"}, vitesse, "swing", function() {
                        currentSlider.find(".item:first").remove();
                        currentSlider.css("left", "0px");
                        animationActive = false;
                    });
                }
            }
            this.blur();
            return false;
        });
        
        // Autoslide
        if ($(this).is('.autoSlide')){

            var btSuiv = $(this).find("a.suiv");

            if ($(this).is('.fondu')) {
                var interval = setInterval(function() { btSuiv.click() }, 10000);
            }
            else {
                var interval = setInterval(function() { setTimeout(function() { btSuiv.click() }, 2500 ) }, 5000);
            }
        
            $(this).bind('mouseover', function(){ clearInterval(interval); });
        }

    });
    
    
    $('#webSite').hide();

});