/**
 */
var user = {
  open: null,
  field: null,
  field_name: null
};

function show_form(dt) {
  if (user.open) {
   hide_form(user.open);
  }
  user.open = dt;
  dt.addClass('active').next('dd').slideDown('fast');
}

function hide_form(dt) {
  dt.removeClass('active').next('dd').slideUp('fast');
  user.open = null;
}

function show_login() {
  $('#account').attr('action', '/user/login');
  $('#register').hide();
  $('#login').show();  
}

$(document).ready(function() {
  /*
   * show registration form
   */
  $('#show_register').click(function() {
    $('#account').attr('action', '/user/register');
    $('#login').hide();
    $('#register').show();
    return false;
  });

  /*
   * show login form
   */
  $('#show_login').click(function() {
    show_login();
    return false;
  });

  if (location.hash == '#account') {
    show_login();
  }

  /*
   * Only one section is open
   */
  var i = 0;
  $('#user dt').each(function() {
    $(this).attr('id', 'm' + i++);
  });

  $('#user dt.form').click(function() {
    if (user.open && user.open.attr('id') == $(this).attr('id')) {
      hide_form($(this));
    }
    else {
      show_form($(this));
    }
  });  

/*
  $('#user input.email').focus(function() {
	  $(this).css({backgroundImage: 'none'});
  });

  $('#user input.password').focus(function() {
	  $(this).css({backgroundImage: 'none'});
  });
*/
});
