﻿
$(document).ready(function () {
    var nm;
    var cm;
    var closeMenuInt;
    function closeCurrentMenu(cb) {
        if (cm != null) {
            cm.slideUp("fast", function () {
                if (cm!=null)
                    cm.removeClass("open");
                cm = null;
                if (cb != null)
                    cb();

            });

        } else {
            if (cb != null)
                cb();
        }
    }



    $("ul.menu").each(function () {
        var w = 0;
        $(this).find("> li").each(function () {
            w += $(this).outerWidth(true);

            $(this).find("> a").mouseenter(function () {
                nm = $(this).next()
                if (nm.hasClass("open")) {
                    return;

                }
                closeCurrentMenu(function () {
                    cm = nm
                    cm.slideDown("fast", function () {
                        cm.addClass("open").mouseenter(function () {
                            $(this).mouseleave(function () {
                                closeCurrentMenu(null);
                            });
                        })

                    })
                });
            });

        });
        var ml = $(this).parent().width() - w;
        $(this).css("margin-left", (ml / 2) + "px");
    });

});
$(window).load(function () {
    $("ul.menu").each(function () {
        var w = 0;
        $(this).find("> li").each(function () {
            w += $(this).outerWidth(true);

        });
        var ml = $(this).parent().width() - w;
        $(this).css("margin-left", (ml / 2) + "px");
    });
});


$(document).ready(function () { $.ga.load(GoogleTrackingId); });
