jQuery.fn.extend(
{
    addNavigationLeft : function ()
    {
        $navigation = function (b)
        {
            var c = this;
            this.options = 
            {
                event : arguments[1] && arguments[1].event ? arguments[1].event : 0, effect : arguments[1] && arguments[1].effect ? arguments[1].effect : false, 
                activeSection : arguments[1] && arguments[1].activeSection ? arguments[1].activeSection : null, 
                callback : arguments[1] && arguments[1].callback ? arguments[1].callback : null
            };
            this.navigation = b;
            this.navigation.find("li").each(function ()
            {
                var e = $(this);
                if (e.find("> ul").length > 0) {
                    e.addClass("HasChild")
                }
                var d;
                e.bind(c.options.event, function (h)
                {
                    var g = null;
                    e.parent().find("li.Active").each(function ()
                    {
                        var l = $(this);
                        if (l.find("li.Active").length <= 0) {
                            g = l;
                        }
                    });
                    var i = false;
                    if (g != null && g.parent().parent().hasClass("Active") && g.html() != e.parent().parent().parent().find("> li.Active").html() && g.html() != e.html() || e.parent().find("> li.Active").length > 0) {
                        d = false
                    }
                    else {
                        d = true
                    }
                    try
                    {
                        if (c.options.effect && c.options.event == "click")
                        {
                            var f = setInterval(function ()
                            {
                                if (g != null && g.parent().parent().hasClass("Active") && g.html() != e.parent().parent().parent().find("> li.Active").html() && g.html() != e.html())
                                {
                                    if (!i)
                                    {
                                        i = true;
                                        if (g.find("> ul:first").length > 0)
                                        {
                                            g.find("> ul:first").slideUp(100, function ()
                                            {
                                                g.removeClass("Active");
                                                g = g.parent().parent();
                                                i = false;
                                            })
                                        }
                                        else {
                                            g.removeClass("Active");
                                            g = g.parent().parent();
                                            i = false;
                                        }
                                    }
                                }
                                else
                                {
                                    if (e.parent().find("> li.Active").length > 0 && !d)
                                    {
                                        clearInterval(f);
                                        if (e.parent().find("> li.Active").get(0) != e.get(0))
                                        {
                                            if (e.parent().find("> li.Active > ul:first").length > 0)
                                            {
                                                e.parent().find("> li.Active > ul:first").slideUp(100, 
                                                function ()
                                                {
                                                    e.parent().find("> li.Active").removeClass("Active");
                                                    d = true;

                                                })
                                            }
                                            else {
                                                e.parent().find("> li.Active").removeClass("Active");
                                                d = true;
                                            }
                                        }
                                    }
                                    else {
                                        d = true;
                                        clearInterval(f)
                                    }
                                }
                            }, 1)
                        }
                        else
                        {
                            while (g != null && g.parent().parent().hasClass("Active") && g.html() != e.parent().parent().parent().find("> li.Active").html() && g.html() != e.html()) {
                                g.find("> ul:first").hide();
                                g.removeClass("Active");
                                g = g.parent().parent()
                            }
                            e.parent().find("> li.Active > ul:first").hide();
                            e.parent().find("> li.Active").removeClass("Active")
                        }
                    }
                    catch (j) {}
                    if (c.options.event == "click")
                    {
                        if (!e.hasClass("Active"))
                        {
                            if (c.options.effect)
                            {
                                var k = setInterval(function ()
                                {
                                    if (d)
                                    {
                                        clearInterval(k);
                                        e.addClass("Active");
                                        if (e.find("> ul:first").length > 0) {
                                            e.find("> ul:first").slideDown("normal", function ()
                                            {
                                                d = false;
                                            })
                                        }
                                        else {
                                            d = false;
                                        }
                                    }
                                }, 1)
                            }
                            else {
                                e.addClass("Active");
                                e.find("> ul:first").show()
                            }
                        }
                        else
                        {
                            if (c.options.effect)
                            {
                                if (e.find("> ul:first").length > 0) {
                                    e.find("> ul:first").slideUp("normal", function ()
                                    {
                                        e.removeClass("Active")
                                    })
                                }
                                else {
                                    e.removeClass("Active")
                                }
                            }
                            else {
                                e.find("> ul:first").hide();
                                e.removeClass("Active")
                            }
                        }
                    }
                    else {
                        e.addClass("Active");
                        e.find("> ul:first").show()
                    }
                    if (typeof (e.find("> ul:first").css("position")) != "undefined" && e.find("> ul:first").css("position").match(/absolute|relative/))
                    {
                        if (e.offset().left + e.find("> ul:first").outerWidth() * 2 > $(window).width()) {
                            e.find("> ul:first").addClass("ToRight")
                        }
                    }
                    h.stopPropagation()
                })
            });
            $(document).bind(c.options.event, function (d) {});
            this.setActive = function ()
            {
                try
                {
                    this.activeSection = c.options.activeSection;
                    if (this.activeSection != null) {
                        var f = this.activeSection.replace(/[a-zA-Z]/g, "").toString().split("_")
                    }
                    var e = this.navigation.find("> li");
                    do {
                        e = e.eq(f[0] - 1);
                        e.addClass("Hilite");
                        e = e.find("ul:first > li");
                        f.splice(0, 1)
                    }
                    while (f.length > 0) {;
                    }
                }
                catch (d) {}
            };
            this.refresh = function (f)
            {
                var e = null;
                this.navigation.find("li.Active").each(function ()
                {
                    var i = $(this);
                    if (i.find("li.Active").length <= 0) {
                        e = i;
                    }
                });
                var g = false;
                try
                {
                    if (c.options.effect && f == "click")
                    {
                        var d = setInterval(function ()
                        {
                            if (e != null && e.hasClass("Active"))
                            {
                                if (!g)
                                {
                                    g = true;
                                    if (e.find("> ul:first").length > 0)
                                    {
                                        e.find("> ul:first").slideUp(100, function ()
                                        {
                                            e.removeClass("Active");
                                            e = e.parent().parent();
                                            g = false;
                                        })
                                    }
                                    else {
                                        e.removeClass("Active");
                                        e = e.parent().parent();
                                        g = false;
                                    }
                                }
                            }
                            else {
                                clearInterval(d)
                            }
                        }, 1)
                    }
                    else
                    {
                        while (e != null && e.hasClass("Active")) {
                            e.find("> ul:first").hide();
                            e.removeClass("Active");
                            e = e.parent().parent();
                        }
                    }
                }
                catch (h) {}
            };
            this.setActive();
            if (this.options.callback != null) {
                this.options.callback()
            }
        };
        var a = arguments[0];
        this.each(function ()
        {
            new $navigation($(this), a)
        })
    }
});

