//menu.js
//richiede le librerie mootools

window.addEvent('domready', function(){
	
	var opened = false;
	//TODO: Calcolare in modo giusto come far apparire il menu downdrop
	$('menu').getElements('li').addEvents({
		'domready':function()
		{
			var cont = this.getElement('div');
			if(cont != null)
			{
				cont.fade(0.92);
			}
		},	
		'mouseover':function()
		{
			var cont = this.getElement('div');
			if(cont != null && !opened){
				opened = true;
				cont.tween('height','80px');
				
			}
		},
		'mouseout':function()
		{
			var cont = this.getElement('div');
			if(cont != null && opened){
				opened = false;
				cont.tween('height','0px');
			}
		}
	});

	/** Login **/
	
	var login = $('login');
	
	//Se e' presente il login 
	if(login != null)
	{
		
		var user = login.getElement('input[name=u]');
		var pass = login.getElement('input[name=p]');
		var backg = user.getStyle('background');
		
		var sub = login.getElement('input[type=submit]');
		
		user.addEvent('keydown',function(){
			this.setStyle('background',backg);
		});
		
		pass.addEvent('keydown',function(){
			this.setStyle('background',backg);
		});
		
		sub.addEvent('click',function(){
			var check = true;
			
			var str = user.get('value');
			if(str.length == 0){
				user.setStyle('background','red');
				check = false;
			}
			
			str = pass.get('value');
			if(str.length == 0){
				pass.setStyle('background','red');
				check = false;
			}
			
			if(!check){
				alert("Riempire i campi username e password!");
			}
			
			return check;
			
		});
		
		
	}
	/** Login **/

});

