(function($){
  Drupal.behaviors.holygrailTheme = {
  attach: function(context, settings) {
    if $('div.messages') {
      $('div.messages:not(.processed)')
        .addClass('processed')
        .each(function() {
          if ($('a', this).size() || $(this).is('.error') || $(this).is('.warning') || $(this).text().length > 100) {
            $(this).prepend("<div class='close-this'>x</span>");
            $('div.close-this', this).click(function() {
              $(this).parent().slideUp('fast');
            });
          }
          else {
            // Adds a 3 second pause before hiding the message.
            $(this).animate({opacity:1}, 4000, 'linear', function() {
              $(this).slideUp('fast');
            });
          }
        });
      }
    };
  };
})(jQuery);;

