/*!
  jStore - Persistent Client-Side Storage
 
  Copyright (c) 2009 Eric Garside (http://eric.garside.name)
  
  Dual licensed under:
   MIT: http://www.opensource.org/licenses/mit-license.php
  GPLv3: http://www.opensource.org/licenses/gpl-3.0.html
 *//*!
  jQuery JSON Plugin
  version: 1.0 (2008-04-17)
 
  This document is licensed as free software under the terms of the
  MIT License: http://www.opensource.org/licenses/mit-license.php
 
  Brantley Harris technically wrote this plugin, but it is based somewhat
  on the JSON.org website's http://www.json.org/json2.js, which proclaims:
  "NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.", a sentiment that
  I uphold.  I really just cleaned it up.
 
  It is also based heavily on MochiKit's serializeJSON, which is 
  copywrited 2005 by Bob Ippolito.
 */(function($){function toIntegersAtLease(n)
{return n<10?'0'+n:n;}
Date.prototype.toJSON=function(date)
{return this.getUTCFullYear()+'-'+
toIntegersAtLease(this.getUTCMonth())+'-'+
toIntegersAtLease(this.getUTCDate());};var escapeable=/["\\\x00-\x1f\x7f-\x9f]/g;var meta={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'};$.quoteString=function(string)
{if(escapeable.test(string))
{return'"'+string.replace(escapeable,function(a)
{var c=meta[a];if(typeof c==='string'){return c;}
c=a.charCodeAt();return'\\u00'+Math.floor(c/16).toString(16)+(c%16).toString(16);})+'"';}
return'"'+string+'"';};$.toJSON=function(o,compact)
{var type=typeof(o);if(type=="undefined")
return"undefined";else if(type=="number"||type=="boolean")
return o+"";else if(o===null)
return"null";if(type=="string")
{return $.quoteString(o);}
if(type=="object"&&typeof o.toJSON=="function")
return o.toJSON(compact);if(type!="function"&&typeof(o.length)=="number")
{var ret=[];for(var i=0;i<o.length;i++){ret.push($.toJSON(o[i],compact));}
if(compact)
return"["+ret.join(",")+"]";else
return"["+ret.join(", ")+"]";}
if(type=="function"){throw new TypeError("Unable to convert object of type 'function' to json.");}
var ret=[];for(var k in o){var name;type=typeof(k);if(type=="number")
name='"'+k+'"';else if(type=="string")
name=$.quoteString(k);else
continue;var val=$.toJSON(o[k],compact);if(typeof(val)!="string"){continue;}
if(compact)
ret.push(name+":"+val);else
ret.push(name+": "+val);}
return"{"+ret.join(", ")+"}";};$.compactJSON=function(o)
{return $.toJSON(o,true);};$.evalJSON=function(src)
{return eval("("+src+")");};$.secureEvalJSON=function(src)
{var filtered=src;filtered=filtered.replace(/\\["\\\/bfnrtu]/g,'@');filtered=filtered.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']');filtered=filtered.replace(/(?:^|:|,)(?:\s*\[)+/g,'');if(/^[\],:{}\s]*$/.test(filtered))
return eval("("+src+")");else
throw new SyntaxError("Error parsing JSON, source is not valid.");};})(jQuery);(function(){var initializing=false,fnTest=/xyz/.test(function(){xyz;})?/\b_super\b/:/.*/;this.Class=function(){};Class.extend=function(prop){var _super=this.prototype;initializing=true;var prototype=new this();initializing=false;for(var name in prop){prototype[name]=typeof prop[name]=="function"&&typeof _super[name]=="function"&&fnTest.test(prop[name])?(function(name,fn){return function(){var tmp=this._super;this._super=_super[name];var ret=fn.apply(this,arguments);this._super=tmp;return ret;};})(name,prop[name]):prop[name];}
function Class(){if(!initializing&&this.init)
this.init.apply(this,arguments);}
Class.prototype=prototype;Class.constructor=Class;Class.extend=arguments.callee;return Class;};})();/*!
  jStore Delegate Framework
  Copyright (c) 2009 Eric Garside (http://eric.garside.name)
 */(function($){this.jStoreDelegate=Class.extend({init:function(parent){this.parent=parent;this.callbacks={};},bind:function(event,callback){if(!$.isFunction(callback))return this;if(!this.callbacks[event])this.callbacks[event]=[];this.callbacks[event].push(callback);return this;},trigger:function(){var parent=this.parent,args=[].slice.call(arguments),event=args.shift(),handlers=this.callbacks[event];if(!handlers)return false;$.each(handlers,function(){this.apply(parent,args)});return this;}});})(jQuery);(function($){var rxJson;try{rxJson=new RegExp('^("(\\\\.|[^"\\\\\\n\\r])*?"|[,:{}\\[\\]0-9.\\-+Eaeflnr-u \\n\\r\\t])+?$')}catch(e){rxJson=/^(true|false|null|\[.*\]|\{.*\}|".*"|\d+|\d+\.\d+)$/}
$.jStore={};$.extend($.jStore,{EngineOrder:new Array('html5','local','ie','flash','gears'),Availability:{},Engines:{},Instances:{},CurrentEngine:null,defaults:{project:null,engine:null,autoload:true,flash:'jStore.Flash.html'},isReady:false,isFlashReady:false,delegate:new jStoreDelegate($.jStore).bind('jStore-ready',function(engine){$.jStore.isReady=true;if($.jStore.defaults.autoload)engine.connect();}).bind('flash-ready',function(){$.jStore.isFlashReady=true;}),ready:function(callback){if($.jStore.isReady)callback.apply($.jStore,[$.jStore.CurrentEngine]);else $.jStore.delegate.bind('jStore-ready',callback);},fail:function(callback){$.jStore.delegate.bind('jStore-failure',callback);},flashReady:function(callback){if($.jStore.isFlashReady)callback.apply($.jStore,[$.jStore.CurrentEngine]);else $.jStore.delegate.bind('flash-ready',callback);},use:function(engine,project,identifier){project=project||$.jStore.defaults.project||location.hostname.replace(/\./g,'-')||'unknown';var e=$.jStore.Engines[engine.toLowerCase()]||null,name=(identifier?identifier+'.':'')+project+'.'+engine;if(!e)throw'JSTORE_ENGINE_UNDEFINED';e=new e(project,name);if($.jStore.Instances[name])throw'JSTORE_JRI_CONFLICT';if(e.isAvailable()){$.jStore.Instances[name]=e;if(!$.jStore.CurrentEngine){$.jStore.CurrentEngine=e;}
$.jStore.delegate.trigger('jStore-ready',e);}else{if(!e.autoload)
throw'JSTORE_ENGINE_UNAVILABLE';else{e.included(function(){if(this.isAvailable()){$.jStore.Instances[name]=this;if(!$.jStore.CurrentEngine){$.jStore.CurrentEngine=this;}
$.jStore.delegate.trigger('jStore-ready',this);}
else $.jStore.delegate.trigger('jStore-failure',this);}).include();}}},setCurrentEngine:function(name){if(!$.jStore.Instances.length)
return $.jStore.FindEngine();if(!name&&$.jStore.Instances.length>=1){$.jStore.delegate.trigger('jStore-ready',$.jStore.Instances[0]);return $.jStore.CurrentEngine=$.jStore.Instances[0];}
if(name&&$.jStore.Instances[name]){$.jStore.delegate.trigger('jStore-ready',$.jStore.Instances[name]);return $.jStore.CurrentEngine=$.jStore.Instances[name];}
throw'JSTORE_JRI_NO_MATCH';},FindEngine:function(){$.each($.jStore.EngineOrder,function(k){if($.jStore.Availability[this]()){$.jStore.use(this,$.jStore.defaults.project,'default');return false;}})},load:function(){if($.jStore.defaults.engine)
return $.jStore.use($.jStore.defaults.engine,$.jStore.defaults.project,'default');try{$.jStore.FindEngine();}catch(e){}},safeStore:function(value){switch(typeof value){case'object':case'function':return $.jStore.compactJSON(value);case'number':case'boolean':case'string':case'xml':return value;case'undefined':default:return'';}},safeResurrect:function(value){return rxJson.test(value)?$.evalJSON(value):value;},store:function(key,value){if(!$.jStore.CurrentEngine)return false;if(!value)
return $.jStore.CurrentEngine.get(key);return $.jStore.CurrentEngine.set(key,value);},remove:function(key){if(!$.jStore.CurrentEngine)return false;return $.jStore.CurrentEngine.rem(key);},get:function(key){return $.jStore.store(key);},set:function(key,value){return $.jStore.store(key,value);}})
$.extend($.fn,{store:function(key,value){if(!$.jStore.CurrentEngine)return this;var result=$.jStore.store(key,value);return!value?result:this;},removeStore:function(key){$.jStore.remove(key);return this;},getStore:function(key){return $.jStore.store(key);},setStore:function(key,value){$.jStore.store(key,value);return this;}})})(jQuery);(function($){this.StorageEngine=Class.extend({init:function(project,name){this.project=project;this.jri=name;this.data={};this.limit=-1;this.includes=[];this.delegate=new jStoreDelegate(this).bind('engine-ready',function(){this.isReady=true;}).bind('engine-included',function(){this.hasIncluded=true;});this.autoload=false;this.isReady=false;this.hasIncluded=false;},include:function(){var self=this,total=this.includes.length,count=0;$.each(this.includes,function(){$.ajax({type:'get',url:this,dataType:'script',cache:true,success:function(){count++;if(count==total)self.delegate.trigger('engine-included');}})});},isAvailable:function(){return false;},interruptAccess:function(){if(!this.isReady)throw'JSTORE_ENGINE_NOT_READY';},ready:function(callback){if(this.isReady)callback.apply(this);else this.delegate.bind('engine-ready',callback);return this;},included:function(callback){if(this.hasIncluded)callback.apply(this);else this.delegate.bind('engine-included',callback);return this;},get:function(key){this.interruptAccess();return this.data[key]||null;},set:function(key,value){this.interruptAccess();this.data[key]=value;return value;},rem:function(key){this.interruptAccess();var beforeDelete=this.data[key];this.data[key]=null;return beforeDelete;}});})(jQuery);/*!
  jStore DOM Storage Engine
  Copyright (c) 2009 Eric Garside (http://eric.garside.name)
 */(function($){var sessionAvailability=$.jStore.Availability.session=function(){return!!window.sessionStorage;},localAvailability=$.jStore.Availability.local=function(){return!!(window.localStorage||window.globalStorage);};this.jStoreDom=StorageEngine.extend({init:function(project,name){this._super(project,name);this.type='DOM';this.limit=5*1024*1024;},connect:function(){this.delegate.trigger('engine-ready');},get:function(key){this.interruptAccess();var out=this.db.getItem(key);return $.jStore.safeResurrect((out&&out.value?out.value:out));},set:function(key,value){this.interruptAccess();this.db.setItem(key,$.jStore.safeStore(value));return value;},rem:function(key){this.interruptAccess();var out=this.get(key);this.db.removeItem(key);return out}})
this.jStoreLocal=jStoreDom.extend({connect:function(){this.db=!window.globalStorage?window.localStorage:window.globalStorage[location.hostname];this._super();},isAvailable:localAvailability})
this.jStoreSession=jStoreDom.extend({connect:function(){this.db=sessionStorage;this._super();},isAvailable:sessionAvailability})
$.jStore.Engines.local=jStoreLocal;$.jStore.Engines.session=jStoreSession;})(jQuery);/*!
  jStore Flash Storage Engine
  Copyright (c) 2009 Eric Garside (http://eric.garside.name)
  jStore.swf Copyright (c) 2008 Daniel Bulli (http://www.nuff-respec.com)
 */(function($){var avilability=$.jStore.Availability.flash=function(){return!!($.jStore.hasFlash('8.0.0'));}
this.jStoreFlash=StorageEngine.extend({init:function(project,name){this._super(project,name);this.type='Flash';var self=this;$.jStore.flashReady(function(){self.flashReady()});},connect:function(){var name='jstore-flash-embed-'+this.project;$(document.body).append('<iframe style="height:1px;width:1px;position:absolute;left:0;top:0;margin-left:-100px;" '+'id="jStoreFlashFrame" src="'+$.jStore.defaults.flash+'"></iframe>');},flashReady:function(e){var iFrame=$('#jStoreFlashFrame')[0];if(iFrame.Document&&$.isFunction(iFrame.Document['jStoreFlash'].f_get_cookie))this.db=iFrame.Document['jStoreFlash'];else if(iFrame.contentWindow&&iFrame.contentWindow.document){var doc=iFrame.contentWindow.document;if($.isFunction($('object',$(doc))[0].f_get_cookie))this.db=$('object',$(doc))[0];else if($.isFunction($('embed',$(doc))[0].f_get_cookie))this.db=$('embed',$(doc))[0];}
if(this.db)this.delegate.trigger('engine-ready');},isAvailable:avilability,get:function(key){this.interruptAccess();var out=this.db.f_get_cookie(key);return out=='null'?null:$.jStore.safeResurrect(out);},set:function(key,value){this.interruptAccess();this.db.f_set_cookie(key,$.jStore.safeStore(value));return value;},rem:function(key){this.interruptAccess();var beforeDelete=this.get(key);this.db.f_delete_cookie(key);return beforeDelete;}})
$.jStore.Engines.flash=jStoreFlash;$.jStore.hasFlash=function(version){var pv=$.jStore.flashVersion().match(/\d+/g),rv=version.match(/\d+/g);for(var i=0;i<3;i++){pv[i]=parseInt(pv[i]||0);rv[i]=parseInt(rv[i]||0);if(pv[i]<rv[i])return false;if(pv[i]>rv[i])return true;}
return true;}
$.jStore.flashVersion=function(){try{try{var axo=new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6');try{axo.AllowScriptAccess='always';}
catch(e){return'6,0,0';}}catch(e){}
return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g,',').match(/^,?(.+),?$/)[1];}catch(e){try{if(navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin){return(navigator.plugins["Shockwave Flash 2.0"]||navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g,",").match(/^,?(.+),?$/)[1];}}catch(e){}}
return'0,0,0';}})(jQuery);function flash_ready(){$.jStore.delegate.trigger('flash-ready');}/*!
  jStore Google Gears Storage Engine
  Copyright (c) 2009 Eric Garside (http://eric.garside.name)
 */(function($){var avilability=$.jStore.Availability.gears=function(){return!!(window.google&&window.google.gears)}
this.jStoreGears=StorageEngine.extend({init:function(project,name){this._super(project,name);this.type='Google Gears';this.includes.push('http://code.google.com/apis/gears/gears_init.js');this.autoload=true;},connect:function(){var db=this.db=google.gears.factory.create('beta.database');db.open('jstore-'+this.project);db.execute('CREATE TABLE IF NOT EXISTS jstore (k TEXT UNIQUE NOT NULL PRIMARY KEY, v TEXT NOT NULL)');this.updateCache();},updateCache:function(){var result=this.db.execute('SELECT k,v FROM jstore');while(result.isValidRow()){this.data[result.field(0)]=$.jStore.safeResurrect(result.field(1));result.next();}result.close();this.delegate.trigger('engine-ready');},isAvailable:avilability,set:function(key,value){this.interruptAccess();var db=this.db;db.execute('BEGIN');db.execute('INSERT OR REPLACE INTO jstore(k, v) VALUES (?, ?)',[key,$.jStore.safeStore(value)]);db.execute('COMMIT');return this._super(key,value);},rem:function(key){this.interruptAccess();var db=this.db;db.execute('BEGIN');db.execute('DELETE FROM jstore WHERE k = ?',[key]);db.execute('COMMIT');return this._super(key);}})
$.jStore.Engines.gears=jStoreGears;})(jQuery);/*!
  jStore HTML5 Specification Storage Engine
  Copyright (c) 2009 Eric Garside (http://eric.garside.name)
 */(function($){var avilability=$.jStore.Availability.html5=function(){return!!window.openDatabase}
this.jStoreHtml5=StorageEngine.extend({init:function(project,name){this._super(project,name);this.type='HTML5';this.limit=1024*200;},connect:function(){var db=this.db=openDatabase('jstore-'+this.project,'1.0',this.project,this.limit);if(!db)throw'JSTORE_ENGINE_HTML5_NODB';db.transaction(function(db){db.executeSql('CREATE TABLE IF NOT EXISTS jstore (k TEXT UNIQUE NOT NULL PRIMARY KEY, v TEXT NOT NULL)');});this.updateCache();},updateCache:function(){var self=this;this.db.transaction(function(db){db.executeSql('SELECT k,v FROM jstore',[],function(db,result){var rows=result.rows,i=0,row;for(;i<rows.length;++i){row=rows.item(i);self.data[row.k]=$.jStore.safeResurrect(row.v);}
self.delegate.trigger('engine-ready');});});},isAvailable:avilability,set:function(key,value){this.interruptAccess();this.db.transaction(function(db){db.executeSql('INSERT OR REPLACE INTO jstore(k, v) VALUES (?, ?)',[key,$.jStore.safeStore(value)]);});return this._super(key,value);},rem:function(key){this.interruptAccess();this.db.transaction(function(db){db.executeSql('DELETE FROM jstore WHERE k = ?',[key])})
return this._super(key);}})
$.jStore.Engines.html5=jStoreHtml5;})(jQuery);/*!
  jStore IE Storage Engine
  Copyright (c) 2009 Eric Garside (http://eric.garside.name)
 */(function($){var avilability=$.jStore.Availability.ie=function(){return!!window.ActiveXObject;}
this.jStoreIE=StorageEngine.extend({init:function(project,name){this._super(project,name);this.type='IE';this.limit=64*1024;},connect:function(){this.db=$('<div style="display:none;behavior:url(\'#default#userData\')" id="jstore-'+this.project+'"></div>').appendTo(document.body).get(0);this.delegate.trigger('engine-ready');},isAvailable:avilability,get:function(key){this.interruptAccess();this.db.load(this.project);return $.jStore.safeResurrect(this.db.getAttribute(key));},set:function(key,value){this.interruptAccess();this.db.setAttribute(key,$.jStore.safeStore(value));this.db.save(this.project);return value;},rem:function(key){this.interruptAccess();var beforeDelete=this.get(key);this.db.removeAttribute(key);this.db.save(this.project);return beforeDelete;}})
$.jStore.Engines.ie=jStoreIE;})(jQuery);

