(function(n){typeof define=="function"&&define.amd?define(["jquery"],n):typeof exports=="object"?n(require("jquery")):n(jQuery)})(function(n){function i(t){var s=arguments.length,e=window[t],u=arguments,f=u[1],o,i,c,r,h;if(s<2)throw new Error("Minimum 2 arguments must be given");else{if(n.isArray(f)){i={};for(r in f){o=f[r];try{i[o]=JSON.parse(e.getItem(o))}catch(l){i[o]=e.getItem(o)}}return i}if(s==2)try{return JSON.parse(e.getItem(f))}catch(l){return e.getItem(f)}else{try{i=JSON.parse(e.getItem(f))}catch(l){throw new ReferenceError(f+" is not defined in this storage");}for(r=2;r<s-1;r++)if(i=i[u[r]],i===undefined)throw new ReferenceError([].slice.call(u,1,r+1).join(".")+" is not defined in this storage");if(n.isArray(u[r])){c=i;i={};for(h in u[r])i[u[r][h]]=c[u[r][h]];return i}return i[u[r]]}}}function u(t){var s=arguments.length,e=window[t],o=arguments,u=o[1],h=o[2],f,c={},i,r;if(s<2||!n.isPlainObject(u)&&s<3)throw new Error("Minimum 3 arguments must be given or second parameter must be an object");else{if(n.isPlainObject(u)){for(r in u)f=u[r],n.isPlainObject(f)?e.setItem(r,JSON.stringify(f)):e.setItem(r,f);return u}if(s==3)return typeof h=="object"?e.setItem(u,JSON.stringify(h)):e.setItem(u,h),h;try{i=e.getItem(u);i!=null&&(c=JSON.parse(i))}catch(l){}for(i=c,r=2;r<s-2;r++)f=o[r],i[f]&&n.isPlainObject(i[f])||(i[f]={}),i=i[f];return i[o[r]]=o[r+1],e.setItem(u,JSON.stringify(c)),c}}function h(t){var o=arguments.length,e=window[t],r=arguments,u=r[1],s,f,i,h;if(o<2)throw new Error("Minimum 2 arguments must be given");else{if(n.isArray(u)){for(i in u)e.removeItem(u[i]);return!0}if(o==2)return e.removeItem(u),!0;try{s=f=JSON.parse(e.getItem(u))}catch(c){throw new ReferenceError(u+" is not defined in this storage");}for(i=2;i<o-1;i++)if(f=f[r[i]],f===undefined)throw new ReferenceError([].slice.call(r,1,i).join(".")+" is not defined in this storage");if(n.isArray(r[i]))for(h in r[i])delete f[r[i][h]];else delete f[r[i]];return e.setItem(u,JSON.stringify(s)),!0}}function v(t,i){var u=f(t);for(var r in u)h(t,u[r]);if(i)for(r in n.namespaceStorages)a(r)}function c(t){var o=arguments.length,s=arguments,h=window[t],e=s[1],u,r;if(o==1)return f(t).length==0;if(n.isArray(e)){for(r=0;r<e.length;r++)if(!c(t,e[r]))return!1;return!0}try{u=i.apply(this,arguments);n.isArray(s[o-1])||(u={totest:u});for(r in u)if(!(n.isPlainObject(u[r])&&n.isEmptyObject(u[r])||n.isArray(u[r])&&!u[r].length||!u[r]))return!1;return!0}catch(l){return!0}}function l(t){var e=arguments.length,o=arguments,s=window[t],f=o[1],u,r;if(e<2)throw new Error("Minimum 2 arguments must be given");if(n.isArray(f)){for(r=0;r<f.length;r++)if(!l(t,f[r]))return!1;return!0}try{u=i.apply(this,arguments);n.isArray(o[e-1])||(u={totest:u});for(r in u)if(!(u[r]!==undefined&&u[r]!==null))return!1;return!0}catch(h){return!1}}function f(t){var s=arguments.length,h=window[t],e=arguments,c=e[1],u=[],r={},f,o;if(r=s>1?i.apply(this,e):h,r&&r._cookie)for(f in n.cookie())f!=""&&u.push(f.replace(r._prefix,""));else for(o in r)u.push(o);return u}function a(t){if(!t||typeof t!="string")throw new Error("First parameter must be a string");e?(window.localStorage.getItem(t)||window.localStorage.setItem(t,"{}"),window.sessionStorage.getItem(t)||window.sessionStorage.setItem(t,"{}")):(window.localCookieStorage.getItem(t)||window.localCookieStorage.setItem(t,"{}"),window.sessionCookieStorage.getItem(t)||window.sessionCookieStorage.setItem(t,"{}"));var i={localStorage:n.extend({},n.localStorage,{_ns:t}),sessionStorage:n.extend({},n.sessionStorage,{_ns:t})};return n.cookie&&(window.cookieStorage.getItem(t)||window.cookieStorage.setItem(t,"{}"),i.cookieStorage=n.extend({},n.cookieStorage,{_ns:t})),n.namespaceStorages[t]=i,i}function y(n){var t="jsapi";try{return window[n]?(window[n].setItem(t,t),window[n].removeItem(t),!0):!1}catch(i){return!1}}var o="ls_",s="ss_",e=y("localStorage"),t={_type:"",_ns:"",_callMethod:function(n,t){var i=[this._type],t=Array.prototype.slice.call(t),r=t[0];return this._ns&&i.push(this._ns),typeof r=="string"&&r.indexOf(".")!==-1&&(t.shift(),[].unshift.apply(t,r.split("."))),[].push.apply(i,t),n.apply(this,i)},get:function(){return this._callMethod(i,arguments)},set:function(){var f=arguments.length,e=arguments,t=e[0],i,r;if(f<1||!n.isPlainObject(t)&&f<2)throw new Error("Minimum 2 arguments must be given or first parameter must be an object");if(n.isPlainObject(t)&&this._ns){for(i in t)u(this._type,this._ns,i,t[i]);return t}return r=this._callMethod(u,e),this._ns?r[t.split(".")[0]]:r},remove:function(){if(arguments.length<1)throw new Error("Minimum 1 argument must be given");return this._callMethod(h,arguments)},removeAll:function(n){return this._ns?(u(this._type,this._ns,{}),!0):v(this._type,n)},isEmpty:function(){return this._callMethod(c,arguments)},isSet:function(){if(arguments.length<1)throw new Error("Minimum 1 argument must be given");return this._callMethod(l,arguments)},keys:function(){return this._callMethod(f,arguments)}},r;n.cookie&&(window.name||(window.name=Math.floor(Math.random()*1e8)),r={_cookie:!0,_prefix:"",_expires:null,_path:null,_domain:null,setItem:function(t,i){n.cookie(this._prefix+t,i,{expires:this._expires,path:this._path,domain:this._domain})},getItem:function(t){return n.cookie(this._prefix+t)},removeItem:function(t){return n.removeCookie(this._prefix+t)},clear:function(){for(var t in n.cookie())t!=""&&(!this._prefix&&t.indexOf(o)===-1&&t.indexOf(s)===-1||this._prefix&&t.indexOf(this._prefix)===0)&&n.removeCookie(t)},setExpires:function(n){return this._expires=n,this},setPath:function(n){return this._path=n,this},setDomain:function(n){return this._domain=n,this},setConf:function(n){return n.path&&(this._path=n.path),n.domain&&(this._domain=n.domain),n.expires&&(this._expires=n.expires),this},setDefaultConf:function(){this._path=this._domain=this._expires=null}},e||(window.localCookieStorage=n.extend({},r,{_prefix:o,_expires:3650}),window.sessionCookieStorage=n.extend({},r,{_prefix:s+window.name+"_"})),window.cookieStorage=n.extend({},r),n.cookieStorage=n.extend({},t,{_type:"cookieStorage",setExpires:function(n){return window.cookieStorage.setExpires(n),this},setPath:function(n){return window.cookieStorage.setPath(n),this},setDomain:function(n){return window.cookieStorage.setDomain(n),this},setConf:function(n){return window.cookieStorage.setConf(n),this},setDefaultConf:function(){return window.cookieStorage.setDefaultConf(),this}}));n.initNamespaceStorage=function(n){return a(n)};e?(n.localStorage=n.extend({},t,{_type:"localStorage"}),n.sessionStorage=n.extend({},t,{_type:"sessionStorage"})):(n.localStorage=n.extend({},t,{_type:"localCookieStorage"}),n.sessionStorage=n.extend({},t,{_type:"sessionCookieStorage"}));n.namespaceStorages={};n.removeAllStorages=function(t){n.localStorage.removeAll(t);n.sessionStorage.removeAll(t);n.cookieStorage&&n.cookieStorage.removeAll(t);t||(n.namespaceStorages={})}})