function Menu_()
{
    this.Menu = Array();
    this.OpacitySpeed = 10;
    this.OpacityUnit = 20;


    this.Add = function(URL, Variable, Parent, Position, Name, PositionMargin)
    {
        this.Menu[Name] = Array();
        this.Menu[Name]["Name"] = Name;
        this.Menu[Name]["Parent"] = Parent;
        this.Menu[Name]["Object"] = null;
        this.Menu[Name]["Position"] = Position;
        this.Menu[Name]["PositionMargin"] = PositionMargin;
        this.Menu[Name]["URL"] = URL;
        this.Menu[Name]["Variable"] = Variable;
        this.Menu[Name]["Ajax"] = new XMLHTTPObject_();
        this.Menu[Name]["Visible"] = false;
        this.Menu[Name]["Loading"] = 0;
        this.Menu[Name]["Closing"] = false;
        this.Menu[Name]["Fixed"] = false;
        this.Menu[Name]["Opacity"] = 0;
        this.Menu[Name]["Timer"] = null;
        this.Menu[Name]["EventCounter"] = 0;
    }

    this.Remove = function(Name)
    {
        this.Menu[Name] = null;
    }

    this.OnMouseOver = function(Name)
    {
        if (this.Menu[Name]["Fixed"] || this.Menu[Name]["Closing"])
            return;

        if (!this.Menu[Name]["EventCounter"])
            this.Show(Name);
        this.Menu[Name]["EventCounter"]++;
    }

    this.OnMouseOut = function(Name)
    {
        if (this.Menu[Name]["Fixed"] || this.Menu[Name]["Closing"])
            return;

        this.Menu[Name]["EventCounter"]--;
        if (this.Menu[Name]["EventCounter"] < 0)
            this.Menu[Name]["EventCounter"] = 0;
        this.intervalTimer = setTimeout(this.Hide.bind(this, Array(Name)), 500);
        //window.setTimeout(this.Hide.bind(this, Array(Name)), 100);
    }

    this.Show = function(Name)
    {
        if (this.Menu[Name]["Loading"]==2)
        {
            if (typeof(this.Menu[Name]["Parent"])=="string")
                var Parent = document.getElementById(this.Menu[Name]["Parent"]);
            else
                Parent = this.Menu[Name]["Parent"];

            if (!Parent)
                return;

            var body = iecompattest();

            if(this.Menu[Name]["Position"] == "TopOpposite")
            {
                if (self.ieFixMode) {
                    var bar = document.getElementById('ChatBar');

                    if (bar) {
                        this.Menu[Name]['Object'].style.top = (body.scrollTop + body.clientHeight - bar.clientHeight) - (this.Menu[Name]['Object'].clientHeight)  + 'px';
                    }
                } else {
                    this.Menu[Name]["Object"].style.bottom = this.Menu[Name]["PositionMargin"] + 'px';
                }
            }
            else if (this.Menu[Name]["Position"] == "Static")
            {
                var is_safari;
                try { is_safari = (navigator.vendor && /Apple/i.test(navigator.vendor)) } catch(e) { is_safari = false; }
                this.Menu[Name]["Object"].style.top = (GetTop(Parent) + Parent.clientHeight - body.scrollTop)
                    + (is_safari ? 10 : 0) + 'px';
            }
            else
            {
                this.Menu[Name]["Object"].style.top = (this.Menu[Name]["PositionMargin"] - body.scrollTop) + 'px';
            }

            this.Menu[Name]["Object"].style.zIndex = 25000;
            if (this.Menu[Name]["Position"] == "Static")
                this.Menu[Name]["Object"].style.left = (General.GetElementPositionX(Parent)+Parent.clientWidth)+"px";
            else
                this.Menu[Name]["Object"].style.left = General.GetElementPositionX(Parent)+"px";
            this.Menu[Name]["Object"].style.display = "block";
            this.Menu[Name]["Object"].style.position = (self.ieFixMode) ? "absolute" : "fixed";
            this.Menu[Name]["Visible"] = true;

            this.Opacity(Name, 100);
        }
        else if (!this.Menu[Name]["Loading"])
            this.LoadContent(Name);
    }

    this.Hide = function(Name)
    {
        if ((this.Menu[Name]["Closing"] || this.Menu[Name]["EventCounter"]==0)&&(this.Menu[Name]["Visible"]))
        {
            if (!this.Menu[Name]["Opacity"])
            {
                var Parent;
                if (typeof(this.Menu[Name]["Parent"])=="string")
                        Parent = document.getElementById(this.Menu[Name]["Parent"]);
                else
                        Parent = this.Menu[Name]["Parent"];

                if (Parent && !this.Menu[Name]["Fixed"] && this.Menu[Name]["Position"] != "Static")
                        Parent.className = "ItemOut";

                this.Menu[Name]["Visible"] = false;
                this.Menu[Name]["Object"].style.display = "none";
                this.Menu[Name]["Closing"] = false;
                this.Menu[Name]["Fixed"] = false;
            }
            else if (this.Menu[Name]["Opacity"]==100)
                this.Opacity(Name, 0);
        }
    }

    this.DoShow = function(Name)
    {
        if (this.Menu[Name]["Closing"])
            return;

        this.Menu[Name]["Fixed"] = true;

        this.Show(Name);
    }

    this.DoHide = function(Name)
    {
        var Parent;
        if (typeof(this.Menu[Name]["Parent"])=="string")
            Parent = document.getElementById(this.Menu[Name]["Parent"]);
        else
            Parent = this.Menu[Name]["Parent"];

        this.Menu[Name]["Closing"] = true;

        if (Parent && !this.Menu[Name]["Fixed"] && this.Menu[Name]["Position"] != "Static")
            Parent.className = "ItemOut";

        this.Hide(Name);
    }

    this.Opacity = function(Name, Opacity)
    {
        if (this.Menu[Name]["Timer"])
            clearTimeout(this.Menu[Name]["Timer"]);

        if (this.Menu[Name]["Opacity"]<Opacity)
        {
            this.Menu[Name]["Opacity"] += this.OpacityUnit;
            this.Menu[Name]["Object"].style.opacity = this.Menu[Name]["Opacity"]/100;
            this.Menu[Name]["Object"].style.filter = "alpha(opacity="+this.Menu[Name]["Opacity"]+")";
            this.Menu[Name]["Timer"] = setTimeout(this.Opacity.bind(this, Array(Name, Opacity)), this.OpacitySpeed);
        }
        else if (this.Menu[Name]["Opacity"]>Opacity)
        {
            this.Menu[Name]["Opacity"] -= this.OpacityUnit;
            this.Menu[Name]["Object"].style.opacity = this.Menu[Name]["Opacity"]/100;
            this.Menu[Name]["Object"].style.filter = "alpha(opacity="+this.Menu[Name]["Opacity"]+")";
            this.Menu[Name]["Timer"] = setTimeout(this.Opacity.bind(this, Array(Name, Opacity)), this.OpacitySpeed);
            this.Hide(Name);
        }

        if (this.Menu[Name]["Opacity"]<=Opacity) {
            if (self.ieFixMode && this.Menu[Name]["Position"] == "TopOpposite") {
                var bar = document.getElementById('ChatBar');
                var body = iecompattest();
                if (bar) {
                    this.Menu[Name]['Object'].style.top = (body.scrollTop + body.clientHeight - bar.clientHeight) - (this.Menu[Name]['Object'].clientHeight)  + 'px';
                }
            }
        }
    }

    this.SetContent = function(Name, Data)
    {
        this.Menu[Name]["Object"] = document.createElement("div");
        this.Menu[Name]["Object"].style.display = "none";
//		this.Menu[Name]["Object"].style.height = "100px";
//		this.Menu[Name]["Object"].style.border = "1px #FFFFFF solid";
        this.Menu[Name]["Object"].style.position = "absolute";
        this.Menu[Name]["Object"].style.opacity = "0.0";
        this.Menu[Name]["Object"].style.filter = "alpha(opacity=0)";

        General.EventHandlerAdd(this.Menu[Name]["Object"], "mouseover", this.OnMouseOver.bind(this, Array(Name)));
        General.EventHandlerAdd(this.Menu[Name]["Object"], "mouseout", this.OnMouseOut.bind(this, Array(Name)));

        var Parent;
        if (typeof(this.Menu[Name]["Parent"])=="string")
            Parent = document.getElementById(this.Menu[Name]["Parent"]);
        else
            Parent = this.Menu[Name]["Parent"];

        if(Parent)
        {
            document.getElementById(this.Menu[Name]["Parent"]).appendChild(this.Menu[Name]["Object"]);
        }
        else
        {
            document.body.appendChild(this.Menu[Name]["Object"]);
        }

        General.DOMInsertHTML(this.Menu[Name]["Object"], Data);
        Form.Initialize();

        this.Menu[Name]["Loading"] = 2;
        this.Show(Name);
    }

    this.LoadContent = function(Name)
    {
        this.Menu[Name]["Loading"] = 1;
        this.Menu[Name]["Ajax"].CallBack(this, this.SetContent, Array(this.Menu[Name]["Name"]));
        this.Menu[Name]["Ajax"].Request("POST", this.Menu[Name]["URL"], this.Menu[Name]["Variable"]);
    }
}
