window.addEvent('domready', function() {	
	
	var mainmenu  = new MainMenu();
	var openlogin = new OpenLogin();
	
});


//window.addEvent('load', function() {	});






	/*********************************************************************************************/
	
	
	
	
	
	

var MainMenu = new Class({
	
	initialize: function(){
        
        if (!$$('.mainmenu')) return;
    	
    	
    	/*this.menus = $$('.menu');
    	this.menus.each(function(menu) {
			menu.hide();
    	});
    	*/
    	
    	
    	this.mainlis = $$('.mainmenu')[0].getChildren('li');
    	
    	
    	
    	this.mainlis.each(function(li) {
					
					this._killHref(li);
									
					li.menu = li.getElement('ul.menu');
					
					li.menu.h = li.menu.getCoordinates().height-26;
					//console.log("li.menu.h "+li.menu.h);
					li.menu.hide();
					
					li.slide = new Fx.Tween(li.menu, {'transition': 'quad:out', 'duration':300});
				
					li.getFirst().addEvent('mouseenter', function(e){
						e.stop();
						//this.alllis.each(function(b) {b.removeClass('active')});
						//li.addClass('active');
						
						if((this.actualli != undefined)&&(this.actualli!=li)) this._hideMenu(this.actualli);
						this._showMenu(li);
						
						this.actualli = li;
						
					}.bind(this));
					
					li.addEvent('mouseleave', function(e){
						e.stop();
						this._hideMenu(li);
					}.bind(this));
				
	
			}.bind(this));	

        
    }, //end constructor
	 
	 
	
	 
	_showMenu : function(li){
		li.menu.show();
		li.slide.cancel();
		li.slide.start('height',0, li.menu.h);
		li.getFirst().setStyle('background-position',' -160px bottom');
		
	},
	
	_hideMenu : function(li){
		li.menu.hide();
		li.getFirst().setStyle('background-position','0px bottom');
		li.slide.cancel();
		/*li.slide.start('height', li.menu.h, 0);*/
	},
	
	_killHref : function(li){
		li.getFirst().set('href', 'javascript:void(0)');
	},	
	
	_closeMe : function(){
		
				
	}	// end methods	
	 
	 
	 
	 
});// end class


   /*********************************************************************************************/




var OpenLogin = new Class({
	
	initialize: function(){
        
        if (!$$('.login')) return;

    	this.btn = $$('.private')[0];
		this.drawer = $('wlpeLogin');
    	this.fx = new Fx.Tween(this.drawer, {'transition': 'quad:out', 'duration':200});
    	this.drawer_h = this.drawer.getCoordinates().height-29;
    	
    	if ($$('.wlpeMessage').length == 0){
    		this.drawer.setStyle('height', '0px');
    		this.isopen = false;
    	}else{
    		this.isopen = true;	
    		this.btn.setStyle('background-position',' -160px bottom');
    	}
    	this.btn.addEvent('click', function(e){
			e.stop();
			
			if (this.isopen == false){
				this.drawer.show();
				this.fx.start('height',0, this.drawer_h);
				this.isopen = true;
				this.btn.setStyle('background-position',' -160px bottom');
				this.drawer.setStyle('padding-bottom',' 18px');
			}
			else{
				this.drawer.hide();
				this.fx.start('height', this.drawer_h,0);
				this.isopen = false;
				this.btn.setStyle('background-position',' 0px bottom');
				this.drawer.setStyle('padding-bottom',' 0px');
			}
			
		}.bind(this));
		    
    }
	 
});// end class





/*****************************************************************************************************/




/* 
var MainMenu = new Class({
	
	initialize: function(){
        
        if (!$('mainmenu')) return;
        
        this.actualul = null;
        this.actualdrawer = null;
        this.allbtns = [];
        this.rows = $('mainmenus').getElements('.mainmenu');
		var id = 0;
		this.rows.each(function(row) {
			id++;
			row.drawer = new Element('div', {
			    'class': 'drawer',
			    'id':'drawer'+id
			});
			
			row.drawer.inject(row, 'after');
			
			this.mainbtns =  row.getElements('.level1');
				
			this.allbtns.combine(this.mainbtns);
			
			this.mainbtns.each(function(btn) {
				
				btn.ul = btn.getElement('ul');
							
				if (btn.ul != null) {
					
					var hasactive = btn.ul.getElement('.active');

					if (hasactive != null){
						this.actualdrawer = row.drawer;
						this.actualul = btn.ul;
					}else{
						btn.ul.setStyle('display', 'none');
					}
					
					row.drawer.grab(btn.ul);
					
					btn.a = btn.getElement('a');
					this.killHref(btn.a);				
					
					row.drawer.slide = new Fx.Tween(row.drawer, {'transition': 'quad:out', 'duration':200});
				
					btn.a.addEvent('click', function(e){
						
						this.allbtns.each(function(b) {b.removeClass('active')});
						btn.addClass('active');
						if (this.actualdrawer != row.drawer) {
							e.stop();	
							btn.ul.setStyle('display', '');
							var h = btn.ul.getCoordinates().height;
							if (this.actualdrawer) this.actualdrawer.slide.start('height',0);
							row.drawer.slide.start('height',0, h);	
							
						}

						if (this.actualul != null) {
							this.actualul.setStyle('display', 'none');
						}
							
						btn.ul.setStyle('display', '');
						
						this.actualul = btn.ul;
						this.actualdrawer = row.drawer;
						
					}.bind(this));
				}
	
			}.bind(this));	
			
			
		
		}.bind(this));
		
	 }, //end constructor
	 
	 
	
	 
	 killHref : function(e){
		e.set('href', 'javascript:void(0)');
	},
	
	
	
	closeMe : function(){
		
				
	}	// end methods	
	 
	 
	 
	 
});// end class




*/






