/** Notify.js - v0.0.1 - 2013/06/06
* http://notifyjs.com/
* Copyright (c) 2013 Jaime Pillora - MIT
*/
(function(t,n,e){"use strict";var i,o,r,s,a,h,l,p,c,u,d,f,m,w,y,g,v,b,x,P,C,H,T=[].indexOf||function(t){for(var n=0,e=this.length;e>n;n++)if(n in this&&this[n]===t)return n;return-1};g="notify",y=g+"js",b={t:"top",m:"middle",b:"bottom",l:"left",c:"center",r:"right"},p=["l","c","r"],H=["t","m","b"],f=["t","b","l","r"],m={t:"b",m:null,b:"t",l:"r",c:null,r:"l"},w=function(t){var n;return n=[],$.each(t.split(/\W+/),function(t,i){var o;return o=i.toLowerCase().charAt(0),b[o]?n.push(o):e}),n},C={},r={name:"core",html:'
',css:"."+y+"-corner {\n position: fixed;\n margin: 5px;\n z-index: 1050;\n}\n\n."+y+"-corner ."+y+"-wrapper,\n."+y+"-corner ."+y+"-container {\n position: relative;\n display: block;\n height: inherit;\n width: inherit;\n margin: 3px;\n}\n\n."+y+"-wrapper {\n z-index: 1;\n position: absolute;\n display: inline-block;\n height: 0;\n width: 0;\n}\n\n."+y+"-container {\n display: none;\n z-index: 1;\n position: absolute;\n cursor: pointer;\n}\n\n."+y+"-text {\n position: relative;\n}\n\n."+y+"-arrow {\n position: absolute;\n z-index: 2;\n width: 0;\n height: 0;\n}"},P={"border-radius":["-webkit-","-moz-"]},o=function(n,i){var o,r;return(null!=(r=C[n])?r.cssElem:void 0)&&(t.console&&console.warn(""+g+": overwriting style '"+n+"'"),C[n].cssElem.remove()),i.name=n,C[n]=i,o="",i.classes&&$.each(i.classes,function(t,n){return o+="."+y+"-"+i.name+"-"+t+" {\n",$.each(n,function(t,n){return P[t]&&$.each(P[t],function(e,i){return o+=" "+i+t+": "+n+";\n"}),o+=" "+t+": "+n+";\n"}),o+="}\n"}),i.css&&(o+="/* styles for "+i.name+" */\n"+i.css),o?(i.cssElem=d(o),i.cssElem.attr("id","notify-"+i.name)):e},d=function(t){var n;n=s("style"),$("head").append(n);try{n.html(t)}catch(e){n[0].styleSheet.cssText=t}return n},v={autoHide:!0,autoHideDelay:5e3,arrowShow:!0,arrowSize:5,elementPosition:"bottom",globalPosition:"top right",style:"bootstrap",className:"error",showAnimation:"slideDown",showDuration:400,hideAnimation:"slideUp",hideDuration:200,gap:5},u=function(t,n){var e;return e=function(){},e.prototype=t,$.extend(!0,new e,n)},a=function(t){return $.extend(v,t)},s=function(t){return $("<"+t+">"+t+">")},l={},h=function(t){var n;return t.is("[type=radio]")&&(n=t.parents("form:first").find("[type=radio]").filter(function(n,e){return $(e).attr("name")===t.attr("name")}),t=n.first()),t},c=function(t,n,i){var o,r;if("string"==typeof i)i=parseInt(i,10);else if("number"!=typeof i)return;if(!isNaN(i))return o=b[m[n.charAt(0)]],r=n,t[o]!==e&&(n=b[o.charAt(0)],i=-i),t[n]===e?t[n]=i:t[n]+=i,null},x=function(t,n,e){if("l"===t||"t"===t)return 0;if("c"===t||"m"===t)return e/2-n/2;if("r"===t||"b"===t)return e-n;throw"Invalid alignment"},i=function(){function t(t,n,e){"string"==typeof e&&(e={className:e}),this.options=u(v,$.isPlainObject(e)?e:{}),this.loadHTML(),this.wrapper=$(r.html),this.wrapper.data(y,this),this.arrow=this.wrapper.find("."+y+"-arrow"),this.container=this.wrapper.find("."+y+"-container"),this.container.append(this.userContainer),t&&t.length&&(this.elementType=t.attr("type"),this.originalElement=t,this.elem=h(t),this.elem.data(y,this),this.elem.before(this.wrapper)),this.container.hide(),this.run(n)}return t.prototype.loadHTML=function(){var t;if(t=this.getStyle(),this.userContainer=$(t.html),this.text=this.userContainer.find("[data-notify-text]"),0===this.text.length&&(this.text=this.userContainer.find("[data-notify-html]"),this.rawHTML=!0),0===this.text.length)throw"style: '"+name+"' HTML is missing a: 'data-notify-text' or 'data-notify-html' attribute";return this.text.addClass(""+y+"-text")},t.prototype.show=function(t,n){var i,o,r,s,a,h=this;if(o=function(){return t||h.elem||h.destroy(),n?n():e},a=this.container.parent().parents(":hidden").length>0,r=this.container.add(this.arrow),i=[],a&&t)s="show";else if(a&&!t)s="hide";else if(!a&&t)s=this.options.showAnimation,i.push(this.options.showDuration);else{if(a||t)return o();s=this.options.hideAnimation,i.push(this.options.hideDuration)}return i.push(o),r[s].apply(r,i)},t.prototype.setGlobalPosition=function(){var t,n,e,i,o,r,a,h;return h=this.getPosition(),a=h[0],r=h[1],o=b[a],t=b[r],i=a+"|"+r,n=l[i],n||(n=l[i]=s("div"),e={},e[o]=0,"middle"===t?e.top="45%":"center"===t?e.left="45%":e[t]=0,n.css(e).addClass(""+y+"-corner"),$("body").append(n)),n.prepend(this.wrapper)},t.prototype.setElementPosition=function(){var t,n,i,o,r,s,a,h,l,u,d,w,y,g,v,P,C,A,S,N,M,z,D,E,k,L,j,O,I;for(D=this.getPosition(),N=D[0],A=D[1],S=D[2],d=this.elem.position(),h=this.elem.outerHeight(),w=this.elem.outerWidth(),l=this.elem.innerHeight(),u=this.elem.innerWidth(),E=this.wrapper.position(),r=this.container.height(),s=this.container.width(),g=b[N],P=m[N],C=b[P],a={},a[C]="b"===N?h:"r"===N?w:0,c(a,"top",d.top-E.top),c(a,"left",d.left-E.left),I=["top","left"],k=0,j=I.length;j>k;k++)M=I[k],v=parseInt(this.elem.css("margin-"+M),10),v&&c(a,M,v);if(y=Math.max(0,this.options.gap-(this.options.arrowShow?i:0)),c(a,C,y),this.options.arrowShow){for(i=this.options.arrowSize,n=$.extend({},a),t=this.userContainer.css("border-color")||this.userContainer.css("background-color")||"white",L=0,O=f.length;O>L;L++)M=f[L],z=b[M],M!==P&&(o=z===g?t:"transparent",n["border-"+z]=""+i+"px solid "+o);c(a,b[P],i),T.call(f,A)>=0&&c(n,b[A],2*i)}else this.arrow.hide();return T.call(H,N)>=0?(c(a,"left",x(A,s,w)),n&&c(n,"left",x(A,i,u))):T.call(p,N)>=0&&(c(a,"top",x(A,r,h)),n&&c(n,"top",x(A,i,l))),this.container.is(":visible")&&(a.display="block"),this.container.removeAttr("style").css(a),n?this.arrow.removeAttr("style").css(n):e},t.prototype.getPosition=function(){var t,n,e,i,o,r,s,a;if(n=this.options.position||(this.elem?this.options.elementPosition:this.options.globalPosition),t=w(n),0===t.length&&(t[0]="b"),e=t[0],0>T.call(f,e))throw"Must be one of ["+f+"]";return(1===t.length||(i=t[0],T.call(H,i)>=0&&(o=t[1],0>T.call(p,o)))||(r=t[0],T.call(p,r)>=0&&(s=t[1],0>T.call(H,s))))&&(t[1]=(a=t[0],T.call(p,a)>=0?"m":"l")),2===t.length&&(t[2]=t[1]),t},t.prototype.getStyle=function(t){var n;if(t||(t=this.options.style),t||(t="default"),n=C[t],!n)throw"Missing style: "+t;return n},t.prototype.updateClasses=function(){var t,n;return t=["base"],$.isArray(this.options.className)?t=t.concat(this.options.className):this.options.className&&t.push(this.options.className),n=this.getStyle(),t=$.map(t,function(t){return""+y+"-"+n.name+"-"+t}).join(" "),this.userContainer.attr("class",t)},t.prototype.run=function(t,n){var i=this;return $.isPlainObject(n)?$.extend(this.options,n):"string"===$.type(n)&&(this.options.color=n),this.container&&!t?(this.show(!1),e):this.container||t?(this.text[this.rawHTML?"html":"text"](t),this.updateClasses(),this.elem?this.setElementPosition():this.setGlobalPosition(),this.show(!0),this.options.autoHide?(clearTimeout(this.autohideTimer),this.autohideTimer=setTimeout(function(){return i.show(!1)},this.options.autoHideDelay)):e):e},t.prototype.destroy=function(){return this.wrapper.remove()},t}(),$[g]=function(t,n,e){return t&&t.nodeName||t.jquery?$(t)[g](n,e):(e=n,n=t,new i(null,n,e)),t},$.fn[g]=function(t,n){return $(this).each(function(){var e;return e=h($(this)).data(y),e?e.run(t,n):new i($(this),t,n)}),this},$.extend($[g],{defaults:a,addStyle:o,pluginOptions:v}),$(function(){return d(r.css).attr("data-notify-style","core"),$(n).on("click","."+y+"-wrapper",function(){var t;return(t=$(this).data(y))?t.elem?t.show(!1):t.destroy():e})})})(window,document);