var Menu = Class.create({
	initialize:function(element,eventName){
		this.container = element;
		this.eventName = eventName;
		this.itemsList = element.childElements();
		this.elShown = null;
		this.isSelected = false;
		
		var obj 	   = this;
		this.itemsList.each(function(item,index){
			if(item.select('ul')[0]){
				item.down('a').firstChild.data += ' +'; 
				var sousMenu = new Menu(item.select('ul')[0],obj.eventName);
				item.child = sousMenu;
				item.father= obj;
				sousMenu.isSelected = (sousMenu.container.select('li.selected')!='');
				sousMenu.forceHide();
				item.observe(obj.eventName,obj.prepare.bindAsEventListener(item));
			}else{
				item.observe('click',obj.stopEv.bindAsEventListener(item));
			}
		});
	},
	
	prepare:function(event){
		// /!\ le scope est sur le "li"
		Event.stop(event);
		
		var show = true;
		
		if(this.father.elShown){
			this.father.elShown.hide();
			var liParent = this.father.elShown.container.parentNode;
			setTimeout(function(){
							if(!liParent.hasClassName('selected'))
							{
								liParent.addClassName('unselected');
								//liParent.removeClassName('selected');
							}
								},200);
			if(this.father.elShown == this.child){
				this.father.elShown = null;
				show = false;
			}
		}
		
		if(show){
			this.child.show();
			//this.addClassName('selected');
			this.removeClassName('unselected');
			this.father.elShown = this.child;
		}
	},
	
	stopEv:function(event){
		Event.stop(event);
		document.location.href = this.select('a')[0].href;
	},
	hide:function(){
		Effect.BlindUp(this.container,{duration:0.2,queue:'end'});
	},
	show:function(){
		Effect.BlindDown(this.container,{duration:0.2,queue:'end'});
	},
	forceHide:function(){
		if(!this.isSelected){
			this.container.hide();
		}
	},
	openSelected:function(){
		
	}	
	
});


Event.observe(window,'load',function(){
									  var menu = new Menu($('menu'),'click');
									  menu.openSelected();
									 });
