var flyout = {

    activetli: null,
    timerhandle: null,
    timerhandle2: null,

    show: function(topli) {
        this.cleartimer();
        if (this.activetli != null) {
            this.hide(this.activetli);
        }
        this.activetli = topli;
        topli.addClass('mover');
    },

    hide: function(topli) {
        topli.removeClass('mover');
    },
    starttimeout: function() {
        this.timerhandle = window.setTimeout(function() { flyout.ontimeout(); }, 300)
    },
    ontimeout: function() {
        this.hide(this.activetli);
        this.activetli = null;
    },

    cleartimer: function() {
        window.clearTimeout(this.timerhandle);
    },

    delay: function(f, t) {
        this.abort();
        this.timerhandle2 = window.setTimeout(function() { f(); flyout.timerhandle2 = null; }, t);
    },
    abort: function() {
        if (this.timerhandle2 != null) {
            window.clearTimeout(this.timerhandle2);
            this.timerhandle2 = null;
        }
    },
    rdy: function() {

        // get submenus
        var submenus = $('#flyOutMenu .submenu');
        var topli = $('#flyOutMenu > li');
        topli.mouseover(function() {
            flyout.show($(this));
        });

        topli.mouseout(function() {
            flyout.starttimeout();
        });

        var topa = $('#flyOutMenu > li > a');
        topa.focus(function() {
            flyout.abort();
            flyout.show($(this).parent());
        });
        topa.blur(
        function() {
            var target = $(this);
            flyout.delay(
            function() {
                flyout.hide(target.parent());
            }, 10
        );
        }
    );
        var suba = $('#flyOutMenu > li > ul > li > a');
        suba.focus(function() {
            flyout.abort();
        });
        suba.blur(
        function() {
            var target = $(this);
            flyout.delay(
                function() {
                    flyout.hide(target.parent().parent().parent());
                }, 10
            );
        }
    );
    }
};

$(document).ready(flyout.rdy);
