/*
 * Inserts non-semantic markup for a visual notification.
 *
 * Copyright (c) 2009 Brandon Diamond <brandon@megathink.com>, http://www.megathink.com
 */

(function($) {
  $.showNotice = function(message, options) {
    var $container;
    var $notice;

    options = $.extend({
      duration: 10000,
      extraClass: "",
      error: false
    }, options);
    
    $container = $("#notice-container");

    // if container not found, create and append to body
    if(!$container.size()) {
      $container = $("<div id='notice-container' />").appendTo("body").click(function () {
        $(".notice", this).fadeOut(function() { $(this).remove(); })
      });
    }

    $notice = $("<div />").addClass("notice")
                          .toggleClass(options.extraClass, options.extraClass)
                          .toggleClass("error", options.error)
                          .text(message)
                          .prependTo($container)
                          .slideDown()
                          .click(function(event) {
                            $(this).remove();
                            event.stopPropagation(); // don't propagate to container div (would hide all)
                          });

    setTimeout(function () {
      try { $notice.slideUp(function() { $(this).remove() }); } catch (e) {}
    }, options.duration);
  }
})(jQuery);


