(function(f,k,o){if(!("console"in f)){var m=f.console={};m.log=m.warn=m.error=m.debug=function(){}}k||(k={fn:{},extend:function(){for(var a=arguments[0],c=1,b=arguments.length;c<b;c++){var e=arguments[c],h;for(h in e)a[h]=e[h]}return a}});k.fn.pm=function(){console.log("usage: \nto send:    $.pm(options)\nto receive: $.pm.bind(type, fn, [origin])");return this};k.pm=f.pm=function(a){b.send(a)};k.pm.bind=f.pm.bind=function(a,c,d,e){b.bind(a,c,d,e)};k.pm.unbind=f.pm.unbind=function(a,c){b.unbind(a,
c)};k.pm.origin=f.pm.origin=null;k.pm.poll=f.pm.poll=200;var b={send:function(a){var a=k.extend({},b.defaults,a),c=a.target;if(a.target)if(a.type){var d={data:a.data,type:a.type};if(a.success)d.callback=b._callback(a.success);if(a.error)d.errback=b._callback(a.error);"postMessage"in c&&!a.hash?(b._bind(),c.postMessage(JSON.stringify(d),a.origin||"*")):(b.hash._bind(),b.hash.send(a,d))}else console.warn("postmessage type required");else console.warn("postmessage target window required")},bind:function(a,
c,d,e){"postMessage"in f&&!e?b._bind():b.hash._bind();e=b.data("listeners.postmessage");e||(e={},b.data("listeners.postmessage",e));var h=e[a];h||(h=[],e[a]=h);h.push({fn:c,origin:d||k.pm.origin})},unbind:function(a,c){var d=b.data("listeners.postmessage");if(d)if(a)if(c){var e=d[a];if(e){for(var h=[],l=0,j=e.length;l<j;l++){var i=e[l];i.fn!==c&&h.push(i)}d[a]=h}}else delete d[a];else for(l in d)delete d[l]},data:function(a,c){if(c===o)return b._data[a];return b._data[a]=c},_data:{},_CHARS:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),
_random:function(){for(var a=[],c=0;c<32;c++)a[c]=b._CHARS[0|Math.random()*32];return a.join("")},_callback:function(a){var c=b.data("callbacks.postmessage");c||(c={},b.data("callbacks.postmessage",c));var d=b._random();c[d]=a;return d},_bind:function(){b.data("listening.postmessage")||(f.addEventListener?f.addEventListener("message",b._dispatch,!1):f.attachEvent&&f.attachEvent("onmessage",b._dispatch),b.data("listening.postmessage",1))},_dispatch:function(a){try{var c=JSON.parse(a.data)}catch(d){console.warn("postmessage data invalid json: ",
d);return}if(c.type){var e=(b.data("callbacks.postmessage")||{})[c.type];if(e)e(c.data);else for(var e=(b.data("listeners.postmessage")||{})[c.type]||[],h=0,l=e.length;h<l;h++){var j=e[h];if(j.origin&&a.origin!==j.origin)console.warn("postmessage message origin mismatch",a.origin,j.origin),c.errback&&b.send({target:a.source,data:{message:"postmessage origin mismatch",origin:[a.origin,j.origin]},type:c.errback});else try{var i=j.fn(c.data);c.callback&&b.send({target:a.source,data:i,type:c.callback})}catch(f){c.errback&&
b.send({target:a.source,data:f,type:c.errback})}}}else console.warn("postmessage message type required")}};b.hash={send:function(a,c){var d=a.target,e=a.url;if(e){var e=b.hash._url(e),h,l=b.hash._url(f.location.href);if(f==d.parent)h="parent";else try{for(var j=0,i=parent.frames.length;j<i;j++)if(parent.frames[j]==f){h=j;break}}catch(q){h=f.name}h==null?console.warn("postmessage windows must be direct parent/child windows and the child must be available through the parent window.frames list"):(h=
{"x-requested-with":"postmessage",source:{name:h,url:l},postmessage:c},l="#x-postmessage-id="+b._random(),d.location=e+l+encodeURIComponent(JSON.stringify(h)))}else console.warn("postmessage target window url is required")},_regex:/^\#x\-postmessage\-id\=(\w{32})/,_regex_len:50,_bind:function(){b.data("polling.postmessage")||(setInterval(function(){var a=""+f.location.hash,c=b.hash._regex.exec(a);if(c&&(c=c[1],b.hash._last!==c))b.hash._last=c,b.hash._dispatch(a.substring(b.hash._regex_len))},k.pm.poll||
200),b.data("polling.postmessage",1))},_dispatch:function(a){if(a){try{if(a=JSON.parse(decodeURIComponent(a)),!(a["x-requested-with"]==="postmessage"&&a.source&&a.source.name!=null&&a.source.url&&a.postmessage))return}catch(c){return}var d=a.postmessage,e=(b.data("callbacks.postmessage")||{})[d.type];if(e)e(d.data);else for(var e=a.source.name==="parent"?f.parent:f.frames[a.source.name],h=(b.data("listeners.postmessage")||{})[d.type]||[],l=0,j=h.length;l<j;l++){var i=h[l];if(i.origin){var q=/https?\:\/\/[^\/]*/.exec(a.source.url)[0];
if(q!==i.origin){console.warn("postmessage message origin mismatch",q,i.origin);d.errback&&b.send({target:e,data:{message:"postmessage origin mismatch",origin:[q,i.origin]},type:d.errback,hash:!0,url:a.source.url});continue}}try{var k=i.fn(d.data);d.callback&&b.send({target:e,data:k,type:d.callback,hash:!0,url:a.source.url})}catch(p){d.errback&&b.send({target:e,data:p,type:d.errback,hash:!0,url:a.source.url})}}}},_url:function(a){return(""+a).replace(/#.*$/,"")}};k.extend(b,{defaults:{target:null,
url:null,type:null,data:null,success:null,error:null,origin:"*",hash:!1}})})(this,typeof jQuery==="undefined"?null:jQuery);if(!this.JSON)this.JSON={};
(function(){function f(a){return a<10?"0"+a:a}function k(a){b.lastIndex=0;return b.test(a)?'"'+a.replace(b,function(a){var c=d[a];return typeof c==="string"?c:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+a+'"'}function o(b,d){var j,i,f,m,p=a,n,g=d[b];g&&typeof g==="object"&&typeof g.toJSON==="function"&&(g=g.toJSON(b));typeof e==="function"&&(g=e.call(d,b,g));switch(typeof g){case "string":return k(g);case "number":return isFinite(g)?String(g):"null";case "boolean":case "null":return String(g);
case "object":if(!g)return"null";a+=c;n=[];if(Object.prototype.toString.apply(g)==="[object Array]"){m=g.length;for(j=0;j<m;j+=1)n[j]=o(j,g)||"null";f=n.length===0?"[]":a?"[\n"+a+n.join(",\n"+a)+"\n"+p+"]":"["+n.join(",")+"]";a=p;return f}if(e&&typeof e==="object"){m=e.length;for(j=0;j<m;j+=1)i=e[j],typeof i==="string"&&(f=o(i,g))&&n.push(k(i)+(a?": ":":")+f)}else for(i in g)Object.hasOwnProperty.call(g,i)&&(f=o(i,g))&&n.push(k(i)+(a?": ":":")+f);f=n.length===0?"{}":a?"{\n"+a+n.join(",\n"+a)+"\n"+
p+"}":"{"+n.join(",")+"}";a=p;return f}}if(typeof Date.prototype.toJSON!=="function")Date.prototype.toJSON=function(){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+f(this.getUTCMonth()+1)+"-"+f(this.getUTCDate())+"T"+f(this.getUTCHours())+":"+f(this.getUTCMinutes())+":"+f(this.getUTCSeconds())+"Z":null},String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(){return this.valueOf()};var m=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
b=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,a,c,d={"\u0008":"\\b","\t":"\\t","\n":"\\n","\u000c":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},e;if(typeof JSON.stringify!=="function")JSON.stringify=function(b,d,f){var i;c=a="";if(typeof f==="number")for(i=0;i<f;i+=1)c+=" ";else typeof f==="string"&&(c=f);if((e=d)&&typeof d!=="function"&&(typeof d!=="object"||typeof d.length!=="number"))throw Error("JSON.stringify");return o("",
{"":b})};if(typeof JSON.parse!=="function")JSON.parse=function(a,b){function c(a,d){var e,f,g=a[d];if(g&&typeof g==="object")for(e in g)Object.hasOwnProperty.call(g,e)&&(f=c(g,e),f!==void 0?g[e]=f:delete g[e]);return b.call(a,d,g)}var d,a=String(a);m.lastIndex=0;m.test(a)&&(a=a.replace(m,function(a){return"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)}));if(/^[\],:{}\s]*$/.test(a.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,
"]").replace(/(?:^|:|,)(?:\s*\[)+/g,"")))return d=eval("("+a+")"),typeof b==="function"?c({"":d},""):d;throw new SyntaxError("JSON.parse");}})();

