//
// (c) 2007 webActive
//

Interface.MenuItem = Broadcaster.extend(
{
	initialize: function(domElement, parentContainer)
	{
		this.parent();
		this.domElement = domElement;
		this.parentContainer = parentContainer;
		this.childContainer = null;

		this.setupMenuItem();
	},

	setupMenuItem: function()
	{
		this.domElement.onmouseover = this.onRollOver.bind(this);
		this.domElement.onmouseout = this.onRollOut.bind(this);
		this.domElement.onmouseup = this.onRelease.bind(this);
		
		var domItems = this.domElement.getElementsByTagName('ul');

		if (domItems.length > 0)
		{
			this.childContainer = new Interface.MenuContainer(domItems[0], this);
		}
	},
	
	onRollOver: function()
	{
		var domItems = this.domElement.getElementsByTagName('a');
		domItems[0].className = 'rollover';

		if (this.childContainer != undefined)
			this.childContainer.onRollOver();
		
		this.parentContainer.hideChildContainers();
		
		this.broadcastMessage('onRollOver');
	},
	
	onRollOut: function()
	{
		var domItems = this.domElement.getElementsByTagName('a');
		domItems[0].className = null;

		if (this.childContainer != undefined)
			this.childContainer.onRollOut();
		this.broadcastMessage('onRollOut');
	},
	
	onRelease: function()
	{
		this.broadcastMessage('onRelease');
	}
});