// initialise menu
jQuery(document).ready(function() {
    /*jQuery('#header ul').superfish();
    jQuery('#sidebar ul').superfish({
        'animation' : {height : 'show'},   // slide-down effect without fade-in
        delay       : 500,
        autoArrows  : true
    });*/

    /********************* Slider actus HOME *********************************************/

    if($('#content_home').length > 0) {
        $('#content_home div#slide_actus div#liste_actus').before('<div id="numeros">').cycle({
            fx:     'turnRight',
            speed:  'fast',
            timeout: 0,
            pager:  '#numeros',
            pagerAnchorBuilder: function(idx, slide) {
                return '<span class="num">'+(idx+1)+'</span>';
            }
        });
    }

    /********************* Menu marques **************************************************/

    $('div#menu_marques div#marques_1').show();
    $('div#menu_marques_next').click(function(){menu_marques_next();});
    $('div#menu_marques_prev').click(function(){menu_marques_prev();});

    /********************* Listes des options ********************************************/

    $('table#liste_options td.une_option a.une_option_a').each(function(){
        var opti_id = $(this).attr('id');
        //BT_setOptions({openWait:0, closeWait:0, enableCache:false});
        
        $(this).qtip({
            content: {
               text: 'Loading...', // The text to use whilst the AJAX request is loading
               ajax: {
                  url: 'ajax/popup_option.php', // URL to the local file
                  type: 'POST', // POST or GET
                  data: {ref : opti_id, langue : $('#langue_options').html()} // Data to pass along with your request
               }
            },
            position: {
                my: 'bottom center',  // Position my top left...
                at: 'top center', // at the bottom right of...
                target: $(this) // my target
            }/*,
            hide: {
                event: 'click'
            }*/
         });

        /*$(this).bt({
            trigger             : 'click',
            positions           : ['top', 'bottom', 'left', 'right'], //['most'],

            width               : '400px',
            ajaxLoading         : 'Chargement...',
            fill                : 'rgb(255, 255, 255)',
            cssClass            : 'tooltip_option',
            closeWhenOthersOpen : true,
            strokeWidth         : 1,

            shadow              : true,
            shadowOffsetX       : 1,
            shadowOffsetY       : 1,
            shadowBlur          : 4,
            shadowColor         : 'rgba(0,0,0,.8)',
            shadowOverlap       : true,
            noShadowOpts        : {strokeStyle: '#000', strokeWidth: 2},

            ajaxPath            : 'ajax/popup_option.php',
            ajaxType            : 'POST',
            ajaxData            : {ref : opti_id, langue : $('#langue_options').html()},
            ajaxCache           : false
        });*/

        /*
        $(this).bt({
            /*ajaxPath            : 'ajax/popup_option.php',
            ajaxType            : 'POST',
            ajaxData            : {ref : opti_id, langue : $('#langue_options').html()},
            ajaxCache           : false
            trigger             : 'click',
            positions           : ['top', 'bottom', 'left', 'right'], //['most'],

            width               : '400px',
            ajaxLoading         : 'Chargement...',
            fill                : 'rgb(255, 255, 255)',
            cssClass            : 'tooltip_option',
            closeWhenOthersOpen : true,
            strokeWidth         : 1,

            shadow              : true,
            shadowOffsetX       : 1,
            shadowOffsetY       : 1,
            shadowBlur          : 4,
            shadowColor         : 'rgba(0,0,0,.8)',
            shadowOverlap       : true,
            noShadowOpts        : {strokeStyle: '#000', strokeWidth: 2},

            ajaxPath            : 'ajax/popup_option.php',
            ajaxType            : 'POST',
            ajaxData            : {ref : opti_id, langue : $('#langue_options').html()},
            ajaxCache           : false
        });*/

    });
});


// Défilement menu des marques
function menu_marques_next() {

    var menu_marques_current = parseInt($('div#menu_marques_current').html());
    var menu_marques_dernier = parseInt($('div.menu_marques').last()[0].id.substr($('div.menu_marques').last()[0].id.length-1,1));

    if (menu_marques_current < 3) {

        $('div#menu_marques_prev')[0].style.visibility = 'visible';

        // Cache le bouton next si avant dernier bloc = current
        if (menu_marques_current == menu_marques_dernier-1) {
            $('div#menu_marques_next')[0].style.visibility = 'hidden';
        }

        $('div.menu_marques').each(function() {
            this.style.display = 'none';
        });

        $('div#marques_'+(menu_marques_current+1)).show();
        $('div#menu_marques_current').html(menu_marques_current+1);
    }
}
function menu_marques_prev() {

    var menu_marques_current = parseInt($('div#menu_marques_current').html());
    var menu_marques_premier = parseInt($('div.menu_marques').first()[0].id.substr($('div.menu_marques').first()[0].id.length-1,1));

    if (menu_marques_current > 1) {

        $('div#menu_marques_next')[0].style.visibility = 'visible';

        // Cache le bouton prev si 2e bloc = current
        if (menu_marques_current == menu_marques_premier+1) {
            $('div#menu_marques_prev')[0].style.visibility = 'hidden';
        }

        $('div.menu_marques').each(function() {
            this.style.display = 'none';
        });

        $('div#marques_'+(menu_marques_current-1)).show();
        $('div#menu_marques_current').html(menu_marques_current-1);
    }
}
