(function(m){m.gritter={};m.gritter.options={position:"",class_name:"",fade_in_speed:"medium",fade_out_speed:1e3,time:6e3};m.gritter.add=function(t){try{return d.add(t||{})}catch(e){var i="Gritter Error: "+e;typeof console!="undefined"&&console.error?console.error(i,t):alert(i)}};m.gritter.remove=function(e,t){d.removeSpecific(e,t||{})};m.gritter.removeAll=function(e){d.stop(e||{})};var d={position:"",fade_in_speed:"",fade_out_speed:"",time:"",_custom_timer:0,_item_count:0,_is_setup:0,_tpl_close:'<a class="gritter-close" href="#" tabindex="1"></a>',_tpl_title:'<span class="gritter-title">[[title]]</span>',_tpl_item:'<div id="gritter-item-[[number]]" class="gritter-item-wrapper [[item_class]]" style="display:none" role="alert"><div class="gritter-top"></div><div class="gritter-item">[[close]][[image]]<div class="[[class_name]]">[[title]]<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(i){if(typeof i=="string"){i={text:i}}if(i.text===null){throw'You must supply "text" parameter.'}if(!this._is_setup){this._runSetup()}var e=i.title,t=i.text,r=i.image||"",s=i.imageSize||"",o=i.sticky||false,n=i.class_name||m.gritter.options.class_name,a=i.position,_=i.time||"";this._verifyWrapper();this._item_count++;var c=this._item_count,f=this._tpl_item;m(["before_open","after_open","before_close","after_close"]).each(function(e,t){d["_"+t+"_"+c]=m.isFunction(i[t])?i[t]:function(){}});this._custom_timer=0;if(_){this._custom_timer=_}var l=r!=""?'<img src="'+r+'" class="gritter-image" '+(s?'style="height:'+s+'px;"':"")+" />":"",p=r!=""?"gritter-with-image":"gritter-without-image";if(e){e=this._str_replace("[[title]]",e,this._tpl_title)}else{e=""}f=this._str_replace(["[[title]]","[[text]]","[[close]]","[[image]]","[[number]]","[[class_name]]","[[item_class]]"],[e,t,this._tpl_close,l,this._item_count,p,n],f);if(this["_before_open_"+c]()===false){return false}m("#gritter-notice-wrapper").addClass(a).append(f);var u=m("#gritter-item-"+this._item_count);u.fadeIn(this.fade_in_speed,function(){d["_after_open_"+c](m(this))});if(!o){this._setFadeTimer(u,c)}m(u).bind("mouseenter mouseleave",function(e){if(e.type=="mouseenter"){if(!o){d._restoreItemIfFading(m(this),c)}}else{if(!o){d._setFadeTimer(m(this),c)}}d._hoverState(m(this),e.type)});m(u).find(".gritter-close").click(function(){d.removeSpecific(c,{},null,true);return false});return c},_countRemoveWrapper:function(e,t,i){t.remove();if(this["_after_close_"+e])this["_after_close_"+e](t,i);if(m(".gritter-item-wrapper").length==0){m("#gritter-notice-wrapper").remove()}this._clean(e)},_clean:function(i){m(["before_open","after_open","before_close","after_close","int_id"]).each(function(e,t){delete d["_"+t+"_"+i]})},_fade:function(e,t,i,r){var i=i||{},s=typeof i.fade!="undefined"?i.fade:true,o=i.speed||this.fade_out_speed,n=r;if(this["_before_close_"+t])this["_before_close_"+t](e,n);if(r){e.unbind("mouseenter mouseleave")}if(s){e.animate({opacity:0},o,function(){e.animate({height:0},300,function(){d._countRemoveWrapper(t,e,n)})})}else{this._countRemoveWrapper(t,e)}},_hoverState:function(e,t){if(t=="mouseenter"){e.addClass("hover");e.find(".gritter-close").show()}else{e.removeClass("hover");e.find(".gritter-close").hide()}},removeSpecific:function(e,t,i,r){if(!i){var i=m("#gritter-item-"+e)}this._fade(i,e,t||{},r)},_restoreItemIfFading:function(e,t){clearTimeout(this["_int_id_"+t]);e.stop().css({opacity:"",height:""})},_runSetup:function(){for(opt in m.gritter.options){this[opt]=m.gritter.options[opt]}this._is_setup=1},_setFadeTimer:function(e,t){var i=this._custom_timer?this._custom_timer:this.time;this["_int_id_"+t]=setTimeout(function(){d._fade(e,t)},i)},stop:function(e){var t=m.isFunction(e.before_close)?e.before_close:function(){};var i=m.isFunction(e.after_close)?e.after_close:function(){};var r=m("#gritter-notice-wrapper");t(r);var s=/^gritter-item-/,o=[];r.find(".gritter-item-wrapper").each(function(){var e=this.id.replace(s,"");if(e)o.push(e)});var n=function(){for(var e=0;e<o.length;e++){d._clean(o[e])}};r.fadeOut(function(){m(this).remove();i();n()});if(!r.is(":visible")){t(r);i();n()}},_str_replace:function(e,t,i,r){var s=0,o=0,n="",a="",_=0,c=0,f=[].concat(e),l=[].concat(t),p=i,u=l instanceof Array,m=p instanceof Array;p=[].concat(p);if(r){this.window[r]=0}for(s=0,_=p.length;s<_;s++){if(p[s]===""){continue}for(o=0,c=f.length;o<c;o++){n=p[s]+"";a=u?l[o]!==undefined?l[o]:"":l[0];p[s]=n.split(f[o]).join(a);if(r&&p[s]!==n){this.window[r]+=(n.length-p[s].length)/f[o].length}}}return m?p:p[0]},_verifyWrapper:function(){if(m("#gritter-notice-wrapper").length==0){m("body").append(this._tpl_wrap)}}}})(jQuery);