//Launch Action
$(document).ready(function(){
    new Menu('.menu .wgMenu');
});


/**
 *  initialize menu Listener
 * @param : <string> content's CSS selector
 */
var Menu = function(s_selector){
    //define menu content
    var $ct = $(s_selector);

    $('ul' , $ct).hide();

    //dispatch the 'display:block' propereties from 'li.on'
    var $current_ul = $('.on' ).parent().parent();
    while($current_ul.is('ul')){
        $current_ul.show();
        $current_ul.prev().addClass('on');
        $current_ul = $current_ul.parent().parent();
    }

    //define click event on link
    $('a[href=#]:not(.on)',$ct).click(function(e){
        e.stopPropagation();
        //$(this).toggleClass('on');
        $(this).next().toggle();
    });

    // On affiche le sous-menu de l'entrée correspondant à la page en cours
    // pour certaines pages.
    if ( -1 != window.location.search.indexOf('pageId=135') ||
         -1 != window.location.search.indexOf('pageId=142') ||
         -1 != window.location.search.indexOf('pageId=152') ||
         -1 != window.location.search.indexOf('pageId=171') ||
         -1 != window.location.href.indexOf('assurance_vie_capi') ||
         -1 != window.location.href.indexOf('compte_titres') ||
         -1 != window.location.href.indexOf('fcpi_fip') ||
         -1 != window.location.href.indexOf('immobilier_investissement')
       )
    {
        $('> li.on ul', $ct).show();
    }
}


