var MenuState = { UNKNOWN: 0, ENABLED : 1, DISABLED : 2}
var MenuItemState = { UNKNOWN: 0, ACTIVE : 1, INACTIVE : 2}
var ContentState = { UNKNOWN: 0, SHOWN : 1, HIDDEN : 2}

var Menu = new Class({
    initialize: function(Element)
    {
    	this.Target = Element;
    	this.Items = new Array();
		this.CurState = MenuState.UNKNOWN;	
        this.LastActivatedItem = 0;
    },
    
    Enable: function() 
    {
		this.CurState = MenuState.ENABLED;
	    
	    // activate last actived menu item
		if(this.Items.length > 0)
		{
		    this.Items[this.LastActivatedItem].Activate();
		}
    },    

    Disable: function() 
    {
		this.CurState = MenuState.DISABLED;
  
   		// deactive all items in order to hide the contents related to them
   		for (var i=0, len=this.Items.length; i<len; ++i)
   		{
			this.Items[i].Deactivate();
		}		
    },
    
	Select: function(Item) 
	{	
   		this.LastActivatedItem = Item;
   		
   		for (var i=0, len=this.Items.length; i<len; ++i)
   		{
			if (i == Item){
				this.Items[i].Activate();
			}
			else{
				this.Items[i].Deactivate();
			}
		}
	},
	
	AddItem: function(Item) 
	{
		this.Items[this.Items.length] = Item;
	}
});

var MenuItem = new Class({
    initialize: function(Element)
    {
    	this.Target = Element;
		this.CurState = MenuItemState.UNKNOWN;  
    },
    
    Activate: function() 
	{	
        this.CurState = MenuItemState.ACTIVE;
	
        if (this.ChildMenu)
        {
            this.ChildMenu.Enable();
        }
        // we have content ourselves
        else if(this.Content)
        {
            this.Content.Show();
        }
	},

	Deactivate: function() 
	{
        this.CurState = MenuItemState.INACTIVE;

        if (this.ChildMenu)
        {
            this.ChildMenu.Disable()
        }
        // we have content ourselves
        else if(this.Content)
        {
            this.Content.Hide()
        }
	},

    // Set child menu
	SetChildMenu: function(Menu) {
		this.ChildMenu = Menu;
	},		

    // Set content
	SetContent: function(Content) {
		this.Content = Content;
	}	
});

var Content = new Class({
    initialize: function(Element)
    {
    	this.Target = Element;
		this.CurState = ContentState.UNKNOWN;      	
    },

	Show: function() 
	{
        this.CurState = ContentState.SHOWN;
        //
	},	

	Hide: function() 
	{
        this.CurState = ContentState.HIDDEN;
        //
   	}
});
