﻿$(document).ready(function() {
    var config = {
        sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
        interval: 100, // number = milliseconds for onMouseOver polling interval    
        over: ShowSubMenu, // function = onMouseOver callback (REQUIRED)    
        timeout: 200, // number = milliseconds delay before onMouseOut    
        out: HideSubMenu // function = onMouseOut callback (REQUIRED)    
    };
    $("li.productCategory").hoverIntent(config);
});

function ShowSubMenu() {
    var subMenu = $(this).find("div.subCatContainer");
    if (subMenu != null) {
        // subMenu.fadeIn("fast");
        subMenu.show();
        var pos = $(this).position(); // Get vertical position of the submenu
        subMenu.css("top", pos.top);
        SetListHeight(subMenu); // Set equal height of all the ul lists in the submenu
    }
}

function HideSubMenu() {
    var subMenu = $(this).find("div.subCatContainer");
    // subMenu.fadeOut("fast");
    subMenu.hide();
}

function SetListHeight(subMenu) {
    var maxHeight = 0;

    // Get alle the lists in the current submenu
    var lists = $(subMenu).find("> ul");

    // Get the height of the longest list
    for (var i = 0, len = lists.length; i < len; ++i) {
        if ($(lists[i]).height() > maxHeight) {
            maxHeight = $(lists[i]).height();
        }
    }

    // Set the height of the lists equal to the maxHeight variable
    for (var i = 0, len = lists.length; i < len; ++i) {
        $(lists[i]).height(maxHeight);
    }
}
