Ext.menu.Menubar = function(config){
	Ext.applyIf(config, {
		plain: true,
		cls: ""
	});
    Ext.menu.Menubar.superclass.constructor.call(this, config);
    this.cls += " x-menubar";
    if (this.orientation == "vertical") {
	    this.subMenuAlign = "tl-tr?";
	    this.cls += " x-vertical-menubar";
    } else {
    	this.subMenuAlign = "tl-bl?";
	    this.cls += " x-horizontal-menubar";
    }
};

Ext.extend(Ext.menu.Menubar, Ext.menu.Menu, {
    minWidth : 120,
    shadow : false,
    orientation: "horizontal",

	hide: function(){
        if(this.activeItem){
            this.activeItem.deactivate();
         delete this.activeItem;
        }
	},

    onClick : function(e){
    	if (this.activeItem) {
            this.activeItem.deactivate();
            delete this.activeItem;
    	}
    	else {
	        var t;
	        if(t = this.findTargetItem(e)){
	            if(t.canActivate && !t.disabled){
	                this.setActiveItem(t, true);
	            }
	        }
	        this.fireEvent("click", this, e, t);
	    }
    },

    onMouseOver : function(e){
    	if (this.activeItem) {
	        var t;
	        if(t = this.findTargetItem(e)){
	            if(t.canActivate && !t.disabled){
	                this.setActiveItem(t, true);
	            }
	        }
	        this.fireEvent("mouseover", this, e, t);
	    }
    },

    onMouseOut : function(e){}
});

function constructMenu(e, clickHandler)
{
	var items = [ ];

	Ext.get(e).select('>li').each( function()
	{
		var html = this.dom.innerHTML;
		//check for separator
		if(html == "")
		{
			var currentItem = '-';
		}
		else
		{
			//normal menu link
			var link = this.child('a:first', true);

			//check for icon
			try{
				var image = this.child('img:first', true);
				var icon = image.src;
			}
			catch(e)
			{
				var icon = "";
			}

			var currentItem =
			{
				text: link.innerHTML,
				cls: link.className,
				id: link.id,
				href: link.href,
				e: null,
				icon: icon,
				hrefTarget: link.target
			};
		}

		//check for sub menu.
		var s = this.select('>ul');
		if (s.elements.length)
		{
			currentItem.hrefTarget="";
			currentItem.href="";
			currentItem.menu = {items: constructMenu(s.item(0), clickHandler)};
		}
		items.push(currentItem);
	});

	return items;
}