function Menu(id, selectedIndex, autoPostBack, visible, menuItemCollection, target, frameID, contentPageId)
{
    this.MenuItemCollection = []; 
    this.Page = document;
    this.Visible = visible;
    this.Id = id;
    this.OuterTable = document.getElementById(this.Id);
//    this.InnerTable = document.getElementById(this.Id + "_InnerTbl");
	this.SelectedIndex = selectedIndex;
    this.ClassName = "Menu";
    this.AutoPostBack = autoPostBack;
    this.HasFilters = (document.body.filters ? true : false);
    this.Initialized = false;

    this.Target = target;
    this.FrameID = frameID;
    this.ContentPageId = contentPageId;

    if (menuItemCollection != null)
    {
        this.MenuItemCollection = menuItemCollection;
        if (this.Initialized == false)
        {
            this.Init();   
        }
    }
}

Menu.prototype.Init = function()
{
	var menu = this;
    if (this.MenuItemCollection == null) { return; }
    
    for (var i = 0; i < this.MenuItemCollection.length; i++)
	{
		menu.MenuItemCollection[i].Parent = this;
		menu.MenuItemCollection[i].Index = i;
    }
    
    this.OuterTable.style.visibility = (this.Visible == false) ? "none" : "visible";
    this.Initialized = true;
    
	try
	{
	    if (this.SelectedIndex > -1)
        {
            this.SetSelectedIndex(this.SelectedIndex);
        }	
	}
	catch(e) { }

};

Menu.prototype.SetSelectedIndex = function(newIndex) {
    var menu = this;
    if (this.MenuItemCollection == null) { return; }

    this.SelectedIndex = newIndex;

    for (var i = 0; i < this.MenuItemCollection.length; i++) {
        if (i == newIndex) {
            menu.MenuItemCollection[i].Selected();
            if (this.ContentPageId != "") {
                document.getElementById(this.ContentPageId).innerHTML = menu.MenuItemCollection[i].ContentPageName;
            }
        }
        else {
            menu.MenuItemCollection[i].Normal();
        }
    }
};

Menu.prototype.RegisterEvent = function(nodeElement, evname, func) 
{
	if( nodeElement.addEventListener ) 
	{
		nodeElement.addEventListener(evname, func, true);
	} 
	else if ( nodeElement.attachEvent ) 
	{
		nodeElement.attachEvent("on" + evname, func);
	}
};

Menu.prototype.RetrieveMenuItemById = function(id)
{
    for (var i = 0; i < this.MenuItemCollection.length; i++)
	{
		if (this.MenuItemCollection[i].Id == id)
		{
		    return this.MenuItemCollection[i];
		}
	}    
    return null;
};

