var QMenu = new Class({
	options:{
		overshow:true,
		delay:500
	},
	initialize:function(base,menu,options){
		this.setOptions(options);
		this.base = $(base);
		this.menu = $(menu);
		if(this.options.overshow){
			this.base.addEvent('mouseover',this.show.bind(this));
		}else{
			this.base.addEvent('click',this.show.bind(this));
		}
	},
	show:function(e){
		if(!this.showing){
			this.showing=true;
			if(!this.moreOnce){
				this.moreOnce = true;
				this.fireEvent('firstshow',{target:this.menu,type:'first'});

				if(this.options.overshow){
					this.menu.addEvents({
						'mouseover':function(){
							this.overmenu=true;
						}.bind(this),
						'mouseout':function(){
							this.overmenu=false;
							this.hide.delay(this.options.delay,this);
						}.bind(this)
					});
					this.base.addEvent('mouseout',function(){
						this.overbase=false;
						this.hide.delay(this.options.delay,this);
					}.bind(this));
				}

			}
			this.menu.setStyle('display','');
			this.fireEvent('show',{target:this.menu,type:'show'});
		}
		if(this.options.overshow){
			this.overbase = true;
		}
	},
	hide:function(){
		if(this.showing){
			if(this.options.overshow && (this.overbase || this.overmenu)){
				return;
			}

			this.showing=false;
			this.menu.setStyle('display','none');
			this.fireEvent('hide',{target:this.menu,type:'hide'});
		}
	}
});
QMenu.implement(new Events,new Options);