$(function(){		

	$('#admin-bar a#login').click(function(){

		$('#admin-bar div a#login').fadeOut("slow", function(){
			var container = $(this);
			var form = $("<div></div>").load('/session/login_form', "", function(response, status, xhr){
				container.replaceWith(form);
				form.fadeIn().animate({right: "600px"}, 700);
			});
			
		});
		
		return false;
	});
	
	$('#status')
	  .ajaxStart(function(){
        $.clearStatus();
          $(this).find('#animation').fadeIn();
        })
        .ajaxStop(function(){
          $(this).find('#animation').fadeOut();
        })
        .ajaxError(function(event, xhr, options){
          $(this).find('#animation').fadeOut(function(){

          //$(this).find('#message').text("An error occured");
          if ($('#status #message').text().length == 0) {
            $.displayStatus("An error occurred");

            console.log(" -- XHR --");
            console.log(xhr);

            console.log(" -- Options --");
            console.log(options);

            console.log(" -- Event -- ");
            console.log(event);

          }
        });
	  });

  $.extend({
    displayStatus: function(messageText){
      $('#admin-bar #status #message').text(messageText);
    },
    clearStatus: function(){
      $('#admin-bar #status #message').text('');
    }
  });

});