﻿(function(a){a.jGrowl=function(c,b){if(a("#jGrowl").size()==0)a('<div id="jGrowl"></div>').addClass(b&&b.position?b.position:a.jGrowl.defaults.position).appendTo("body");a("#jGrowl").jGrowl(c,b)};a.fn.jGrowl=function(b,d){if(a.isFunction(this.each)){var c=arguments;return this.each(function(){var e=this;if(a(this).data("jGrowl.instance")==undefined){a(this).data("jGrowl.instance",a.extend(new a.fn.jGrowl,{notifications:[],element:null,interval:null}));a(this).data("jGrowl.instance").startup(this)}if(a.isFunction(a(this).data("jGrowl.instance")[b]))a(this).data("jGrowl.instance")[b].apply(a(this).data("jGrowl.instance"),a.makeArray(c).slice(1));else a(this).data("jGrowl.instance").create(b,d)})}};a.extend(a.fn.jGrowl.prototype,{defaults:{pool:0,header:"",group:"",sticky:false,position:"top-right",glue:"after",theme:"default",themeState:"highlight",corners:"10px",check:250,life:8e3,closeDuration:"normal",openDuration:"normal",easing:"swing",closer:true,closeTemplate:"&times;",closerTemplate:"<div>[ close all ]</div>",log:function(){},beforeOpen:function(){},afterOpen:function(){},open:function(){},beforeClose:function(){},close:function(){},animateOpen:{opacity:"show"},animateClose:{opacity:"hide"}},notifications:[],element:null,interval:null,create:function(c,b){var b=a.extend({},this.defaults,b);if(typeof b.speed!=="undefined"){b.openDuration=b.speed;b.closeDuration=b.speed}this.notifications.push({message:c,options:b});b.log.apply(this.element,[this.element,c,b])},render:function(c){var d=this,e=c.message,b=c.options;b.themeState=b.themeState==""?"":"ui-state-"+b.themeState;var c=a('<div class="jGrowl-notification '+b.themeState+" ui-corner-all"+(b.group!=undefined&&b.group!=""?" "+b.group:"")+'">'+'<div class="jGrowl-close">'+b.closeTemplate+"</div>"+'<div class="jGrowl-header">'+b.header+"</div>"+'<div class="jGrowl-message">'+e+"</div></div>").data("jGrowl",b).addClass(b.theme).children("div.jGrowl-close").bind("click.jGrowl",function(){a(this).parent().trigger("jGrowl.close")}).parent();a(c).bind("mouseover.jGrowl",function(){a("div.jGrowl-notification",d.element).data("jGrowl.pause",true)}).bind("mouseout.jGrowl",function(){a("div.jGrowl-notification",d.element).data("jGrowl.pause",false)}).bind("jGrowl.beforeOpen",function(){if(b.beforeOpen.apply(c,[c,e,b,d.element])!=false)a(this).trigger("jGrowl.open")}).bind("jGrowl.open",function(){if(b.open.apply(c,[c,e,b,d.element])!=false){if(b.glue=="after")a("div.jGrowl-notification:last",d.element).after(c);else a("div.jGrowl-notification:first",d.element).before(c);a(this).animate(b.animateOpen,b.openDuration,b.easing,function(){if(a.browser.msie&&(parseInt(a(this).css("opacity"),10)===1||parseInt(a(this).css("opacity"),10)===0))this.style.removeAttribute("filter");if(a(this).data("jGrowl")!=null)a(this).data("jGrowl").created=new Date;a(this).trigger("jGrowl.afterOpen")})}}).bind("jGrowl.afterOpen",function(){b.afterOpen.apply(c,[c,e,b,d.element])}).bind("jGrowl.beforeClose",function(){if(b.beforeClose.apply(c,[c,e,b,d.element])!=false)a(this).trigger("jGrowl.close")}).bind("jGrowl.close",function(){a(this).data("jGrowl.pause",true);a(this).animate(b.animateClose,b.closeDuration,b.easing,function(){if(a.isFunction(b.close)){if(b.close.apply(c,[c,e,b,d.element])!==false)a(this).remove()}else a(this).remove()})}).trigger("jGrowl.beforeOpen");if(b.corners!=""&&a.fn.corner!=undefined)a(c).corner(b.corners);if(a("div.jGrowl-notification:parent",d.element).size()>1&&a("div.jGrowl-closer",d.element).size()==0&&this.defaults.closer!=false)a(this.defaults.closerTemplate).addClass("jGrowl-closer "+this.defaults.themeState+" ui-corner-all").addClass(this.defaults.theme).appendTo(d.element).animate(this.defaults.animateOpen,this.defaults.speed,this.defaults.easing).bind("click.jGrowl",function(){a(this).siblings().trigger("jGrowl.beforeClose");if(a.isFunction(d.defaults.closer))d.defaults.closer.apply(a(this).parent()[0],[a(this).parent()[0]])})},update:function(){a(this.element).find("div.jGrowl-notification:parent").each(function(){if(a(this).data("jGrowl")!=undefined&&a(this).data("jGrowl").created!=undefined&&a(this).data("jGrowl").created.getTime()+parseInt(a(this).data("jGrowl").life)<(new Date).getTime()&&a(this).data("jGrowl").sticky!=true&&(a(this).data("jGrowl.pause")==undefined||a(this).data("jGrowl.pause")!=true))a(this).trigger("jGrowl.beforeClose")});if(this.notifications.length>0&&(this.defaults.pool==0||a(this.element).find("div.jGrowl-notification:parent").size()<this.defaults.pool))this.render(this.notifications.shift());if(a(this.element).find("div.jGrowl-notification:parent").size()<2)a(this.element).find("div.jGrowl-closer").animate(this.defaults.animateClose,this.defaults.speed,this.defaults.easing,function(){a(this).remove()})},startup:function(b){this.element=a(b).addClass("jGrowl").append('<div class="jGrowl-notification"></div>');this.interval=setInterval(function(){a(b).data("jGrowl.instance").update()},parseInt(this.defaults.check));if(a.browser.msie&&parseInt(a.browser.version)<7&&!window["XMLHttpRequest"])a(this.element).addClass("ie6")},shutdown:function(){a(this.element).removeClass("jGrowl").find("div.jGrowl-notification").remove();clearInterval(this.interval)},close:function(){a(this.element).find("div.jGrowl-notification").each(function(){a(this).trigger("jGrowl.beforeClose")})}});a.jGrowl.defaults=a.fn.jGrowl.prototype.defaults})(jQuery)
