$(document).ready(function() {
    $('.menuItem .subMenu').prepend('<div class="menuShim"></div>');
    $(".menuItem .subMenu ul").find('li:first').addClass('first');
    $(".menuItem .subMenu ul").find('li:last').addClass('last');
    $(".menuItem:last").addClass('lastMenuItem');
    $(".menuItem").hoverIntent({
        sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)
        interval: 1,   // number = milliseconds for onMouseOver polling interval
        over: function() {
            var menu = $(this);
            var subMenu = menu.children(".subMenu");
            var menuImg = menu.find('a img');
            subMenu.show();
            subMenu.bind('mouseover', function() {
                var newsrc;
                var src = menuImg.attr('src');
                if (/-C.gif/.test(src)) {
                    newsrc = src.replace('-C.gif', '-X.gif');
                    menu.addClass("selected");
                } else {
                    newsrc = src.replace('-O.gif', '-X.gif');
                }
                menuImg.attr('src', newsrc);
            });
        },     // function = onMouseOver callback (required)
        timeout: 200,   // number = milliseconds delay before onMouseOut
        out: function() {
            var menu = $(this);
            menu.children(".subMenu").hide();
            var newsrc = menu.find('a img').attr('src').replace('-X.gif', '-O.gif');
            if (menu.hasClass("selected")) {
                newsrc = menu.find('a img').attr('src').replace('-X.gif', '-C.gif');
            }
            
            menu.find('a img').attr('src', newsrc);
        }       // function = onMouseOut callback (required)
    });

    $('.dropDownPanel').hoverIntent({
        sensitivity: 1,
        interval: 1,
        over: function() { $(this).find(".dropDownContent").fadeIn(); },
        timeout: 1,
        out: function() { $(this).find(".dropDownContent").fadeOut(); }
    });

    $('.quickView').hoverIntent({
        sensitivity: 1,
        interval: 1,
        over: function() { $(this).find(".quickViewLink").fadeIn(); },
        timeout: 500,
        out: function() { $(this).find(".quickViewLink").fadeOut(); }
    });
});
