var __state = '';
$(function() {
  orderSwitch = {};
  orderSwitch.openLogin = function() {
    $('#order-auth-login').attr('class', 'active font_color_attr_white background_attr_red');
    $('#order-auth-reg').attr('class', 'ajax font_color_attr_red');

    $('#order-auth-ajax').show();
    $.get(
      $('#order-auth-login').attr('href'),
      function (data) {
        $('#order-auth-container').html(data);
        $('#order-auth-ajax').hide();
        orderSwitch.hackFormLoginReg();
      }
    );
    return false;
  }
  orderSwitch.openReg = function() {
    $('#order-auth-login').attr('class', 'ajax font_color_attr_red');
    $('#order-auth-reg').attr('class', 'active font_color_attr_white background_attr_red');

    $('#order-auth-ajax').show();
    $.get(
      $('#order-auth-reg').attr('href'),
      function (data) {
        $('#order-auth-container').html(data);
        $('#order-auth-ajax').hide();
        orderSwitch.hackFormLoginReg();
      }
    );
    return false;
  }

  orderSwitch.hackFormLoginRegSubmit = function() {
    var self = this;
    $('#order-auth-ajax').show();
    $.post(
      $(self).attr('action'),
      $(self).serialize(),
      function (data) {
        $('#order-auth-container').html(data);
        $('#order-auth-ajax').hide();
        orderSwitch.hackFormLoginReg();
      }
    );
    return false;
  }

  orderSwitch.hackFormLoginReg = function() {
    $('form').submit(orderSwitch.hackFormLoginRegSubmit);
  }

  orderSwitch.init = function() {
    if (__state == 'reg') {
      orderSwitch.openReg();
    } else {
      orderSwitch.openLogin();
    }
      $('#order-auth-login').click(orderSwitch.openLogin);
      $('#order-auth-reg').click(orderSwitch.openReg);

  }
  orderSwitch.init();
});
