/*
 Gritter for jQuery
 http://www.boedesign.com/

 Copyright (c) 2009 Jordan Boesch
 Dual licensed under the MIT and GPL licenses.

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

