/**
 *  Script qui gère la partie menu du site.
 *  @author ZEZUKA Clément  <clemzezuk@gmail.com>
 */
$(function(){
    
    /**
     *  La variable 'index' est un entier, est correspond à l'index numerique de l'élément de menu en cours de consultation.
     *  @default    0
     */
    var index = 0;
    
    //  Méthode appelée au survol d'un élément du menu.
    $('#menu_box').children().hover(
        function() {
            if (index != $(this).index() / 2) {
                $(this).stop().animate({ opacity: 0 }, 500);  
            }
        },
        function() {
            if (index != $(this).index() / 2) {
                $(this).stop().animate({ opacity: 1 }, 500);
            }
        }
    );
    
    //  Méthode appelée au clique d'un élément du menu
    $('#menu_box').children().click(function(){
        index = $(this).index() / 2;
        menu(index);
    });
    
    /**
     *  Méthode qui gère le scrolling du container ainsi que l'apparence du menu
     *  @param   index
     */
    function menu(index) {
        switch(index) {
            case 0 : $.scrollTo('#rond_home', 800, {offset: {top:-200, left:-( ( $(window).width() - $('#container').width() ) / 2 ) - 635 }, "easing" : 'jswing' });
            break;
            case 1 : $.scrollTo('#rond_realisations', 800, {offset: {top:-100, left:-( ( $(window).width() - $('#container').width() ) / 2 ) }, "easing" : 'jswing' });
            break;
            case 2 : $.scrollTo('#rond_services', 800, {offset: {top:-100, left:-( ( $(window).width() - $('#container').width() ) / 2 ) }, "easing" : 'jswing' });
            break;
            case 3 : $.scrollTo('#rond_contact', 800, {offset: {top:-100, left:-( ( $(window).width() - $('#container').width() ) / 2 ) }, "easing" : 'jswing' });
            break;
        }
        var exp = new RegExp("^[0-9]+$","g");
        $('#menu_box').children().each(function(i) {
            if (exp.test(i/2)) {
                if (i/2 != index) {
                    $(this).animate({opacity:1}, 500);
                }
            }
        });
        $('#menu_box img').eq(index*2).animate({opacity:0}, 500);
    }
    
    //  Lance la méthode 'menu' au lancement du site.
    menu(index);
    
});
