$(document).ready(function() {
	$(".box .box-toggle").bind('click', function(){boxToggle(this);return false;});
	$(".remove-btn").bind('click', function(){messageRemove(this);return false;});
	$(".cerrar-btn").bind('click', function(){messageRemove(this);return false;});
});

function boxToggle(that) {
	content_box = $(that).parent().parent().parent().find(".box-content");
	box = $(content_box).parent();
	if($(content_box).css("display") == "none") {
		$(content_box).slideDown(200, function(){
			$(box).removeClass("closed").addClass("open");
		});
	}
	else {
		$(content_box).slideUp(200, function(){
			$(box).removeClass("open").addClass("closed");
		});
	}
}

function messageRemove(that) {
	$(that).parent().slideUp(200);
}


/***************
jquery login
****************/
$(document).ready(function()
{
	$("#login_form").submit(function()
	{
		//remove all the class add the messagebox classes and start fading
		$("#msgbox").removeClass().addClass('messagebox').text('Validando....').fadeIn(1000);
		//check the username exists or not from ajax
		$.post("login.php",{ username:$('#username').val(),password:$('#password').val() } ,function(data)
        {
		  if(data=='yes') //if correct login detail
		  {
		  	$("#msgbox").fadeTo(200,0.1,function()  //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Logueando.....').addClass('messageboxok').fadeTo(900,1,
              function()
			  { 
			  	 //redirect to secure page
				 //document.location='secure.php';
				 document.location='dashboard.php';
			  });
			  
			});
		  }
		  else
		  {
          $("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
		  { 
		  //add message and change the class of the box and start fading
		  $(this).html('No se pudo loguear password incorrecto').addClass('messageboxerror').fadeTo(900,1);
		  //$(".messageboxerror").removeClass();
		  });	
		  }	
        });
 		return false; //not to post the  form physically
	});
	//now call the ajax also focus move from 
	$("#password").blur(function()
	{
		$("#login_form").trigger('submit');
	});
});
