$(document).ready(function(){
    var hash = window.location.hash.toString();
    hash = hash.split('#')[1];

    if(hash == 'failed'){
        $('#login').hide();
        $('#fail').show();
        $('#fail p:first').text('The username/password combination is incorrect');
    }

   $('#forgot-pass').click(function(){
        $('#login').fadeOut('fast',function(){
            $('#forgot').fadeIn('fast');
        });
        return false;
   });

   $('#cancel-forgot').click(function(){
        $('#forgot').fadeOut('fast',function(){
            $('#login').fadeIn('fast');
        });
        return false;
   });

   $('#forgot').submit(function(){
        $.post('/ajax/forgot.php', { email: $('#forgotpass').val() }, function(data){
            
            $('#forgotpass').val('');
            if(data == 'Success'){
                $('#forgot').fadeOut('fast', function(){
                    $('#success').fadeIn('fast');
                });
            } else {
                $('#forgot').fadeOut('fast', function(){
                    $('#fail p:first').text('We can\'t seem to find your email address in our database!');
                    $('#fail').fadeIn('fast');
                });
               
            }
        });
        return false;
   });

   $('.back').click(function(){
       $('#fail, #success').fadeOut('fast', function(){
           $('#login').fadeIn('fast');
       });
       return false;
   });

});