function MenuItem (parent, index, args)
{
	if (arguments.length)
	{
		this.instance = new MenuItemStruct (parent, this, index);
		this.state = 0;
		this.target = null;
		for (var i = 0; i < args.length; i++)
		{
			this[this.args[i]] = args[i];
		}
		if (this.target == null || this.target == "")
		{
			this.target = this.getRoot ().baseTarget;
		}
	}
}

MenuItem.menuInit ();

MenuItem.prototype.args = ['text', 'href', 'target', 'styleId', 'state', 'topOffset'];

MenuItem.prototype.addStyle = function ()
{
	var r = this.getRoot ();
	return r.addStyle.apply (r, arguments);
};

MenuItem.prototype.applyEvents = function (o)
{
	o.controller = this;
	o.onmouseover = function ()
	{
		this.controller.onRollOverEvent ();
	};
	o.onmouseout = function ()
	{
		this.controller.onRollOutEvent ();
	};
	o.onclick = function ()
	{
		this.controller.onClickEvent ();
	};
};

MenuItem.prototype.changeClass = function (s)
{
	this.div.className = this.getRoot ().styles[this.styleId][['fu', 'fv', 'nu', 'nv'][s]];
};

MenuItem.prototype.getHTML = function ()
{
	var p = document.createElement ('div');
	var o = document.createElement ('div');
		o.innerHTML = this.text;
		p.appendChild (o);
	this.getRoot ().div.appendChild (p);
	this.div = o;
	this.cdiv = p;
	this.applyEvents (o);
	this.changeClass (0);
};

MenuItem.prototype.onClickEvent = function ()
{
	if (this.state != 1)
	{
		this.setOn ();
	}
	if (this.href != "#" && this.href != null)
	{
		if (this.href.indexOf ('javascript:') == -1)
		{
			if (this.target == document)
			{
				location.href = this.href;
			}
			else
			{
				//window.open (this.href, this.getRoot ().baseTarget);
				parent.frames[this.getRoot ().baseTarget].location.href = this.href;
			}
		}
		else
		{
			eval (this.href.substr (11));
		}
	}
};

MenuItem.prototype.onRollOutEvent = function ()
{
	this.changeClass (this.state ? 2 : 0);
};

MenuItem.prototype.onRollOverEvent = function ()
{
	this.changeClass (this.state ? 3 : 1);
};

MenuItem.prototype.setOff = function ()
{
	this.changeClass (0);
	this.state = 0;
};

MenuItem.prototype.setOn = function ()
{
	this.changeClass (3);
	this.state = 1;
	for (var o, s = this.getSiblings (), i = 0; o = s[i]; i++)
	{
		o.setOff ();
	}
};

function Menu (div, basetarget)
{
	this.instance = new MenuItemStruct (null, this, 0);
	this.styles = new Array ();
	this.div = div;
	this.baseTarget = arguments.length == 1 ? document : basetarget;
}

Menu.prototype = new MenuItem ();

Menu.prototype.addStyle = function (a, b, c, d)
{
	return this.styles.push ({fu:a, fv:b, nu:c, nv:d}) - 1;
};

Menu.prototype.build = function ()
{
	this.div.innerHTML = '';
	for (var o, i = 0, a = this.getChildren (); o = a[i]; i++)
	{
		o.getHTML ();
	}
	for (var o, i = 0, r = this.getRoot (), a = this.getChildrenRec (); o = a[i]; i++)
	{
		if (o.state == 1)
		{
			while (o != r)
			{
				o.setOn ();
				o.changeClass (2);
				o = o.getParent ();
			}
			break;
		}
	}
};
