/*! ab - v0.0.3 - 2014-03-24 */ !function(){function a(){this._events={}}function b(a){this.name=a}function c(a,b){this.name=a,this.traffic=b,this.slice=null,this.storage=i,this._slices={}}var d={},e=function(a,b,e){return d.hasOwnProperty(a)?d[a]:("undefined"==typeof b&&(b=1),d[a]=new c(a,b),e&&e.length&&d[a].slices(e),d[a])};e.clear=function(){for(var a in d)d.hasOwnProperty(a)&&d[a].clear();d={}};var f=window.ab;e.noConflict=function(){return window.ab=f,e},e.events=new a,e.version="__VERSION__",e.config={STORAGE_PREFIX:"ab:"};var g=function(a){var b="test";try{return window[a+"Storage"].setItem(b,b),window[a+"Storage"].removeItem(b),!0}catch(c){return!1}},h=function(a){function b(a,b,c){var d,e;c?(d=new Date,d.setTime(d.getTime()+24*c*60*60*1e3),e="; expires="+d.toGMTString()):e="",document.cookie=a+"="+b+e+"; path=/"}function c(a){var b,c,d=a+"=",e=document.cookie.split(";");for(b=0;bc;c++)this._events[a][c].apply(window,b)},a.prototype.on=function(a,b){this._events.hasOwnProperty(a)||(this._events[a]=[]),this._events[a].push(b)},b.prototype.toString=function(){return this.name},b.prototype.toJSON=function(){return{name:this.name}},c.prototype.slices=function(a){if(null!==this.slice)throw new Error("Attempted to add slices to already running test.");"[object Array]"!==Object.prototype.toString.call(a)&&(a=Array.prototype.slice.call(arguments,0));for(var c=0,d=a.length;d>c;c++)this.add(new b(a[c]));return this},c.prototype.add=function(a){return this._slices[a.name]=a,this},c.prototype.run=function(a){var c=this.urlSlice()||this.storedSlice();return c&&this.hasSlice(c)?this.slice=this.getSlice(c):Math.random()>this.traffic?(this.slice=new b("control"),e.events.trigger("start",this)):(this.slice=this.chooseSlice(),e.events.trigger("start",this)),this.storage.setItem(this.key(),this.slice.name),"function"==typeof a&&a.call(this),e.events.trigger("run",this),this},c.prototype.chooseSlice=function(){var a=[];for(var c in this._slices)this._slices.hasOwnProperty(c)&&a.push(c);if(0===a.length)return new b("control");var d=Math.floor(Math.random()/(1/a.length));return this.getSlice(a[d])},c.prototype.hasSlice=function(a){return"control"===a&&this.traffic<1||this._slices.hasOwnProperty(a)},c.prototype.getSlice=function(a){return"control"===a?new b("control"):this._slices[a]},c.prototype.urlSlice=function(){var a,b=window.location.hash,c=window.location.search,d=new RegExp("("+this.key()+")=([\\w0-9]+)");return(a=b.match(d))?a[2]:(a=c.match(d))?a[2]:!1},c.prototype.storedSlice=function(){return this.storage.getItem(this.key())},c.prototype.key=function(){return e.config.STORAGE_PREFIX+this.name},c.prototype.toString=function(){return this.key()},c.prototype.clear=function(){this.storage.removeItem(this.key())},c.prototype.style=function(a){var b=document.createElement("link");return b.rel="stylesheet",b.href=a,document.head.appendChild(b),this},c.prototype.script=function(a,b){var c=document.createElement("script");c.type="text/javascript",c.async="undefined"==typeof b?!0:!!b,c.src=a;var d=document.getElementsByTagName("script")[0];return d.parentNode.insertBefore(c,d),this},e.Test=c,e.Slice=b,e.Storage=h,e.Events=a,"undefined"!=typeof module&&module.exports&&"undefined"!=typeof require?module.exports=e:"function"==typeof define&&define.amd?define("ab",function(){return e}):window.ab=e}();