/**
 *	A sub-menu is a menu item that opens a sub-menu to show 
 *	any child documents that it has.
 */
SubMenu.prototype = new MenuItem();

/**
 *	The popup menu that shows its contents.
 */
SubMenu.prototype.menu = null;

/**
 *	The parent menu.
 */
SubMenu.prototype.parent = null;

/**
 *	Constructor.
 */
function SubMenu(name, title,href, width) {
	this.title = title;
	this.href = href;
	this.menu = new PopupMenu(name,width);
	this.menu.exclusive = false;
	this.menu.displayClass = "SubMenu";
	
}


SubMenu.prototype.addItem = function(menuItem) {
	this.menu.addItem(menuItem);
}

SubMenu.prototype.show = function() {
	//	 Calculate the appropriate position.
	var i = this.parent.indexOf(this);
	
	var x_pos = this.parent.locationX + this.parent.width+10;
	var y_pos = this.parent.locationY + i * this.parent.itemHeight;
	
	this.parent.show();
	
	//	Supress the auto-hide of the parent for now.
	this.parent.over = 1;	
	this.menu.show(x_pos,y_pos);
}

SubMenu.prototype.toHtml = function() {
	var v = "<div class=\""+this.displayClass+"\">";
	
	v += "<a href=\""+this.href+"\" onmouseover=\""+this.menu.name+".show();\">"+this.title + "</a></div>";
	
	//	Make sure the sub-menu is initialized.
	this.menu.initialize();
	
	return v;
}

