function delegate(o, m){ return function() { return m.call(o) } }
jQuery.noData = {};

var menu_open = false;
var menu_anim = false;

function triggerMenu( aux, elseAux )
{
	//$(aux + "_m").trigger("click");
	/*
	if( jQuery.inArray(aux, ["#"]) >= 0 )
	{
		$(aux + "_m").trigger("click");
	}
	else if( elseAux )
	{
		$(elseAux + "_m").trigger("click");
	}*/
}

function openMenu() 
{
	if( !menu_anim && !menu_open)
	{
		var $tab = $('#menu_left .menu #menu_tab');
		var $nav = $('#menu_left .menu nav');
		menu_anim = true;
		
		$nav.show();
		$tab.stop(true).hide()// "clip", {}, 100, function()
		//{
			$nav.children("div").each(function(i) {
				$(this).stop(true).delay(80 * i).show( "clip", {}, 300, function(){
					if( i == ($nav.children().length - 1) )
					{
						menu_anim = false;
						menu_open = true;
					}
				});
			});
		//});
	}
};
function closeMenu() 
{
	if( !menu_anim && menu_open)
	{
		var $tab = $('#menu_left .menu #menu_tab');
		var $nav = $('#menu_left .menu nav');
		menu_anim = true;
		
		$nav.children("div").each(function(i) {
			$(this).stop(true).delay(80 * (($nav.children().length - 1) - i)).hide( "clip", {}, 300, function(){
				if( i == 0 )
				{
					$tab.stop(true).show()// "clip", {}, 100, function(){
						$nav.hide();
						menu_anim = false
						menu_open = false;
					//});
				}
			});
		});
	}
}
$(document).ready(function()
{
	$(".noscript").removeClass("noscript");
	
	/** MENU **/
	$('#menu_left .menu').hover(openMenu, closeMenu);
	
	/** LOGIN **/
	$('#login_formlog_show').click(function(){
		$('#login_formlog').stop(true).toggle("fast");	
		return false;
	});
	$('#login_formlog form').submit(function() 
	{
		$.post("/servicios/formulario_acceso", 
		{ "email": $('#login_formlog form input[name="email"]').val(), "password": $('#login_formlog form input[name="password"]').val() },
		function(data)
		{
			if(data.error)
			{
				$('#login_formlog form .mensaje').show().html(data.error);
			}
		},
		"json");
		return false;
	});
	
	//triggerMenu( window.location.hash, "#Home" );
	
	/*$(window).hashchange( function()
	{
		triggerMenu( window.location.hash );
	});*/
});
