function loader()
{
  $(".thickbox").each(function()
  {
    $(this).unbind("click");
  });
  tb_init(".thickbox");
      
  $("form:not(form:last)").each(function()
  {
    var el = $(this);
    el.autoAjax({
      src: ".container",
      dest: ".container",
      beforeRequest: function()
      {
        $.blockUI();
      },
      afterRequest: function(data)
      {
        $(".container").css("position", "static");
        loader();
        $.unblockUI();
        
        var parts = el.attr("action").split("#");
        var error = $("div.errorMessage");
        var success = $("#success").hide();
        
        if (parts.length > 1)
        {
          var elo = $("#" + parts[1]);
          if (elo.length > 0)
          {
            var t = elo.position().top;
            if ($(".scrolling").outerHeight() > elo.parent().outerHeight() - 10) t -= $(".scrolling").outerHeight() - elo.parent().outerHeight() + 10; 
            
            $(".scrolling").stop().animate({
              top: t
            }, 500);
            
            $("html, body").stop().animate({
              scrollTop: elo.position().top
            }, 500, function()
            {
              if (error.length > 0)
              {
                $.blockUI({
                  css: {
                    padding: 10,
                    backgroundColor: "#ffe7e4",
                    color: "#cc0000"
                  },
                  message: error.html() + '<br><p><a href="javascript:void(0)" title="Close" onclick="$.unblockUI()">Close</a></p>'
                });
              }
              else if (success.length > 0)
                success.fadeIn(500);
            });
          }
        }
      },
      error: function(xhr, txt, err)
      {
        $.unblockUI();
        alert(xhr.status);
      }
    }).find("input[type=radio]").click(function()
    {
      $(this).closest("form").submit();
    });
  });
  
  $("div.start-over a").autoAjax({
    src: ".container",
    dest: ".container",
    beforeRequest: function()
    {
      $.blockUI();
    },
    afterRequest: function()
    {
      $(".container").css("position", "static");
      loader();
      $.unblockUI();
      
      $("html, body").stop().animate({
        scrollTop: 0
      }, 500);
    }
  });
  
  var el = $(".scrolling");
  el.css({
    position: "absolute",
    left: 0,
    top: 0,
    width: el.parent().width()
  });
  
  $("table.choices tr.has-button").hide();
  $("#txtLocatorZip").maskLabel({
    css: {
      fontWeight: "bold",
      color: "#ccc"
    },
    text: "ENTER 5 DIGIT ZIP"
  });
}

$(function()
{
  loader();
});
