$(function() {
  $('.hide').css('display', 'none');
  
  if ($.fn.cornerz)
  {
    $('.panel:not(.nocornerz)').cornerz();
    $('.panel.ondark').cornerz({background: '#d9dce3'});
    $('.panel > h3').cornerz({background: '#d9dce3', radius: 5, corners: 'tl tr'});
    
    $('.attention').cornerz();
    $('.cornered').cornerz();
    $('div.flash').cornerz();
    $('div.notice').cornerz();
    $('div.errorExplanation').cornerz();
    
    $('ul.tabbed-steps li:first-child').cornerz({radius: 7, corners: 'tl'});
    $('ul.tabbed-steps li:last-child').cornerz({radius: 7, corners: 'tr'});
    
    $('.sidebar-bubble > div').cornerz({radius: 14});
  }
  
  setTimeout(function() {
    $('div.flash').fadeOut();
  }, 6000);
  
  if (typeof IE7 != 'undefined') {
    IE7.recalcOrig = IE7.recalc;
    IE7.recalc = function() { IE7.recalcOrig(); resizeFrame(null, true); };
  } else {
    resizeFrame(null, true);
  }
  
  $('.undercurve').undercurve();
  $('.slideshow').slideshow();
  
  $('form').each(function() {
    var buttons = $(this).find('input.antidupe');
    if (!buttons.length) return;
    
    buttons.each(function() {
      // Make a disabled clone of the button.
      var clone = $(this).clone()
        .css({ position: 'absolute', left: -1000, top: -1000 })
        .attr('disabled', 'disabled')
        .appendTo('body');
      
      // Associate it with the source button.
      $(this).data('clone', clone);
    });
    
    $(this).submit(function() {
      // When submitting, position the clones.
      buttons.each(function() {
        var offset = $(this).offset();
        $(this).data('clone').css({ left: offset.left, top: offset.top });
      });
      
      // Don't allow the form to be resubmitted.
      $(this).unbind('submit').submit(function() { return false; });
    });
  });
});
