$(document).ready(function(){
    // ajustement du fond de page
    $('#background').css('height', $(document).height()+'px');
    $(window).resize(function(){ $('#background').css('height', $(document).height()+'px'); });
    // items
    $('.item').hover(function(){
        $(this).addClass('item_hover');
    }, function(){
        $(this).removeClass('item_hover');
    });
    // gallery
    $('.gallery').each(function(){
        var thumbs = $(this).find('a');
        var large = $('#product_illustration');
        thumbs.click(function(){
            large.attr('src', $(this).attr('href'));
            return false;
        });
    });
    // menu
    $('.sub_menu_trigger').each(function(){
        var trigger = $(this);
        var fadeOutTimer;
        var th = trigger.outerHeight();
        var rel = trigger.find('a').attr('rel');
        $('body').append($(rel).remove());
        var sub = $(rel)
            .mouseenter(function(){ if(fadeOutTimer) clearTimeout(fadeOutTimer); })
            .mouseleave(function(){ sub.fadeOut('fast'); });
        trigger.hover(function(){
            var o = trigger.offset();
            sub.css({ left:o.left+'px', top:o.top+th+'px' }).fadeIn('fast');
        }, function(){
            fadeOutTimer = setTimeout(function(){ sub.fadeOut('fast') }, 350);
        });
    });
});
