$(function () {
    // Slow down the mouseover image and menu layer effects as they're usability front end nightmares when layers flash open on your way to select a menu item, etc
    // This jquery file works in conjunction with /js/hoverintent.js
    var config = {
        sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)    
        interval: 100,  // number = milliseconds for onMouseOver polling interval    
        over: doOpen,   // function = onMouseOver callback (REQUIRED)    
        timeout: 0,   // number = milliseconds delay before onMouseOut    
        out: doClose    // function = onMouseOut callback (REQUIRED)    
    };

    function doOpen() {

        //$(this).addClass("hover");

        var currentImage = $(this);

        if ('gallery' != currentImage.attr('class')) {
            funcOverlay(currentImage);

            $(this).mouseout(function () {
                $('.prod-overlay').hide();
            });
        }
        if ('gallery' == currentImage.attr('class')) {
            funcOverlayGallery(currentImage);

            $(this).mouseout(function () {
                $('.gallery-overlay').hide();
            });
        }

        //funcOverlay(currentImage);

       
    }

    function doClose() {
        //$(this).removeClass("hover");
    }

    // Set the delay hoverIntent() routine on these page items
    $(".carousel-small-img img").hoverIntent(config);

    $(".product-img img").hoverIntent(config);

    $('.product-img img.gallery').hoverIntent(config);

    // Mega menu 
    // This jquery file works in conjunction with /js/hoverintent.js
    var configMegaMenu = {
        sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)    
        interval: 100,  // number = milliseconds for onMouseOver polling interval    
        over: doOpenMegaMenu,   // function = onMouseOver callback (REQUIRED)    
        timeout: 0,   // number = milliseconds delay before onMouseOut    
        out: doCloseMegaMenu    // function = onMouseOut callback (REQUIRED)    
    };

    function doOpenMegaMenu() {
       // alert('in here');
        var currentLi = $("#jqMdd li");
        var currentOffset = currentLi.offset();

        var submenu = $(".mdd-wrapper");

        submenu.css({
            position: 'absolute',
            top: currentOffset.top - 110
        }).show()

        //$(this).addClass("hoverX");
    }

    function doCloseMegaMenu() {
        //$(this).removeClass("hoverX");
    }

    // Set the delay hoverIntent() routine on the mega Menu
    $("#jqMdd li a").hoverIntent(configMegaMenu);

});
