FM.MenuBar= function(element, grid) {
	this._menuBar= element;
	this.Grid= grid;
	this._glow= null;
	
	this.ms_btn_bg= "#C8C8C8";
	this.ms_btn_border= "gray";
	
	this.initialize();
}

FM.MenuBar.prototype= {

	dispose: function() {
		this.detachDocumentHandlers();
		$clearHandlers(this._menuBar);
	},
	
	initialize : function() {
		$addHandlers(this._menuBar, {
			'click': this._onClick,
			'mouseover': this._onOver,
			'mouseout': this._onOut
		}, this);
	},
	
	getSpan : function(o) {
		if (o.tagName == "IMG" || o.tagName == "LABEL") o= o.parentNode;
		if (o.tagName == "SPAN") return o;
		return null;
	},
	
	_onClick : function(e) {
		var o= this.getSpan(e.target);
		if (!o) return;
		if (o.className == "mnu mnuDD") {
			this.toggleMenu(o);
		} else {
			var act= o.getAttribute('action');
			if (act) window.eval(act);
		}
	},
	
	_onOver : function(e) {
		var o= this.getSpan(e.target);
		if (o && this._glow != o) {
			this._onOut();
			o.style.backgroundColor= this.ms_btn_bg;
			//o.style.borderColor= this.ms_btn_border;
			o.style.borderTopColor= "#F2F5F9";
			o.style.borderRightColor= "#B0B0B0";
			o.style.borderLeftColor= "#F2F5F9";

			this._glow= o;
		}
	},
	
	_onOut : function(e) {
		if (this._glow) {
			this._glow.style.backgroundColor= "";
			this._glow.style.borderColor= "";
			this._glow= null;
		}
	},
	
	toggleMenu : function(mnu) {
		var o= mnu.nextSibling;
		o.style.left= getAbsoluteLeft(mnu) + "px";
		o.style.top= getAbsoluteTop(mnu, 24) + "px";
		o.style.display= "block";
		
		FM._ResourceLoader.StartTransitionalEffect(o, 20, 10);
		
		this._activeMenu= o;
		this.documentMouseUpHnd= Function.createDelegate(this, this.documentMouseUp);
		$addHandler(window.document, 'mouseup', this.documentMouseUpHnd);
	},
	
	detachDocumentHandlers : function() {
		if (this.documentMouseUpHnd) {
			$removeHandler(window.document, 'mouseup', this.documentMouseUpHnd);
			this.documentMouseUpHnd= null;
		}
	},
	
	documentMouseUp : function(e) {
		this.detachDocumentHandlers();
		var o= this._activeMenu;
		o.style.display= "none";
		this._activeMenu= null;
	},
	
	popupToggle : function(b) {
	}

}

FM.MenuBar.registerClass('FM.MenuBar',  null, Sys.IDisposable);


Sys.Application.notifyScriptLoaded();