$(document).ready( function() {
  // Observe an imput and toggle its value
  $(':input.toggle').each( function() {
  	var value = $(this).val();

  	$(this).focus( function() {
  		if ($(this).val() == value) {
  			$(this).val('');
  		}
  	});

  	$(this).blur( function() {
  		if ($(this).val() == '') {
  			$(this).val(value);
  		}
  	});
  });


  // Observe the temp-password field and replace it with a input[type=password] 
  // All this so IE can swap type on an input properly
  $(':input[name=temp-password]').focus( function() {
  	var temp = $(this);

  	// hide the temp text field
  	temp.attr('disabled', true);
  	temp.hide();

  	// create a new password text field
  	var el = document.createElement('input');

  	// set the attributes
  	$(el).attr({
  		type:'password',
  		name:'apassword',
  		'class':'text'
  	});

  	// insert after the temp-password field and focus it
  	temp.after(el);
  	$(el).focus();

  	// observe the field
  	$(el).blur( function() {
  		if ($(this).val() == '') {
  			$(this).remove();
  			temp.show();
  			temp.attr('disabled', false);
  		}
  	});
  });
  
  // Toggle the homepage form between login and forgot password
  $('a.toggle-form').each( function() {
    var form = $(this).parents('form');
  	var show = $(form).attr('id') == 'login' ? '#forgot-password' : '#login';
  	
  	$(this).click( function() {
  	  form.hide();
  	  $('#msg').hide();
  	  $('#err').hide();
  	  $('#msg-forgot').hide();
  	  $('#err-forgot').hide();
  	  $('#msg-forgot-br').hide();
  	  $('#err-forgot-br').hide();
  	  $(show).show();
  	  return false;
  	});
  });
});
