$(document).ready(function() {

    // afficher / masquer le détail d'un §
    $('.js_slideContent').each(function() {
        $(this).hide();
    })
    $('.js_slideTitle').each(function() {
        $(this).mouseover(function() {
            $(this).css("cursor", "help");
        });
        $(this).click(function() {
            $(this).next().slideToggle();
        });   
    });

    // slider home
    window.home_scrollable = $("#home").scrollable({
        size: 1,
        rotate: false,
        items: '.items',
        prev: '#nav_prev',
        next: '#nav_next',
        'clickable': false,
        onBeforeSeek: function() {
            return (window.home_popup == null);
        }
    }).autoscroll({
        interval: 5000,
        autopause: false,
        api: true
    });

    jQuery.each([$('#nav_next'), $('#nav_prev'), $('#home .tabs li')], function() {
        this.click(function() {
            window.home_scrollable.stop();
        });
    });

    // gestion cookie test accueil
    init_cookie = $.cookies.get('init_form_answer');
    if((init_cookie != '1') && (init_cookie != '2') && (init_cookie != '3') && (init_cookie != '4')) {
        if (window.welcome_answers != null) {
            window.home_popup = $.fn.colorbox({
                href:'/home/form',
                transition:'fade',
                iframe:true,
                opacity:0.8,
                width:550,
                height:250,
                overlayClose:false,
                open:true,
                onClosed: function() {
                    window.home_popup = null;
                    answer_idx = $.cookies.get('init_form_answer') - 1;
                    answer_text = window.welcome_answers[answer_idx];
                    if(answer_text != "") {
                        $('#welcome_message').html( answer_text );
                    }
                    if(answer_text != null) {
                        if(window._gaq != undefined) {
                          _gaq.push(['_trackPageview', ('/motif_visite/'+window.tracking_urls[answer_idx])]);
                        }
                    }
                }
            });
        }
    }

    // map clients
    if($('js_map')) {
        var params = {
            menu: "false",
            wmode: "transparent"
        };
        swfobject.embedSWF("map-clients.swf", "js_map", "260", "217", "10", "expressInstall.swf", null, null, params, null);
    }
    
    // cocher les cases du test au clic
    if($('ul.test')) {
        $('ul.test li a').live('click', function() {
            $(this).addClass('checked');
        });
    }

});

