﻿// function to reposition mega menu popup
function repositionPopUps(tabLi) {
    var containerwidth = 949;
    var popupList = $(tabLi).children('ul');
    var buttonposition = $(tabLi).position();
    var buttonwidth = $(tabLi).width();
    var popupleftposition;

    var popupwidth;
    switch (popupList.children('li').size()) // count number of sub menus
    {
        default:
            popupwidth = '180px';
            break;
    }
    popupList.css('width', popupwidth);
    popupList.children('li').css('width', '180px');

    var childwidth = popupList.width();
}

// Mega Menu jquery code
$(document).ready(function() {
    // change the class of the anchor tag when the user is hovering over the sub mega menu
    $('#megamenu ul.AspNet-MegaMenu ul').mouseenter(
        function() {
            $(this).prev('a').addClass("megamenuNavHover");
        }).mouseleave(function() {
            $(this).prev('a').removeClass("megamenuNavHover");
        });


    $('#megamenu ul.AspNet-MegaMenu > li > a').mouseenter(
        function() {
            $(this).addClass("megamenuNavHover");
        }).mouseleave(function() {
            $(this).removeClass("megamenuNavHover");
        });



    // set the style for current category
    $('#megamenu ul.AspNet-MegaMenu > li.AspNet-MegaMenu-Selected > a').addClass('megamenuNavSelected');
    $('#megamenu ul.AspNet-MegaMenu > li.AspNet-MegaMenu-ChildSelected > a').addClass('megamenuNavSelected');

    // dynamically reposition child popups when page loads // Fix IE 6 repositioning
    $('#megamenu ul.AspNet-MegaMenu > li').each(
            function() {
                repositionPopUps(this);
            }
        );

    // show popup on the hover of a tab item
    $('#megamenu ul.AspNet-MegaMenu > li').mouseenter(
              function() {
                  $(this).children('ul').css('visibility', 'visible');
                  $(this).children('ul').children('li').children('ul').css('visibility', 'visible');

              }).mouseleave(function() {
                  $(this).children('ul').children('li').children('ul').css('visibility', 'hidden');
                  $(this).children('ul').css('visibility', 'hidden');
              }
            );

    //    $('#megamenu .AspNet-MegaMenu > li > ul').masonry({
    //        singleMode: true,
    //        itemSelector: '> li'
    //    });
});
         


		 
