-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvillo.min.js
More file actions
24 lines (24 loc) · 44.1 KB
/
villo.min.js
File metadata and controls
24 lines (24 loc) · 44.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/*
* Copyright (c) 2012, Villo Services. All rights reserved.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*/
var villo;(function(){villo=this.villo||{},villo.version="0.9.9 c1",villo.global=this})(),villo.analytics={enable:function(){this.enabled=!0,this.load()},disable:function(){this.enabled=!1},send:function(a){if(typeof a!="string"){if(typeof a=="object"){if(!this.enabled)if(!a.force||a.force!==!0)return!1;return a.title&&a.data&&villo.trim(a.title)!==""&&villo.trim(a.data)!==""?(typeof a.data=="object"&&(a.data=JSON.stringify(a.data)),this.sendAnalytic({title:a.title,data:a.data}),!0):!1}return!1}if(!this.enabled)return!1;if(a==="launch"){if(!this.launched)return!0;this.launched=!0,this.sendAnalytic({title:"villo-launch",data:"true"})}else a==="login"?this.sendAnalytic({title:"villo-login",data:"true"}):a==="register"&&this.sendAnalytic({title:"villo-register",data:"true"})},sendAnalytic:function(a){villo.ajax("https://api.villo.me/analytics.php",{method:"post",parameters:{api:villo.apiKey,appid:villo.app.id,username:villo.user.getUsername()||"",token:villo.user.token||"",version:villo.app.version,title:villo.app.title,type:villo.app.type,patched:villo.patched?"yes":"no",datatitle:a.title,data:a.data},onSuccess:function(a){console.log(a)},onFailure:function(a){}})},load:function(){this.loaded||(this.loaded=!0,villo.hooks.listen({name:"load",retroactive:!0,callback:function(){villo.analytics.send("launch")},protect:!0}),villo.hooks.listen({name:"login",retroactive:!0,callback:function(){villo.analytics.send("login")},protect:!0}),villo.hooks.listen({name:"register",retroactive:!0,callback:function(){villo.analytics.send("register")},protect:!0}))},loaded:!1,launched:!1},villo.chat={rooms:[],buildName:function(a){return"VILLO.CHAT."+villo.app.id.toUpperCase()+"."+a.toUpperCase()},join:function(a){if(villo.chat.isSubscribed(a.room)===!1){var b=function(b){b.username=b.uuid,delete b.uuid,a.presence(b)};return PUBNUB.subscribe({restore:!0,channel:villo.chat.buildName(a.room),callback:typeof a.callback=="function"?function(b){a.callback(b)}:function(){},connect:a.connect||function(){},error:a.error||function(){},reconnect:a.reconnect||function(){},disconnect:a.disconnect||function(){},presence:typeof a.presence=="function"?b:!1}),villo.chat.rooms.push({name:a.room.toUpperCase()}),!0}return!0},presence:function(a){PUBNUB.here_now({channel:villo.chat.buildName(a.room),callback:function(b){b.users=b.uuids,delete b.uuids,a.callback(b)}})},isSubscribed:function(a){var b=!1;for(var c in villo.chat.rooms)if(villo.chat.rooms.hasOwnProperty(c)&&villo.chat.rooms[c].name.toUpperCase()===a.toUpperCase()){b=!0;break}return b},send:function(a){var b={username:villo.user.username,message:a.message,timestamp:(new Date).getTime()};return a.room||(a.room=villo.chat.rooms[0].name),PUBNUB.publish({channel:villo.chat.buildName(a.room),message:b}),!0},leaveAll:function(){for(var a in villo.chat.rooms)villo.chat.rooms.hasOwnProperty(a)&&PUBNUB.unsubscribe({channel:villo.chat.buildName(villo.chat.rooms[a].name)});return villo.chat.rooms=[],!0},leave:function(a){PUBNUB.unsubscribe({channel:villo.chat.buildName(a)});var b="";for(var c in villo.chat.rooms)if(villo.chat.rooms.hasOwnProperty(c)&&villo.chat.rooms[c].name===a){villo.chat.rooms.splice(c,1);break}return!0},history:function(a){PUBNUB.history({channel:villo.chat.buildName(a.room),limit:a.limit||25,callback:function(b){a.callback(b)}})}},villo.clipboard={copy:function(a){var b=villo.app.clipboard.length;return villo.app.clipboard[b]=a,b},paste:function(a){if(a)return villo.app.clipboard[a];var b=villo.app.clipboard.length;return villo.app.clipboard[b-1]}},villo.feeds={post:function(a){a.reference&&typeof a.reference=="object"&&(a.reference=a.reference.join(", ")),villo.ajax("https://api.villo.me/feeds.php",{method:"post",parameters:{api:villo.apiKey,appid:villo.app.id,type:"post",username:villo.user.username,token:villo.user.token,description:a.description,action:a.action||"user-post",reference:a.reference||""},onSuccess:function(b){console.log(b),b==="1"?a.callback(!0):a.callback(33)},onFailure:function(b){a.callback(33)}})},get:function(a){a.id&&typeof a.id=="object"&&(a.id=a.id.join(", ")),villo.ajax("https://api.villo.me/feeds.php",{method:"post",parameters:{api:villo.apiKey,appid:villo.app.id,type:"get",username:villo.user.username,token:villo.user.token,id:a.id},onSuccess:function(b){try{var c=JSON.parse(b);a.callback(c)}catch(d){a.callback(33)}},onFailure:function(b){a.callback(33)}})},search:function(a){villo.ajax("https://api.villo.me/feeds.php",{method:"post",parameters:{api:villo.apiKey,appid:villo.app.id,type:"search",username:villo.user.username,token:villo.user.token,limit:a.limit||50,term:a.term},onSuccess:function(b){try{b=JSON.parse(b)}catch(c){}b&&b.feeds?a.callback(b):a.callback(33)},onFailure:function(b){a.callback(33)}})},history:function(a){villo.ajax("https://api.villo.me/feeds.php",{method:"post",parameters:{api:villo.apiKey,appid:villo.app.id,type:"history",username:villo.user.username,token:villo.user.token,limit:a.limit||50,historyType:a.type||"public",after:a.after||!1},onSuccess:function(b){try{b=JSON.parse(b)}catch(c){}b&&b.feeds?a.callback(b):a.callback(33)},onFailure:function(b){a.callback(33)}})},listen:function(a){var b="VILLO/FEEDS/";a.type||(a.type="public");var c=a.type;c.toLowerCase()==="public"?b+="PUBLIC":c.toLowerCase()==="user"||c.toLowerCase()==="username"?b+="USERS/"+(a.username.toUpperCase()||villo.user.getUsername().toUpperCase()):c.toLowerCase()==="app"&&(b+="APPS/"+(a.appid.toUpperCase()||villo.app.id)),PUBNUB.subscribe({channel:b,callback:function(b){a.callback(b)}})},unlisten:function(){}},villo.friends={add:function(a){villo.ajax("https://api.villo.me/friends.php",{method:"post",parameters:{api:villo.apiKey,appid:villo.app.id,type:"add",username:villo.user.username,token:villo.user.token,addUsername:a.username},onSuccess:function(b){villo.verbose&&villo.log(b);if(b!==""){var c=JSON.parse(b);c.friends?a.callback(c):b===33||b===66||b===99?a.callback(b):a.callback(33)}else a.callback(33)},onFailure:function(){a.callback(33)}})},remove:function(a){villo.ajax("https://api.villo.me/friends.php",{method:"post",parameters:{api:villo.apiKey,appid:villo.app.id,type:"remove",username:villo.user.username,token:villo.user.token,removeUsername:a.username},onSuccess:function(b){villo.verbose&&villo.log(b);if(b!==""){var c=JSON.parse(b);c.friends?a.callback(c):b===33||b===66||b===99?a.callback(b):a.callback(33)}else a.callback(33)},onFailure:function(){a.callback(33)}})},get:function(a){villo.ajax("https://api.villo.me/friends.php",{method:"post",parameters:{api:villo.apiKey,appid:villo.app.id,type:"get",username:villo.user.username,token:villo.user.token},onSuccess:function(b){villo.verbose&&villo.log(b);if(b!==""){var c=JSON.parse(b);c.friends?a.callback(c):b===33||b===66||b===99?a.callback(b):a.callback(33)}else a.callback(33)},onFailure:function(){a.callback(33)}})}},villo.games={},villo.Game=function(a){if(this instanceof villo.Game){if(!a.name)return!1;this.name=a.name,delete a.name;var b="";a.type?(this.type=a.type,b=this.type,delete a.type):(this.type="all",b="all");if(a.features){this.features=a.features,delete a.features;for(var c in this.features)this.features.hasOwnProperty(c)&&villo.Game.features[this.features[c]]&&(this[this.features[c]]=villo.clone(villo.Game.features[this.features[c]]))}else villo.mixin(this,villo.clone(villo.Game.features));a.events&&(this.events=a.events,delete a.events,this.triggerEvent=function(a){return this.events[a.name]?(this[this.events[a.name]](a.data||!0),!0):!1}),a.create&&(this.create=a.create,delete a.create),villo.mixin(this,a);var d=villo.bind(this,function(a){villo.Game.invoke[a]&&(villo.Game.invoke[a].inherit&&villo.Game.invoke[a].inherit!==""&&villo.Game.invoke[villo.Game.invoke[a].inherit]&&d(villo.Game.invoke[a].inherit),villo.Game.invoke[a].create.call(this,!0))});return b&&d(this.type),this.create&&typeof this.create=="function"&&this.create(!0),villo.games[this.name]=this,this}return villo.verbose&&console.log("Forgot to include new keyword with villo.Game, attempting to call new instance."),new villo.Game(a)},villo.Game.features={},villo.Game.invoke={},villo.Game.feature=function(a){var b=a.name;delete a.name,villo.Game.features[b]?villo.mixin(villo.Game.features[b],a):villo.Game.features[b]=a},villo.Game.type=function(a){villo.Game.invoke[a.name]={create:a.create||function(){},inherit:a.inherit||""}},villo.Game.feature({name:"chat",room:"main",send:function(a){return villo.chat.send({room:a.room||this.room,message:a.message}),this},join:function(a){return this.room=a.room||this.room,villo.chat.join({room:this.room,callback:a.callback}),this},history:function(a){return villo.chat.history({room:a.room||this.room,callback:a.callback}),this},leave:function(a){return villo.chat.leave(a||this.room),this},leaveAll:function(){return villo.chat.leaveAll(),this}}),villo.Game.feature({name:"data",room:"data-main",send:function(){},interval:function(){},timeout:function(){},join:function(){this.room="data-"+joinObject.room||this.room},user:function(){}}),villo.Game.type({name:"all",create:function(){return this.chat&&this.chat.join({room:"game-"+this.name,callback:villo.bind(this,function(a){this.triggerEvent({name:"chat",data:a})})}),!this.presence,this.data&&this.data.join({room:this.name,callback:villo.bind(this,function(a){this.triggerEvent({name:"data",data:a})})}),this}}),villo.Game.type({name:"none",create:villo.doNothing}),villo.gift={retrieve:function(a){villo.ajax("https://api.villo.me/gifts.php",{method:"post",parameters:{api:villo.apiKey,appid:villo.app.id,type:"specific",category:a.categoryStack},onSuccess:function(b){villo.log(b);if(b!==""){var c=JSON.parse(b);c.gifts?a.callback(c):b===33||b===66||b===99?a.callback(b):a.callback(33)}else a.callback(99)},onFailure:function(b){villo.log("failure!"),a.callback(33)}})},getCatagories:function(){villo.gift.getCategories(arguments)},getCategories:function(a){villo.ajax("https://api.villo.me/gifts.php",{method:"post",parameters:{api:villo.apiKey,appid:villo.app.id,type:"category"},onSuccess:function(b){villo.log(b);if(b!==""){var c=JSON.parse(b);c.gifts?a.callback(c):b===33||b===66||b===99?a.callback(b):a.callback(33)}else a.callback(33)},onFailure:function(b){villo.log("failure!"),a.callback(33)}})},buy:function(a){villo.ajax("https://api.villo.me/gifts.php",{method:"post",parameters:{api:villo.apiKey,appid:villo.app.id,type:"buy",username:villo.user.username,token:villo.user.token,buyID:a.giftID},onSuccess:function(b){villo.log(b);if(b!==""){var c=JSON.parse(b);c.gifts&&a.callback(c),b===33||b===66||b===99?a.callback(b):a.callback(33)}else a.callback(33)},onFailure:function(b){villo.log("failure!"),a.callback(33)}})},credits:function(a){villo.log(villo.user.token),villo.log("Gettin' it!!"),villo.ajax("https://api.villo.me/gifts.php",{method:"post",parameters:{api:villo.apiKey,appid:villo.app.id,type:"checkCredit",username:villo.user.username,token:villo.user.token},onSuccess:function(b){villo.log(b);if(b!==""){var c=JSON.parse(b);c.gifts&&(villo.credits=c.gifts.data,a.callback(c)),b===33||b===66||b===99?a.callback(b):a.callback(33)}else a.callback(33)},onFailure:function(b){villo.log("failure!"),a.callback(33)}})},purchases:function(a){villo.ajax("https://api.villo.me/gifts.php",{method:"post",parameters:{api:villo.apiKey,appid:villo.app.id,type:"purchases",username:villo.user.username,token:villo.user.token},onSuccess:function(b){villo.log(b);if(b!==""){var c=JSON.parse(b);c.gifts&&(villo.credits=c.gifts.data,a.callback(c)),b===33||b===66||b===99?a.callback(b):a.callback(33)}else a.callback(33)},onFailure:function(b){a.callback(33)}})}},villo.isLoaded=!1,villo.verbose=!1,villo.resource=function(a){if(a&&typeof a=="object"&&a.resources){var b=a.resources,c=[];for(var d in b)b[d].slice(-2)==="js"?c.push(b[d]):b[d].slice(-1)==="/"?c.push(b[d]+"info.villo.js"):c.push(b[d]+"/info.villo.js");var e=a.callback||function(){};$LAB.script(c).wait(e)}},villo.load=function(a){if(villo.isLoaded===!0)if(!a.forceReload||a.forceReload!==!0)return villo.resource(a),!0;var b=function(a){villo.isLoaded=!0,villo.hooks.call({name:"load"}),a&&a.onload&&typeof a.onload=="function"&&a.onload(!0),a.patch===!1?villo.verbose&&console.log("Not loading patch file."):(villo.verbose&&console.log("Loading patch file."),$LAB.script("https://api.villo.me/patch.js").wait(function(){villo.verbose&&console.log("Loaded patch file, Villo fully loaded and functional."),villo.hooks.call({name:"patch"})}))};villo.apiKey=a.api||"",villo.app.type=a.type||"",villo.app.title=a.title||"",villo.app.id=a.id||"",villo.app.version=a.version||"",villo.app.developer=a.developer||"",villo.settings.exists()&&(villo.settings.load({instant:!0}),villo.settings.load({callback:function(){villo.hooks.call({name:"settings"})}})),"analytics"in a&&a.analytics===!1?villo.analytics.disable():villo.analytics.enable(),a.verbose&&(villo.verbose=a.verbose),villo.store.get("token.user")&&villo.store.get("token.token")&&villo.user.strapLogin({username:villo.store.get("token.user"),token:villo.store.get("token.token")});var c=[];if(a.include&&typeof (a.include==="object")&&a.include.length>0)for(var d in a.include)a.include.hasOwnProperty(d)&&c.push(a.include[d]);if(a.extensions&&typeof (a.extensions==="object")&&a.extensions.length>0)for(var e in a.extensions)a.extensions.hasOwnProperty(e)&&c.push(a.extensions[e]);c.length>0?$LAB.script(c).wait(function(){b(a)}):b(a)},villo.leaders={get:function(a){var b="";a.board&&a.board!==""?b=a.board:b=villo.app.title;var c=30;a.limit&&a.limit!==""&&typeof a.limit=="number"&&(c=a.limit),villo.ajax("https://api.villo.me/leaders.php",{method:"post",parameters:{api:villo.apiKey,type:a.duration,username:villo.user.username,appName:b,appid:villo.app.id,limit:c},onSuccess:function(b){villo.verbose&&villo.log("Success!"),villo.verbose&&villo.log(b);if(b!==""){var c=JSON.parse(b);c.leaders?a.callback(c):b===33||b===66||b===99?a.callback(b):a.callback(33)}else a.callback(33)},onFailure:function(b){villo.verbose&&villo.log("failure!"),a.callback(33)}})},search:function(a){var b=villo.app.title;a.board&&a.board!==""&&(b=a.board);var c=30;a.limit&&a.limit!==""&&typeof a.limit=="number"&&(c=a.limit),villo.ajax("https://api.villo.me/leaders.php",{method:"post",parameters:{api:villo.apiKey,type:"search",username:villo.user.username,appName:b,appid:villo.app.id,usersearch:a.username,limit:c},onSuccess:function(b){villo.verbose&&villo.log("Success!"),villo.verbose&&villo.log(b);if(b!==""){var c=JSON.parse(b);c.leaders?a.callback(c):b===33||b===66||b===99?a.callback(b):a.callback(33)}else a.callback(33)},onFailure:function(b){villo.verbose&&villo.log("failure!"),a.callback(33)}})},submit:function(a){var b=villo.app.title;a.board&&a.board!==""&&(b=a.board);var c=villo.user.username;if(villo.user.username===""||!villo.user.username||a.anon&&a.anon===!0)c="Guest";villo.ajax("https://api.villo.me/leaders.php",{method:"post",parameters:{api:villo.apiKey,type:"submit",username:c,token:villo.user.token,appName:b,appid:villo.app.id,score:a.score},onSuccess:function(b){villo.verbose&&villo.log(b),b!==""?b==="0"?a.callback(!0):b===33||b===66||b===99?a.callback(b):a.callback(33):a.callback(33)},onFailure:function(b){villo.verbose&&villo.log("failure!"),a.callback(33)}})}},villo.messages={},villo.profile={get:function(a){a.username||(a.username=villo.user.username),villo.ajax("https://api.villo.me/profile.php",{method:"post",parameters:{api:villo.apiKey,appid:villo.app.id,type:"get",username:a.username,ourUsername:villo.user.username||"Guest",ourToken:villo.user.token||""},onSuccess:function(b){villo.verbose&&villo.log(b);if(b!==""){var c=JSON.parse(b);c.profile?a.callback(c):b===33||b===66||b===99?a.callback(b):a.callback(33)}else a.callback(33)},onFailure:function(){a.callback(33)}})},set:function(a){villo.ajax("https://api.villo.me/profile.php",{method:"post",parameters:{api:villo.apiKey,appid:villo.app.id,username:villo.user.username,token:villo.user.token,type:"specific",field:a.field,data:a.data},onSuccess:function(b){villo.verbose&&villo.log(b);if(b!==""){var c=JSON.parse(b);c.profile?a.callback(c):b===33||b===66||b===99?a.callback(b):a.callback(33)}else a.callback(33)},onFailure:function(){a.callback(33)}})},friends:function(a){villo.verbose&&villo.log("villo.profile.friends called"),villo.ajax("https://api.villo.me/profile.php",{method:"post",parameters:{api:villo.apiKey,appid:villo.app.id,username:villo.user.username,token:villo.user.token,type:"friends"},onSuccess:function(b){if(b!==""){var c=JSON.parse(b);c.friends?a.callback(c):b===33||b===66||b===99?a.callback(b):a.callback(33)}else a.callback(33)},onFailure:function(){villo.verbose&&villo.log("failed request"),a.callback(33)}})},avatar:function(a){var b=a.username||villo.user.getUsername(),c="full",d="false";return a.size.toLowerCase()==="thumbnail"?c="thumbnail":a.size.toLowerCase()==="small"?c="small":a.size.toLowerCase()==="big"?c="big":(c="custom",d=a.size),"https://api.villo.me/avatar.php?username="+encodeURIComponent(b)+"&"+c+"=true&size="+d}},villo.settings={load:function(a){if(a.instant&&a.instant===!0)return villo.store.get("VilloSettingsProp")?(villo.app.settings=villo.store.get("VilloSettingsProp").settings,a.callback&&a.callback(villo.app.settings),villo.app.settings):(a.callback&&a.callback(!1),!1);var b=villo.store.get("VilloSettingsProp").timestamp||0;villo.storage.get({privacy:!0,title:"VilloSettingsProp",callback:function(c){typeof c!="object"?(villo.app.settings=villo.store.get("VilloSettingsProp").settings,a.callback(villo.app.settings)):c.timestamp>b?(villo.store.set("VilloSettingsProp",c),villo.app.settings=c.settings,a.callback(villo.app.settings)):(villo.app.settings=villo.store.get("VilloSettingsProp").settings,a.callback(villo.app.settings),villo.settings.save({settings:villo.app.settings}))}})},save:function(a){var b={},c=new Date,d=c.getTime();return b.timestamp=d,b.settings=a.settings||villo.app.settings,villo.store.set("VilloSettingsProp",b),villo.app.settings=b.settings,villo.storage.set({privacy:!0,title:"VilloSettingsProp",data:b,callback:villo.doNothing}),villo.app.settings},remove:function(){return villo.store.remove("VilloSettingsProp"),villo.app.settings={},!0},exists:function(a){if(!a||!a.cloud||a.cloud!==!0)return villo.store.get("VilloSettingsProp")?(a&&a.callback&&a.callback(!0),!0):(a&&a.callback&&a.callback(!1),!1);villo.storage.get({title:"VilloSettingsProp",privacy:!0,callback:function(b){b===!1?a.callback(!1):a.callback(!0)}})}},villo.states={set:function(a){return villo.store.set("VAppState",a),villo.storage.set({privacy:!0,title:"VAppState",data:a,callback:villo.doNothing}),!0},get:function(a){if(a.instant&&a.instant===!0){var b=villo.store.get("VAppState")||!1;return a.callback&&a.callback(b),b}villo.storage.get({privacy:!0,title:"VAppState",callback:function(b){b===!1||b===33?a.callback(villo.store.get("VAppState")||!1):a.callback(b)}})}},villo.storage={set:function(a){a.privacy||(a.privacy=!1),typeof a.data=="object"&&(a.data=JSON.stringify(a.data)),villo.ajax("https://api.villo.me/storage.php",{method:"post",parameters:{api:villo.apiKey,appid:villo.app.id,app:villo.app.title,type:"store",username:villo.user.username,token:villo.user.token,privacy:a.privacy,title:a.title,data:a.data},onSuccess:function(b){villo.verbose&&console.log(b),b==="1"?a.callback(!0):a.callback(33)},onFailure:function(){a.callback(33)}})},get:function(a){a.privacy||(a.privacy=!1);var b=villo.app.title,c=villo.app.id;a.external&&(b=a.external.appTitle,c=a.external.appID),villo.ajax("https://api.villo.me/storage.php",{method:"post",parameters:{api:villo.apiKey,appid:c,app:b,type:"get",username:villo.user.username,token:villo.user.token,title:a.title,privacy:a.privacy},onSuccess:function(b){villo.verbose&&console.log(b);if(b!==""&&b!=="0"){var c="";try{c=JSON.parse(b)}catch(d){c=b}a.callback(c)}else b==="0"?a.callback(!1):(villo.verbose&&console.log("Error 33 - Generic Error: "+b),a.callback(!1))},onFailure:function(){villo.verbose&&console.log("onFailure storage.get error"),a.callback(!1)}})}},villo.user={login:function(a){villo.ajax("https://api.villo.me/user/login.php",{method:"post",parameters:{api:villo.apiKey,appid:villo.app.id,username:a.username,password:a.password},onSuccess:function(b){var c=villo.trim(b);c===1||c===2||c===33||c===99?a.callback(c):c.length===32?(villo.user.strapLogin({username:a.username,token:c}),a.callback(!0),villo.hooks.call({name:"login"})):(a.callback(33),villo.verbose&&villo.log(33),villo.verbose&&villo.log("Error Logging In - Undefined: "+c))},onFailure:function(b){a.callback(33)}})},logout:function(){return villo.store.remove("token.user"),villo.store.remove("token.token"),delete villo.user.username,delete villo.user.token,villo.hooks.call({name:"logout"}),!0},isLoggedIn:function(){return villo.user.username&&villo.user.username!==""&&villo.user.token&&villo.user.token!==""?!0:!1},register:function(a){villo.ajax("https://api.villo.me/user/register.php",{method:"post",parameters:{api:villo.apiKey,appid:villo.app.id,username:a.username,password:a.password,password_confirm:a.password_confirm||a.password,fourvalue:a.fourvalue||!1,email:a.email},onSuccess:function(b){var c=villo.trim(b);c===1||c===2||c===33||c===99?a.callback(c):c.length===32?(villo.user.strapLogin({username:a.username,token:c}),a.callback(!0),villo.hooks.call({name:"register"})):(a.callback(33),villo.verbose&&villo.log(33),villo.verbose&&villo.log("Error Logging In - Undefined: "+c))},onFailure:function(b){a.callback(33)}})},strapLogin:function(a){return villo.store.set("token.user",a.username),villo.store.set("token.token",a.token),villo.user.username=a.username,villo.user.token=a.token,villo.hooks.call({name:"account"}),villo.sync(),!0},getUsername:function(){return villo.user.username||!1},username:null,token:""},villo.ajax=function(a,b){var c="";if(b.parameters&&typeof b.parameters=="object")for(var d in b.parameters)b.parameters.hasOwnProperty(d)&&(c+=escape(d)+"="+escape(b.parameters[d])+"&");var e="";b.method.toLowerCase()==="post"?e="POST":e="GET",villo._do_ajax({url:a,type:e,data:c,success:function(a){villo.verbose&&console.log(a),b.onSuccess(a)},error:function(a){villo.verbose&&console.log(a),b.onFailure(a)},forceXHR:b.forceXHR||!1,jsonp:b.jsonp||!1})},villo.jsonp={callbackCounter:0,fetch:function(a,b){var c="JSONPCallback_"+this.callbackCounter++;window[c]=this.evalJSONP(b),a=a.replace("=JSONPCallback","="+c);var d=document.createElement("SCRIPT");d.src=a,d.onerror=window[c],document.getElementsByTagName("HEAD")[0].appendChild(d)},evalJSONP:function(a){return function(b){var c=!1;if(typeof b=="string")try{c=JSON.parse(b)}catch(d){}else c=JSON.parse(JSON.stringify(b)),window.console&&console.warn("response data was not a JSON string");if(!c)throw"JSONP call returned invalid or empty JSON";a(c)}}},villo._do_ajax=function(a){var b=function(){return!1},c=a.url,d=a.type||"GET",e=a.success,f=a.error,g=a.data,h=a.forceXHR||!1,i=a.jsonp||!1,j=new XMLHttpRequest;j&&"withCredentials"in j&&i===!0&&delete j.withCredentials;if(!j||!("withCredentials"in j||h===!0)){villo.jsonp.fetch("http://query.yahooapis.com/v1/public/yql?q="+encodeURIComponent('select * from html where url="'+c+"?"+g+'"')+"&format=json&callback=JSONPCallback",function(a){try{a.query.url=c,a.query.data=g}catch(b){}if(a&&a.query&&a.query.results){var d=a.query.results;d.body&&d.body.p?e(d.body.p,"JSONP"):f(a)}else f(a)});return}j.open(d,c,!0);if(!j)return f("Ajax is not supported on your browser."),!1;var k=function(a){return function(c){c=b()?j:c,a==="load"&&(b()||c.readyState===4)&&e?e(c.responseText,c):f&&f(c)}};j.onload=function(a){k("load")(b()?a:a.target)},j.onerror=function(a){k("error")(b()?a:a.target)},d.toLowerCase()==="post"&&"setRequestHeader"in j&&j.setRequestHeader("Content-type","application/x-www-form-urlencoded"),j.send(g)},villo.app={clipboard:[],logs:[],settings:{},pubnub:{pub:"pub-42c6b905-6d4e-4896-b74f-c1065ab0dc10",sub:"sub-4e37d063-edfa-11df-8f1a-517217f921a4"}},villo.doNothing=function(){return!0},villo.doSomething=function(){var a=[];for(var b=0;b<arguments.length;b++)typeof (arguments[b]==="object")?a.push(JSON.stringify(arguments[b])):a.push(arguments[b]);return villo.log("You said",a),arguments[0]==="easterEgg"&&villo.webLog("Oh, hi Mark!"),!0},villo.bind=function(a,b){return typeof b=="string"&&a[b]&&(b=a[b]),function(){return b.apply(a,arguments)}},villo.mixin=function(a,b){for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a},villo.clone=function(a){if(typeof a!="object")return a;if(a.constructor===RegExp)return a;var b=new a.constructor;for(var c in a)a.hasOwnProperty(c)&&(b[c]=villo.clone(a[c]));return b},villo.extend=function(a,b){return villo.verbose&&console.log("Extending Villo:",a),villo.mixin(a,b),typeof a.create=="function"&&(a.create(),a._ext&&a._ext.keepit&&a._ext.keepit===!0?delete a._ext:delete a.create),a},villo.hooks={hooks:[],called:{},reserved:["login","register","logout","account","load","patch","settings"],listen:function(a){a.retroactive&&a.retroactive===!0&&this.called[a.name]&&a.callback.apply(this,this.called[a.name].args||[!0]);var b={name:a.name,callback:a.callback,protect:a.protect||!1};return parseInt(this.hooks.push(b),10)-1},unlisten:function(a){return this.hooks[a]?this.hooks[a].protect?!1:(delete this.hooks[a],!0):!1},call:function(a){if(!a.retroactive||a.retroactive!==!1)this.called[a.name]={name:a.name,args:a.args||[!0]};var b=villo.bind(this,function(b){return function(){b.apply(villo.global,a.args||[!0])}});for(var c in this.hooks)this.hooks.hasOwnProperty(c)&&this.hooks[c].name===a.name&&(a.async?window.setTimeout(b(this.hooks[c].callback),1):this.hooks[c].callback.apply(villo.global,a.args||[!0]));return!0}},villo.addSlashes=function(a){return a=a.replace(/\\/g,"\\\\"),a=a.replace(/\'/g,"\\'"),a=a.replace(/\"/g,'\\"'),a=a.replace(/\0/g,"\\0"),a},villo.stripslashes=function(a){return(a+"").replace(/\\(.?)/g,function(a,b){switch(b){case"\\":return"\\";case"0":return"\0";case"":return"";default:return b}})},villo.trim=function(a){a=a.replace(/^\s+/,"");for(var b=a.length-1;b>=0;b--)if(/\S/.test(a.charAt(b))){a=a.substring(0,b+1);break}return a},villo.cap=function(a){return a.slice(0,1).toUpperCase()+a.slice(1)},villo.log=function(){var a=[];for(var b=0;b<arguments.length;b++)typeof (arguments[b]==="object")?a.push(JSON.stringify(arguments[b])):a.push(arguments[b]);return console&&console.log?(console.log(a.join(" ")),villo.app.logs[villo.app.logs.length]=a.join(" ")):villo.app.logs[villo.app.logs.length]=a.join(" "),!0},villo.webLog=function(){var a=[];for(var b=0;b<arguments.length;b++)typeof (arguments[b]==="object")?a.push(JSON.stringify(arguments[b])):a.push(arguments[b]);console&&console.log?(console.log(a.join(" ")),villo.app.logs[villo.app.logs.length]=a.join(" ")):villo.app.logs[villo.app.logs.length]=a.join(" ");var c="";return villo.user.username&&villo.user.username!==""?c=villo.user.username:c="Guest",theLog=a.join(" "),villo.ajax("http://api.villo.me/log.php",{method:"post",parameters:{api:villo.apiKey,type:"log",username:c,appid:villo.app.id,log:theLog},onSuccess:function(a){},onFailure:function(a){}}),!0},villo.dumpLogs=function(a){return a&&a===!0?villo.app.logs:JSON.stringify(villo.app.logs)},villo.store=function(){var a=typeof localStorage!="undefined"&&localStorage,b=function(a){return a+"."+(villo.app.id||"myapp").toUpperCase()};return{get:function(c){c=b(c);if(!a)return document.cookie.indexOf(c)===-1?null:((document.cookie||"").match(RegExp(c+"=([^;]+)"))||[])[1]||null;var d=a.getItem(c);try{var e=JSON.parse(d);return typeof e=="object"?e:d}catch(f){return d}},set:function(c,d){c=b(c),typeof d=="object"&&(d=JSON.stringify(d));if(a)return a.setItem(c,d);document.cookie=c+"="+d+"; expires=Thu, 1 Aug 2030 20:00:00 UTC; path=/"},remove:function(c){c=b(c),a?a.removeItem(c):document.cookie=c+"="+""+"; expires=Thu, 1 Aug 2000 20:00:00 UTC; path=/"}}}(),villo.sync=function(){var a=new Date,b=function(b){villo.store.set("voucher",a.toString()),b||villo.ajax("https://api.villo.me/credits.php",{method:"post",parameters:{api:villo.apiKey,appid:villo.app.id,type:"voucher",username:villo.user.username,token:villo.user.token},onSuccess:function(){},onFailure:function(){}})},c=villo.store.get("voucher");c?(new Date(c)).getDate()!==a.getDate()?b():a.getTime()>(new Date(c)).getTime()+72e5&&(b(!1),villo.ajax("https://api.villo.me/credits.php",{method:"post",parameters:{api:villo.apiKey,appid:villo.app.id,type:"launch",username:villo.user.username,token:villo.user.token},onSuccess:function(a){},onFailure:function(){}})):b()},function(a){function t(a){return Object.prototype.toString.call(a)=="[object Function]"}function u(a){return Object.prototype.toString.call(a)=="[object Array]"}function v(a,b){var c=/^\w+\:\/\//;return/^\/\/\/?/.test(a)?a=location.protocol+a:!c.test(a)&&a.charAt(0)!="/"&&(a=(b||"")+a),c.test(a)?a:(a.charAt(0)=="/"?j:i)+a}function w(a,b){for(var c in a)a.hasOwnProperty(c)&&(b[c]=a[c]);return b}function x(a){var b=!1;for(var c=0;c<a.scripts.length;c++)a.scripts[c].ready&&a.scripts[c].exec_trigger&&(b=!0,a.scripts[c].exec_trigger(),a.scripts[c].exec_trigger=null);return b}function y(a,b,c,d){a.onload=a.onreadystatechange=function(){if(a.readyState&&a.readyState!="complete"&&a.readyState!="loaded"||b[c])return;a.onload=a.onreadystatechange=null,d()}}function z(a){a.ready=a.finished=!0;for(var b=0;b<a.finished_listeners.length;b++)a.finished_listeners[b]();a.ready_listeners=[],a.finished_listeners=[]}function A(a,b,d,e,f){setTimeout(function(){var h,i=b.real_src,l;if("item"in k){if(!k[0]){setTimeout(arguments.callee,25);return}k=k[0]}h=document.createElement("script"),b.type&&(h.type=b.type),b.charset&&(h.charset=b.charset),f?q?(a[g]&&m("start script preload: "+i),d.elem=h,p?(h.preload=!0,h.onpreload=e):h.onreadystatechange=function(){h.readyState=="loaded"&&e()},h.src=i):f&&i.indexOf(j)==0&&a[c]?(l=new XMLHttpRequest,a[g]&&m("start script preload (xhr): "+i),l.onreadystatechange=function(){l.readyState==4&&(l.onreadystatechange=function(){},d.text=l.responseText+"\n//@ sourceURL="+i,e())},l.open("GET",i),l.send()):(a[g]&&m("start script preload (cache): "+i),h.type="text/cache-script",y(h,d,"ready",function(){k.removeChild(h),e()}),h.src=i,k.insertBefore(h,k.firstChild)):r?(a[g]&&m("start script load (ordered async): "+i),h.async=!1,y(h,d,"finished",e),h.src=i,k.insertBefore(h,k.firstChild)):(a[g]&&m("start script load: "+i),y(h,d,"finished",e),h.src=i,k.insertBefore(h,k.firstChild))},0)}function B(){function r(a,b,c){function f(){d!=null&&(d=null,z(c))}var d;if(o[b.src].finished)return;a[e]||(o[b.src].finished=!0),d=c.elem||document.createElement("script"),b.type&&(d.type=b.type),b.charset&&(d.charset=b.charset),y(d,c,"finished",f),c.elem?c.elem=null:c.text?(d.onload=d.onreadystatechange=null,d.text=c.text):d.src=b.real_src,k.insertBefore(d,k.firstChild),c.text&&f()}function C(a,b,c,d){var g,i,j=function(){b.ready_cb(b,function(){r(a,b,g)})},k=function(){b.finished_cb(b,c)};b.src=v(b.src,a[h]),b.real_src=b.src+(a[f]?(/\?.*$/.test(b.src)?"&_":"?_")+~~(Math.random()*1e9)+"=":""),o[b.src]||(o[b.src]={items:[],finished:!1}),i=o[b.src].items,a[e]||i.length==0?(g=i[i.length]={ready:!1,finished:!1,ready_listeners:[j],finished_listeners:[k]},A(a,b,g,d?function(){g.ready=!0;for(var a=0;a<g.ready_listeners.length;a++)g.ready_listeners[a]();g.ready_listeners=[]}:function(){z(g)},d)):(g=i[0],g.finished?k():g.finished_listeners.push(k))}function D(){function k(a,c){b[g]&&m("script preload finished: "+a.real_src),a.ready=!0,a.exec_trigger=c,o()}function l(a,c){b[g]&&m("script execution finished: "+a.real_src),a.ready=a.finished=!0,a.exec_trigger=null;for(var d=0;d<c.scripts.length;d++)if(!c.scripts[d].finished)return;c.finished=!0,o()}function o(){while(e<c.length){if(t(c[e])){b[g]&&m("$LAB.wait() executing: "+c[e]);try{c[e++]()}catch(a){b[g]&&n("$LAB.wait() error caught: ",a)}continue}if(!c[e].finished){if(x(c[e]))continue;break}e++}e==c.length&&(f=!1,h=!1)}function p(){(!h||!h.scripts)&&c.push(h={scripts:[],finished:!0})}var a,b=w(i,{}),c=[],e=0,f=!1,h;return a={script:function(){for(var c=0;c<arguments.length;c++)(function(c,e){var g;u(c)||(e=[c]);for(var i=0;i<e.length;i++){p(),c=e[i],t(c)&&(c=c());if(!c)continue;if(u(c)){g=[].slice.call(c),g.unshift(i,1),[].splice.apply(e,g),i--;continue}typeof c=="string"&&(c={src:c}),c=w(c,{ready:!1,ready_cb:k,finished:!1,finished_cb:l}),h.finished=!1,h.scripts.push(c),C(b,c,h,j&&f),f=!0,b[d]&&a.wait()}})(arguments[c],arguments[c]);return a},wait:function(){if(arguments.length>0){for(var b=0;b<arguments.length;b++)c.push(arguments[b]);h=c[c.length-1]}else h=!1;return o(),a}},{script:a.script,wait:a.wait,setOptions:function(c){return w(c,b),a}}}var i={},j=q||s,l=[],o={},p;return i[c]=!0,i[d]=!1,i[e]=!1,i[f]=!1,i[g]=!1,i[h]="",p={setGlobalDefaults:function(a){return w(a,i),p},setOptions:function(){return D().setOptions.apply(null,arguments)},script:function(){return D().script.apply(null,arguments)},wait:function(){return D().wait.apply(null,arguments)},queueScript:function(){return l[l.length]={type:"script",args:[].slice.call(arguments)},p},queueWait:function(){return l[l.length]={type:"wait",args:[].slice.call(arguments)},p},runQueue:function(){var a=p,b=l.length,c=b,d;for(;--c>=0;)d=l.shift(),a=a[d.type].apply(null,d.args);return a},noConflict:function(){return a.$LAB=b,p},sandbox:function(){return B()}},p}var b=a.$LAB,c="UseLocalXHR",d="AlwaysPreserveOrder",e="AllowDuplicates",f="CacheBust",g="Debug",h="BasePath",i=/^[^?#]*\//.exec(location.href)[0],j=/^\w+\:\/\/\/?[^\/]+/.exec(i)[0],k=document.head||document.getElementsByTagName("head"),l=a.opera&&Object.prototype.toString.call(a.opera)=="[object Opera]"||"MozAppearance"in document.documentElement.style,m=function(){},n=m,o=document.createElement("script"),p=typeof o.preload=="boolean",q=p||o.readyState&&o.readyState=="uninitialized",r=!q&&o.async===!0,s=!q&&!r&&!l;a.console&&a.console.log&&(a.console.error||(a.console.error=a.console.log),m=function(b){a.console.log(b)},n=function(b,c){a.console.error(b,c)}),a.$LAB=B(),function(a,b,c){document.readyState==null&&document[a]&&(document.readyState="loading",document[a](b,c=function(){document.removeEventListener(b,c,!1),document.readyState="complete"},!1))}("addEventListener","DOMContentLoaded")}(this),window.JSON&&window.JSON.stringify||function(){function quote(a){return escapable.lastIndex=0,escapable.test(a)?'"'+a.replace(escapable,function(a){var b=meta[a];return typeof b=="string"?b:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+a+'"'}function str(a,b){var c,d,e,f,g=gap,h,i=b[a];i&&typeof i=="object"&&typeof i.toJSON=="function"&&(i=i.toJSON(a)),typeof rep=="function"&&(i=rep.call(b,a,i));switch(typeof i){case"string":return quote(i);case"number":return isFinite(i)?String(i):"null";case"boolean":case"null":return String(i);case"object":if(!i)return"null";gap+=indent,h=[];if(Object.prototype.toString.apply(i)==="[object Array]"){f=i.length;for(c=0;c<f;c+=1)h[c]=str(c,i)||"null";return e=h.length===0?"[]":gap?"[\n"+gap+h.join(",\n"+gap)+"\n"+g+"]":"["+h.join(",")+"]",gap=g,e}if(rep&&typeof rep=="object"){f=rep.length;for(c=0;c<f;c+=1)d=rep[c],typeof d=="string"&&(e=str(d,i),e&&h.push(quote(d)+(gap?": ":":")+e))}else for(d in i)Object.hasOwnProperty.call(i,d)&&(e=str(d,i),e&&h.push(quote(d)+(gap?": ":":")+e));return e=h.length===0?"{}":gap?"{\n"+gap+h.join(",\n"+gap)+"\n"+g+"}":"{"+h.join(",")+"}",gap=g,e}}window.JSON||(window.JSON={}),typeof String.prototype.toJSON!="function"&&(String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(a){return this.valueOf()});var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={"\b":"\\b"," ":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},rep;typeof JSON["stringify"]!="function"&&(JSON.stringify=function(a,b,c){var d;gap="",indent="";if(typeof c=="number")for(d=0;d<c;d+=1)indent+=" ";else typeof c=="string"&&(indent=c);rep=b;if(!b||typeof b=="function"||typeof b=="object"&&typeof b.length=="number")return str("",{"":a});throw new Error("JSON.stringify")}),typeof JSON["parse"]!="function"&&(JSON.parse=function(text){return eval("("+text+")")})}(),window.PUBNUB||function(){function a(){return"x"+ ++d+""+ +(new Date)}function b(){return+(new Date)}function n(a,c){var d,e=0,f=function(){e+c>b()?(clearTimeout(d),d=setTimeout(f,c)):(e=b(),a())};return f}function o(a){return document.getElementById(a)}function p(a){console.log(a)}function q(a,b){var c=[];return r(a.split(/\s+/),function(a){r((b||document).getElementsByTagName(a),function(a){c.push(a)})}),c}function r(a,b){if(!a||!b)return;if(typeof a[0]!="undefined")for(var c=0,d=a.length;c<d;)b.call(a[c],a[c],c++);else for(var c in a)a.hasOwnProperty&&a.hasOwnProperty(c)&&b.call(a[c],c,a[c])}function s(a,b){var c=[];return r(a||[],function(a,d){c.push(b(a,d))}),c}function t(a,b){var c=[];return r(a||[],function(a){b(a)&&c.push(a)}),c}function u(a,b){return a.replace(f,function(a,c){return b[c]||a})}function v(a,b,c){r(a.split(","),function(a){var d=function(a){a||(a=window.event),c(a)||(a.cancelBubble=!0,a.returnValue=!1,a.preventDefault&&a.preventDefault(),a.stopPropagation&&a.stopPropagation())};b.addEventListener?b.addEventListener(a,d,!1):b.attachEvent?b.attachEvent("on"+a,d):b["on"+a]=d})}function w(a,b,c){b.removeEventListener?b.removeEventListener(a,!1):b.detachEvent?b.detachEvent("on"+a,!1):b["on"+a]=null}function x(){return q("head")[0]}function y(a,b,c){if(!c)return a&&a.getAttribute&&a.getAttribute(b);a.setAttribute(b,c)}function z(a,b){for(var c in b)if(b.hasOwnProperty(c))try{a.style[c]=b[c]+("|width|height|top|left|".indexOf(c)>0&&typeof b[c]=="number"?"px":"")}catch(d){}}function A(a){return document.createElement(a)}function B(a,b){return setTimeout(a,b)}function C(){return l||N()?0:a()}function D(a){return s(encodeURIComponent(a).split(""),function(a){return"-_.!~*'()".indexOf(a)<0?a:"%"+a.charCodeAt(0).toString(16).toUpperCase()}).join("")}function F(b){if(l||N())return G(b);var c=A("script"),d=b.callback,e=a(),f=0,k=B(function(){q(1)},i),m=b.fail||function(){},n=b.success||function(){},p=function(){x().appendChild(c)},q=function(a,b){if(f)return;f=1,a||n(b),c.onerror=null,clearTimeout(k),B(function(){a&&m();var b=o(e),c=b&&b.parentNode;c&&c.removeChild(b)},j)};window[d]=function(a){q(0,a)},c[g]=g,c.onerror=function(){q(1)},c.src=b.url.join(h);if(b.data){c.src+="?";for(key in b.data)c.src+=key+"="+b.data[key]+"&"}return y(c,"id",e),p(),q}function G(a){var b,c=function(){if(e)return;e=1,clearTimeout(f);try{response=JSON.parse(b.responseText)}catch(a){return k(1)}j(response)},d=0,e=0,f=B(function(){k(1)},i),g=a.fail||function(){},j=a.success||function(){},k=function(a){if(d)return;d=1,clearTimeout(f),b&&(b.onerror=b.onload=null,b.abort&&b.abort(),b=null),a&&g()};try{b=N()||window.XDomainRequest&&new XDomainRequest||new XMLHttpRequest,b.onerror=b.onabort=function(){k(1)},b.onload=b.onloadend=c,b.timeout=i,url=a.url.join(h);if(a.data){url+="?";for(key in a.data)url+=key+"="+a.data[key]+"&"}b.open("GET",url,!0),b.send()}catch(m){return k(0),l=0,F(a)}return k}function M(){PUBNUB.time(b),PUBNUB.time(function(a){B(function(){if(I)return;I=1,r(J,function(a){a[2].subscribe(a[0],a[1])})},j)})}function N(){if(!L.get)return 0;var a={id:N.id++,send:function(){},abort:function(){a.id={}},open:function(b,c){N[a.id]=a,L.get(a.id,c)}};return a}window.console||(window.console=window.console||{}),console.log||(console.log=(window.opera||{}).postError||function(){});var c=function(){var a=window.localStorage;return{get:function(b){try{return a?a.getItem(b):document.cookie.indexOf(b)==-1?null:((document.cookie||"").match(RegExp(b+"=([^;]+)"))||[])[1]||null}catch(c){return}},set:function(b,c){try{if(a)return a.setItem(b,c)&&0;document.cookie=b+"="+c+"; expires=Thu, 1 Aug 2030 20:00:00 UTC; path=/"}catch(d){return}}}}(),d=1,e="https://dh15atwfs066y.cloudfront.net/pubnub.swf",f=/{([\w\-]+)}/g,g="async",h="/",i=31e4,j=1e3,k=navigator.userAgent,l=k.indexOf("MSIE 6")==-1,m=function(){var a=Math.floor(Math.random()*9)+1;return function(b){return b.indexOf("pubsub")>0&&b.replace("pubsub","ps"+(++a<10?a:a=1))||b}}(),E={list:{},unbind:function(a){E.list[a]=[]},bind:function(a,b){(E.list[a]=E.list[a]||[]).push(b)},fire:function(a,b){r(E.list[a]||[],function(a){a(b)})}},H=o("pubnub")||{},I=0,J=[],K=function(d){var e={},f=d.publish_key||"pub-42c6b905-6d4e-4896-b74f-c1065ab0dc10",g=d.subscribe_key||"sub-4e37d063-edfa-11df-8f1a-517217f921a4",h=d.ssl?"s":"",i=function(){return villo.user.getUsername()||"Guest"}(),k="http"+h+"://"+(d.origin||"pubsub.pubnub.com"),l={history:function(a,b){var b=a.callback||b,c=a.limit||100,d=a.channel,e=C();if(!d)return p("Missing Channel");if(!b)return p("Missing Callback");F({callback:e,url:[k,"history",g,D(d),e,c],success:function(a){b(a)},fail:function(a){p(a)}})},time:function(a){var b=C();F({callback:b,url:[k,"time",b],success:function(b){a(b[0])},fail:function(){a(0)}})},uuid:function(a){return villo.user.getUsername()||"Guest";var b},publish:function(a,b){var b=b||a.callback||function(){},c=a.message,d=a.channel,e=C(),h;if(!c)return p("Missing Message");if(!d)return p("Missing Channel");if(!f)return p("Missing Publish Key");c=JSON.stringify(c),h=[k,"publish",f,g,0,D(d),e,D(c)],i=l.uuid(),F({callback:e,success:function(a){b(a)},fail:function(){b([0,"Disconnected"])},url:h,data:{uuid:i}})},unsubscribe:function(a){var b=a.channel;if(!(b in e))return;e[b].connected=0,e[b].done&&e[b].done(0)},subscribe:function(a,b){function y(){var a=C();if(!e[d].connected)return;i=l.uuid(),e[d].done=F({callback:a,url:[x,"subscribe",f,D(d),a,n],data:{uuid:i},fail:function(){v||(v=1,t()),B(y,j),l.time(function(a){a&&v?(v=0,s()):o()})},success:function(a){if(!e[d].connected)return;w||(w=1,q()),v&&(v=0,s()),h=c.set(g+d,n=h&&c.get(f+d)||a[1]),r(a[0],function(c){b(c,a)}),B(y,10)}})}var d=a.channel,b=b||a.callback,f=a.subscribe_key||g,h=a.restore,n=0,o=a.error||function(){},q=a.connect||function(){},s=a.reconnect||function(){},t=a.disconnect||function(){},u=a.presence||function(){},v=0,w=0,x=m(k);if(!I)return J.push([a,b,l]);if(!d)return p("Missing Channel");if(!b)return p("Missing Callback");if(!g)return p("Missing Subscribe Key");d in e||(e[d]={});if(e[d].connected)return p("Already Connected");e[d].connected=1,y(),a.presence&&l.subscribe({channel:a.channel+"-pnpres",callback:u,restore:a.restore})},here_now:function(a,b){var b=a.callback||b,c=a.channel,d=C(),e=m(k);if(!c)return p("Missing Channel");if(!b)return p("Missing Callback");data=null,d!="0"&&(data.callback=d),F({callback:d,url:[e,"v2","presence","sub_key",g,"channel",D(c)],data:data,success:function(a){b(a)},fail:function(a){p(a)}})},xdr:F,ready:M,db:c,each:r,map:s,css:z,$:o,create:A,bind:v,supplant:u,head:x,search:q,attr:y,now:b,unique:a,events:E,updater:n,init:K};return i==""&&(i=l.uuid()),l};PUBNUB=K({publish_key:y(H,"pub-key"),subscribe_key:y(H,"sub-key"),ssl:y(H,"ssl")=="on",origin:y(H,"origin"),uuid:y(H,"uuid")}),z(H,{position:"absolute",top:-j});if("opera"in window||y(H,"flash"))H.innerHTML="<object id=pubnubs data="+e+"><param name=movie value="+e+"><param name=allowscriptaccess value=always></object>";var L=o("pubnubs")||{};v("load",window,function(){B(M,0)}),PUBNUB.rdx=function(a,b){if(!b)return N[a].onerror();N[a].responseText=unescape(b),N[a].onload()},N.id=j,window.jQuery&&(window.jQuery.PUBNUB=PUBNUB),typeof module!="undefined"&&(module.exports=PUBNUB)&&M()}()