var mb = 
{
	Init :
	{
		Menu : function()
		{
			$("#menu > UL > LI > A").each( function(i)
			{
				var a = $(this),
					submenu = a.next()[0];
				if( submenu )
				{
					submenu = $(submenu);
					a.parent().mouseenter( function()
					{
						a.addClass("selected");
						submenu.stop();
						submenu.height("inherit");
						submenu.slideDown(100);
					});
					a.parent().mouseleave( function()
					{ 
						a.removeClass("selected");
						submenu.slideUp(100);
					});
				}
			});
		},
		
		Custom : function()
		{
			if( typeof(custom_scripts) != "undefined" && custom_scripts.length != undefined )
				for(var i=0; i<custom_scripts.length; i++)
					custom_scripts[i]();
		}
	},
	
	Forms : 
	{
		EMAIL : /\w{1,}[@][\w\-]{1,}([.]([\w\-]{2,})){1,3}$/,
		DATETIME : /^(0[1-9]|[12]\d|3[01])\-(0[1-9]|1[0-2])\-(2\d\d\d) ([01]\d|2[0-3]):([0-5]\d)/,
		
		ChangeStatus : function(o, b)
		{
			if(b)
			{
				$(o).removeClass("error");
				return true;
			}
			
			$(o).addClass("error");
			return false
		},
		
		Check : function(form)
		{
			var ok = true;
			$("INPUT[type=text], INPUT[type=password], INPUT[type=file], TEXTAREA, SELECT", form).each(function(i)
			{
				var this_ok = true;
				
				// ¿Obligatorio?
				if(this.className.indexOf("_req_") > -1)
					this_ok = !( (/^\s*$/).test(this.value) );
				
				// Comprueba email
				if(this_ok && this.className.indexOf("_email_") > -1)
					this_ok = mb.Forms.EMAIL.test(this.value);
				
				// Comprueba fecha y hora
				if(this.className.indexOf("_date_") > -1)
					this_ok = mb.Forms.DATETIME.test(this.value);
				
				// Campo de texto que con un valor por defecto que desaparece al clicar
				if(this_ok && this.className.indexOf("_toggle_") > -1 && typeof(this.defaultValue) != "undefined")
					this_ok = (this.value != this.defaultValue);
				
				if( !mb.Forms.ChangeStatus(this, this_ok) )
					ok = false;
			});
			
			return ok;
		},
		
		ToggleTextInput : function(input, text, format)
		{
			input = $(input);
			input[0].defaultValue = text;
			
			input.focus( function(e) { if(this.value==text) this.value = ""; } );
			input.blur ( function(e)
			{
				if( (/^\s*$/).test(this.value) )
					this.value = text;
				
				if( format !== false )
				{
					if(this.value != this.defaultValue)
						$(this).addClass("notempty");
					else
						$(this).removeClass("notempty");
				}
			} );
			
			return input;
		}
	},
	
	Article : 
	{
		id : 0
	},
	
	Modules : 
	{
		Search :
		{
			VALUE : "Buscar en Madrid-Barcelona.com",
			
			Init : function()
			{
				new mb.Forms.ToggleTextInput( "#mod-buscador-search", mb.Modules.Search.VALUE );
			}
		}
	}
}
