var  RollDownMenu=Class.create();

RollDownMenu.menus=[];
RollDownMenu.active=null;

RollDownMenu.newMenu=function(handler, menu){
	RollDownMenu.menus.push(new RollDownMenu(handler, menu));
};



RollDownMenu.prototype={
	initialize:function(handler, menu){
		this.menu=$(menu);
		this.handler=$(handler);
		Event.observe(handler, "mouseover", function(){this.timer=setTimeout(this.show.bind(this), 500)}.bindAsEventListener(this));
		Event.observe(handler, "mouseout", this.startTimer.bind(this));
		Event.observe(menu, "mouseover", this.show.bindAsEventListener(this));
		Event.observe(menu, "mouseout", this.startTimer.bind(this));
		this.menu.hide();
	},
	startTimer:function(){
		clearTimeout(this.timer);
		this.timer=setTimeout( function(){
			
			this.hide();
			
		
		}.bind(this), 300)
	},
	timer:null,
	effect:null,
	show:function(){
		
		clearTimeout(this.timer);
		if(this.effect){
			this.effect.cancel()
		}
		this.effect=Effect.Appear(this.menu, {duration:0.3});
		RollDownMenu.active=this;
	},
	hide:function(){
		if(this.effect){
			this.effect.cancel()
		}
		this.effect=Effect.Fade(this.menu, {duration:0.3});
		RollDownMenu.active=null;
	}
}
document.observe('dom:loaded', function () {
	RollDownMenu.newMenu("menu_button_news", "menu_news");
	RollDownMenu.newMenu("menu_button_discount", "menu_discount");

});