// @note: This is now deprecated as of 10/30/2009
var mpmetrics={};mpmetrics.super_properties={"all":{},"events":{},"funnels":{}};mpmetrics.init=function(a){var b=(("https:"==document.location.protocol)?"https://":"http://");this.token=a;this.api_host=b+'api.mixpanel.com';try{mpmetrics.get_super()}catch(err){}};mpmetrics.send_request=function(a,b){var c='mpmetrics.jsonp_callback';if(a.indexOf("?")>-1){a+="&callback="}else{a+="?callback="}a+=c+"&";if(b){a+=this.http_build_query(b)}a+='&_='+new Date().getTime().toString();var d=document.createElement("script");d.setAttribute("src",a);d.setAttribute("type","text/javascript");document.body.appendChild(d)};mpmetrics.log=function(a,b){if(!a.project){a.project=this.token}if(a.project&&a.category){this.callback=b;a.ip=1;this.send_request(this.api_host+"/log/",a)}};mpmetrics.track_funnel=function(a,b,c,d,e){if(!d){d={}}d.funnel=a;d.step=parseInt(b,10);d.goal=c;if(d.step==1){if(document.referrer.search('http://(.*)google.com')===0){var f=mpmetrics.get_query_param(document.referrer,'q');if(f.length){mpmetrics.register({'mp_keyword':f},'funnels')}}}mpmetrics.track('mp_funnel',d,e,"funnels")};mpmetrics.get_query_param=function(a,b){b=b.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");var c="[\\?&]"+b+"=([^&#]*)";var d=new RegExp(c);var e=d.exec(a);if(e===null||(e&&typeof(e[1])!='string'&&e[1].length)){return''}else{return unescape(e[1]).replace(/\+/g,' ')}};mpmetrics.track=function(a,b,c,d){if(!d){d="events"}if(!b){b={}}if(!b.token){b.token=this.token}if(c){this.callback=c}b.time=this.get_unixtime();if(d!="all"){for(var p in mpmetrics.super_properties[d]){if(!b[p]){b[p]=mpmetrics.super_properties[d][p]}}}if(mpmetrics.super_properties.all){for(p in mpmetrics.super_properties.all){if(!b[p]){b[p]=mpmetrics.super_properties.all[p]}}}var e={'event':a,'properties':b};var f=this.base64_encode(this.json_encode(e));this.send_request(this.api_host+'/track/',{'data':f,'ip':1})};mpmetrics.register=function(a,b,c){if(!b){b="all"}if(!c){c=7}if(a){for(var p in a){if(p){mpmetrics.super_properties[b][p]=a[p]}}}mpmetrics.set_cookie("mp_super_properties",mpmetrics.json_encode(mpmetrics.super_properties),c)};mpmetrics.http_build_query=function(a,b){var c,use_val,use_key,i=0,tmp_arr=[];if(!b){b='&'}for(c in a){if(c){use_val=encodeURIComponent(a[c].toString());use_key=encodeURIComponent(c);tmp_arr[i++]=use_key+'='+use_val}}return tmp_arr.join(b)};mpmetrics.get_unixtime=function(){return parseInt(new Date().getTime().toString().substring(0,10),10)};mpmetrics.jsonp_callback=function(a){if(this.callback){this.callback(a);this.callback=false}};mpmetrics.json_encode=function(j){var l;var m=j;var i;var n=function(b){var d=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;var e={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'};d.lastIndex=0;return d.test(b)?'"'+b.replace(d,function(a){var c=e[a];return typeof c==='string'?c:'\\u'+('0000'+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+b+'"'};var o=function(a,b){var c='';var d='    ';var i=0;var k='';var v='';var e=0;var f=c;var g=[];var h=b[a];if(h&&typeof h==='object'&&typeof h.toJSON==='function'){h=h.toJSON(a)}switch(typeof h){case'string':return n(h);case'number':return isFinite(h)?String(h):'null';case'boolean':case'null':return String(h);case'object':if(!h){return'null'}c+=d;g=[];if(Object.prototype.toString.apply(h)==='[object Array]'){e=h.length;for(i=0;i<e;i+=1){g[i]=o(i,h)||'null'}v=g.length===0?'[]':c?'[\n'+c+g.join(',\n'+c)+'\n'+f+']':'['+g.join(',')+']';c=f;return v}for(k in h){if(Object.hasOwnProperty.call(h,k)){v=o(k,h);if(v){g.push(n(k)+(c?': ':':')+v)}}}v=g.length===0?'{}':c?'{'+g.join(',')+''+f+'}':'{'+g.join(',')+'}';c=f;return v}};return o('',{'':m})};mpmetrics.base64_encode=function(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";var c,o2,o3,h1,h2,h3,h4,bits,i=0,ac=0,enc="",tmp_arr=[];if(!a){return a}a=this.utf8_encode(a+'');do{c=a.charCodeAt(i++);o2=a.charCodeAt(i++);o3=a.charCodeAt(i++);bits=c<<16|o2<<8|o3;h1=bits>>18&0x3f;h2=bits>>12&0x3f;h3=bits>>6&0x3f;h4=bits&0x3f;tmp_arr[ac++]=b.charAt(h1)+b.charAt(h2)+b.charAt(h3)+b.charAt(h4)}while(i<a.length);enc=tmp_arr.join('');switch(a.length%3){case 1:enc=enc.slice(0,-2)+'==';break;case 2:enc=enc.slice(0,-1)+'=';break}return enc};mpmetrics.utf8_encode=function(a){a=(a+'').replace(/\r\n/g,"\n").replace(/\r/g,"\n");var b="";var c,end;var d=0;c=end=0;d=a.length;for(var n=0;n<d;n++){var e=a.charCodeAt(n);var f=null;if(e<128){end++}else if((e>127)&&(e<2048)){f=String.fromCharCode((e>>6)|192)+String.fromCharCode((e&63)|128)}else{f=String.fromCharCode((e>>12)|224)+String.fromCharCode(((e>>6)&63)|128)+String.fromCharCode((e&63)|128)}if(f!==null){if(end>c){b+=a.substring(c,end)}b+=f;c=end=n+1}}if(end>c){b+=a.substring(c,a.length)}return b};mpmetrics.set_cookie=function(a,b,c){var d=new Date();d.setDate(d.getDate()+c);document.cookie=a+"="+escape(b)+((c===null)?"":";expires="+d.toGMTString())+"; path=/"};mpmetrics.get_cookie=function(a){if(document.cookie.length>0){var b=document.cookie.indexOf(a+"=");if(b!=-1){b=b+a.length+1;var c=document.cookie.indexOf(";",b);if(c==-1){c=document.cookie.length}return unescape(document.cookie.substring(b,c))}}return""};mpmetrics.get_super=function(){var a=eval('('+mpmetrics.get_cookie("mp_super_properties")+')');if(a){for(var i in a){if(i){mpmetrics.super_properties[i]=a[i]}}}};