(function(a){a.gritter={};a.gritter.options={fade_in_speed:"medium",fade_out_speed:1e3,time:6e3};a.gritter.add=function(a){try{return b.add(a||{})}catch(d){var c="Gritter Error: "+d;typeof console!="undefined"&&console.error?console.error(c,a):alert(c)}};a.gritter.remove=function(c,a){b.removeSpecific(c,a||{})};a.gritter.removeAll=function(a){b.stop(a||{})};var b={fade_in_speed:"",fade_out_speed:"",time:"",_custom_timer:0,_item_count:0,_is_setup:0,_tpl_close:'<div class="gritter-close"></div>',_tpl_item:'<div id="gritter-item-[[number]]" class="gritter-item-wrapper [[item_class]]" style="display:none"><div class="gritter-top"></div><div class="gritter-item">[[image]]<div class="[[class_name]]"><span class="gritter-title">[[username]]</span><p>[[text]]</p></div><div style="clear:both"></div></div><div class="gritter-bottom"></div></div>',_tpl_wrap:'<div id="gritter-notice-wrapper"></div>',add:function(c){if(!c.title||!c.text)throw'You need to fill out the first 2 params: "title" and "text"';!this._is_setup&&this._runSetup();var n=c.title,m=c.text,f=c.image||"",e=c.sticky||false,k=c.class_name||"",i=c.time||"";this._verifyWrapper();this._item_count++;var d=this._item_count,h=this._tpl_item;a(["before_open","after_open","before_close","after_close"]).each(function(f,e){b["_"+e+"_"+d]=a.isFunction(c[e])?c[e]:function(){}});this._custom_timer=0;if(i)this._custom_timer=i;var l=f!=""?'<img src="'+f+'" class="gritter-image" />':"",j=f!=""?"gritter-with-image":"gritter-without-image";h=this._str_replace(["[[username]]","[[text]]","[[image]]","[[number]]","[[class_name]]","[[item_class]]"],[n,m,l,this._item_count,j,k],h);this["_before_open_"+d]();a("#gritter-notice-wrapper").append(h);var g=a("#gritter-item-"+this._item_count);g.fadeIn(this.fade_in_speed,function(){b["_after_open_"+d](a(this))});!e&&this._setFadeTimer(g,d);a(g).bind("mouseenter mouseleave",function(c){if(c.type=="mouseenter")!e&&b._restoreItemIfFading(a(this),d);else!e&&b._setFadeTimer(a(this),d);b._hoverState(a(this),c.type)});return d},_countRemoveWrapper:function(c,b){b.remove();this["_after_close_"+c](b);a(".gritter-item-wrapper").length==0&&a("#gritter-notice-wrapper").remove()},_fade:function(a,d,c,e){var c=c||{},f=typeof c.fade!="undefined"?c.fade:true;fade_out_speed=c.speed||this.fade_out_speed;this["_before_close_"+d](a);e&&a.unbind("mouseenter mouseleave");if(f)a.animate({opacity:0},fade_out_speed,function(){a.animate({height:0},300,function(){b._countRemoveWrapper(d,a)})});else this._countRemoveWrapper(d,a)},_hoverState:function(a,d){if(d=="mouseenter"){a.addClass("hover");var c=a.find("img");c.length?c.before(this._tpl_close):a.find("span").before(this._tpl_close);a.find(".gritter-close").click(function(){var c=a.attr("id").split("-")[2];b.removeSpecific(c,{},a,true)})}else{a.removeClass("hover");a.find(".gritter-close").remove()}},removeSpecific:function(b,e,c,d){if(!c)var c=a("#gritter-item-"+b);this._fade(c,b,e||{},d)},_restoreItemIfFading:function(b,a){clearTimeout(this["_int_id_"+a]);b.stop().css({opacity:""})},_runSetup:function(){for(opt in a.gritter.options)this[opt]=a.gritter.options[opt];this._is_setup=1},_setFadeTimer:function(d,a){var c=this._custom_timer?this._custom_timer:this.time;this["_int_id_"+a]=setTimeout(function(){b._fade(d,a)},c)},stop:function(b){var d=a.isFunction(b.before_close)?b.before_close:function(){},e=a.isFunction(b.after_close)?b.after_close:function(){},c=a("#gritter-notice-wrapper");d(c);c.fadeOut(function(){a(this).remove();e()})},_str_replace:function(m,k,l,d){var b=0,c=0,e="",h="",j=0,i=0,g=[].concat(m),f=[].concat(k),a=l,n=f instanceof Array,o=a instanceof Array;a=[].concat(a);if(d)this.window[d]=0;for(b=0,j=a.length;b<j;b++){if(a[b]==="")continue;for(c=0,i=g.length;c<i;c++){e=a[b]+"";h=n?f[c]!==undefined?f[c]:"":f[0];a[b]=e.split(g[c]).join(h);if(d&&a[b]!==e)this.window[d]+=(e.length-a[b].length)/g[c].length}}return o?a:a[0]},_verifyWrapper:function(){a("#gritter-notice-wrapper").length==0&&a("body").append(this._tpl_wrap)}}})(jQuery);
