﻿$.fn.TopMenu = function () {
    return this.each(function () {
        var el = $(this),
            links = $("a:not(li ul li a)", el),
            uls = $("ul li ul", el);

        var timer;

        links.mouseover(
            function () {
                el.find("li ul").not($(this).parent().find("ul")).hide();
                clearTimeout(timer);
                //$(this).stop(true, true).animate({ "color": "#E6E6E6" }, 300);
                //$(this).parent().find("ul").fadeIn(300);
                $(this).parent().find("ul").show();
            });

        links.mouseout(
            function () {
                var $this = $(this);

                if ($this.attr("class").indexOf("selected") == -1) {
                //    $(this).animate({ "color": "#333132" }, 500);
                }

                timer = setTimeout(function () {
                    //  $this.parent().find("ul").fadeOut(500);
                    $this.parent().find("ul").hide();
                }, 500);
            }
        );

        uls.find("li a").hover(function () {
            //$(this).stop(true, true).animate({ "color": "#E6E6E6" }, 300);
        }, function () {
            //$(this).animate({ "color": "#333132" }, 500);
        });

        uls.mouseover(function () {
            clearTimeout(timer);
        });

        uls.mouseout(function () {
            var ul = $(this);
            timer = setTimeout(function () {
                //  ul.fadeOut(500);
                ul.hide();
            }, 500);
        });





    });

}
