(function(){var g=function(a,b){return Object.prototype.hasOwnProperty.call(a,b)},i=function(a){var b=0;for(var c in a)g(a,c)&&b++;return b},d=this.Store=function(a,b,c){this.name=a;this.defaults=b||{};this.watcherSpeed=c||500;this.listeners={};this.applyDefaults()};d.clear=function(){localStorage.clear()};d.prototype.applyDefaults=function(){for(var a in this.defaults)g(this.defaults,a)&&this.get(a)===undefined&&this.set(a,this.defaults[a]);return this};d.prototype.watcher=function(a){this.watcherTimer&&
clearTimeout(this.watcherTimer);if(i(this.listeners)||a){this.newObject=this.toObject();if(this.oldObject){for(var b in this.newObject)g(this.newObject,b)&&this.newObject[b]!==this.oldObject[b]&&this.fireEvent(b,this.newObject[b]);for(b in this.oldObject)g(this.oldObject,b)&&!g(this.newObject,b)&&this.fireEvent(b,this.newObject[b])}this.oldObject=this.newObject;var c=this;this.watcherTimer=setTimeout(function(){c.watcher()},this.watcherSpeed)}return this};d.prototype.get=function(a){a=localStorage.getItem("store."+
this.name+"."+a);if(a!==null)try{return JSON.parse(a)}catch(b){return null}};d.prototype.set=function(a,b){if(b===undefined)this.remove(a);else{if(typeof b==="function")b=null;try{b=JSON.stringify(b)}catch(c){b=null}localStorage.setItem("store."+this.name+"."+a,b)}return this};d.prototype.remove=function(a){localStorage.removeItem("store."+this.name+"."+a);return this.applyDefaults()};d.prototype.reset=function(){for(var a="store."+this.name+".",b=localStorage.length-1;b>=0;b--)localStorage.key(b).substring(0,
a.length)===a&&localStorage.removeItem(localStorage.key(b));return this.applyDefaults()};d.prototype.toObject=function(){for(var a={},b="store."+this.name+".",c=localStorage.length-1;c>=0;c--)if(localStorage.key(c).substring(0,b.length)===b){var e=localStorage.key(c).substring(b.length),f=this.get(e);if(f!==undefined)a[e]=f}return a};d.prototype.fromObject=function(a,b){b||this.reset();for(var c in a)g(a,c)&&this.set(c,a[c]);return this};d.prototype.addEvent=function(a,b){this.watcher(true);this.listeners[a]||
(this.listeners[a]=[]);var c=this.listeners[a],e;a:{e=c.length>>>0;for(var f=0;f<e;f++)if(c[f]===b){e=f;break a}e=-1}e!==-1||c.push(b);return this};d.prototype.removeEvent=function(a,b){for(var c=this.listeners[a].length-1;c>=0;c--)this.listeners[a][c]===b&&this.listeners[a].splice(c,1);this.listeners[a].length||delete this.listeners[a];return this};d.prototype.fireEvent=function(a,b){for(var c=[a,"*"],e=0;e<c.length;e++){var f=c[e];if(this.listeners[f])for(var h=0;h<this.listeners[f].length;h++)this.listeners[f][h](b,
a,this.name)}return this}})();
